Progress of file picker

This commit is contained in:
Jordan Eldredge 2019-02-20 09:28:14 -08:00
parent f4dfceface
commit 82d0323f58
10 changed files with 166 additions and 243 deletions

View file

@ -1,59 +0,0 @@
var glob = require("glob");
const path = require("path");
var { exec } = require("child_process");
const _ = require("lodash");
function allSkinPaths() {
return new Promise((resolve, reject) => {
glob(
path.join(
__dirname,
"../../webamp/experiments/automatedScreenshots/skins/",
"**/*.wsz"
),
function(err, files) {
if (err != null) {
reject(err);
return;
}
resolve(files);
}
);
});
}
async function filenamesForSkin(skinPath) {
const paths = await new Promise((resolve, reject) => {
exec(`zipinfo -1 ${skinPath}`, function(error, stdout, stderr) {
if (error != null) {
//reject(error);
//return;
}
resolve(stdout);
});
});
return paths.split("\n");
}
async function allFilenames() {
const skins = await allSkinPaths();
const paths = _.flatten(
await Promise.all(
skins.map(skin => {
return filenamesForSkin(skin);
})
)
);
const fileNames = paths.map(p => path.basename(p).toLowerCase());
const uniqueFileNames = {};
for (fileName of fileNames) {
uniqueFileNames[fileName] =
uniqueFileNames[fileName] == null ? 1 : uniqueFileNames[fileName] + 1;
}
const entries = Object.entries(uniqueFileNames);
const sorted = _.sortBy(entries, ([filename, count]) => count);
console.log(JSON.stringify(sorted, null, 2));
}
allFilenames();

View file

@ -5,6 +5,19 @@ const { getSkinMetadata } = require("./utils");
const client = algoliasearch("HQ9I5Z6IM5", "f5357f4070cdb6ed652d9c3feeede89f");
const index = client.initIndex("Skins");
function tuncate(str, len) {
const overflow = str.length - len;
if (overflow < 0) {
return str;
}
const half = Math.floor((len - 1) / 2);
const start = str.slice(0, half);
const end = str.slice(-half);
return `${start} ########### ${end}`;
}
async function buildSkinIndex(hash) {
const textMetadata = await getSkinMetadata(hash, "extracted-data");
return {
@ -12,7 +25,7 @@ async function buildSkinIndex(hash) {
md5: hash,
fileName: skins[hash].fileName,
emails: textMetadata.emails,
readmeText: textMetadata.raw.slice(0, 1000)
readmeText: tuncate(textMetadata.raw, 4800)
};
}
@ -24,6 +37,12 @@ const indexesPromise = Promise.all(
async function go() {
const indexes = await indexesPromise;
const large = indexes.filter(index => {
return index.readmeText.length > 4790;
});
large.map(l => {
return l.fileName;
});
return new Promise((resolve, reject) => {
index.saveObjects(indexes, function(err, content) {
@ -33,4 +52,4 @@ async function go() {
});
}
go().then(content => console.log(content));
go(); // .then(content => console.log("Updated index for:", content.length));