mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-19 01:23:49 +00:00
Use a constant for file types
This commit is contained in:
parent
100795bba1
commit
5be20276f7
4 changed files with 26 additions and 9 deletions
|
|
@ -6,6 +6,7 @@ const { memoize } = require("lodash");
|
|||
const md5File = require("md5-file/promise");
|
||||
const Filehound = require("filehound");
|
||||
const Utils = require("./utils");
|
||||
const { FILE_TYPES } = require("./constants");
|
||||
|
||||
const memoizedMd5File = memoize(md5File);
|
||||
|
||||
|
|
@ -45,7 +46,7 @@ module.exports = async function collectSkins({
|
|||
|
||||
fsPromises.writeFile(filenamesPath, pathList);
|
||||
collectionInfo
|
||||
.filter(info => info.skinType === "PACK")
|
||||
.filter(info => info.skinType === FILE_TYPES.PACK)
|
||||
.forEach(pack => {
|
||||
const packPath = path.resolve(`./assets/md5Packs/${pack.md5}`);
|
||||
if (fs.existsSync(packPath)) {
|
||||
|
|
@ -58,7 +59,7 @@ module.exports = async function collectSkins({
|
|||
}
|
||||
});
|
||||
collectionInfo
|
||||
.filter(info => info.skinType === "INVALID")
|
||||
.filter(info => info.skinType === FILE_TYPES.INVALID)
|
||||
.forEach(async invalid => {
|
||||
const filePath = path.resolve(`./assets/md5Invalids/${invalid.md5}.wsz`);
|
||||
if (fs.existsSync(filePath)) {
|
||||
|
|
@ -72,10 +73,14 @@ module.exports = async function collectSkins({
|
|||
moved: collectionInfo.filter(info => info.moved).length,
|
||||
newScreenshots: collectionInfo.filter(info => info.screenshotCreated)
|
||||
.length,
|
||||
classic: collectionInfo.filter(info => info.skinType === "CLASSIC").length,
|
||||
packs: collectionInfo.filter(info => info.skinType === "PACK").length,
|
||||
invalid: collectionInfo.filter(info => info.skinType === "INVALID").length,
|
||||
modern: collectionInfo.filter(info => info.skinType === "MODERN").length,
|
||||
classic: collectionInfo.filter(info => info.skinType === FILE_TYPES.CLASSIC)
|
||||
.length,
|
||||
packs: collectionInfo.filter(info => info.skinType === FILE_TYPES.PACK)
|
||||
.length,
|
||||
invalid: collectionInfo.filter(info => info.skinType === FILE_TYPES.INVALID)
|
||||
.length,
|
||||
modern: collectionInfo.filter(info => info.skinType === FILE_TYPES.MODERN)
|
||||
.length,
|
||||
// TODO: Tell modern skins from packs
|
||||
nonClassic: collectionInfo.filter(info => !info.classic).length
|
||||
};
|
||||
|
|
|
|||
8
experiments/skinArchiveTools/lib/constants.js
Normal file
8
experiments/skinArchiveTools/lib/constants.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
const FILE_TYPES = {
|
||||
INVALID: "INVALID",
|
||||
CLASSIC: "CLASSIC",
|
||||
MODERN: "MODERN",
|
||||
PACK: "PACK"
|
||||
};
|
||||
|
||||
module.exports = { FILE_TYPES };
|
||||
|
|
@ -23,6 +23,7 @@ const outputDir = path.resolve(rawOutputDir);
|
|||
const screenshotDir = path.resolve(rawScreenshotDir);
|
||||
const filenamesPath = path.resolve(rawFilenamesPath);
|
||||
|
||||
// It's nice to be able to fiddle these manually
|
||||
const collect = true;
|
||||
const screenshots = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
const JSZip = require("jszip");
|
||||
const fsPromises = require("fs").promises;
|
||||
const { FILE_TYPES } = require("./constants");
|
||||
|
||||
// Reduce an array down to it's unique value given an async hasher function
|
||||
async function unique(arr, hasher) {
|
||||
|
|
@ -24,11 +25,13 @@ async function skinType(skinPath) {
|
|||
const zip = await JSZip.loadAsync(buffer);
|
||||
if (zip.file(/.*\.(wsz|wal|zip)$/i).length) {
|
||||
// This is a collection of skins
|
||||
return "PACK";
|
||||
return FILE_TYPES.PACK;
|
||||
}
|
||||
return zip.file(/^main\.bmp$/i).length === 1 ? "CLASSIC" : "MODERN";
|
||||
return zip.file(/^main\.bmp$/i).length === 1
|
||||
? FILE_TYPES.CLASSIC
|
||||
: FILE_TYPES.MODERN;
|
||||
} catch (e) {
|
||||
return "INVALID";
|
||||
return FILE_TYPES.INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue