mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 01:57:29 +00:00
Use utils to extract skin text
This commit is contained in:
parent
f2a544e64c
commit
122b2bbc8b
2 changed files with 9 additions and 58 deletions
|
|
@ -1,60 +1,6 @@
|
|||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const md5File = require("md5-file");
|
||||
var { exec } = require("child_process");
|
||||
|
||||
const METADATA_ROOT = path.join(__dirname, "../metadata/");
|
||||
|
||||
function getSkinMetadataPath(md5, key) {
|
||||
return path.join(METADATA_ROOT, md5, `${key}.json`);
|
||||
}
|
||||
|
||||
function getSkinMetadata(md5, key) {
|
||||
const skinMetadataPath = getSkinMetadataPath(md5, key);
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile(skinMetadataPath, "utf8", (err, data) => {
|
||||
if (err != null) reject(err);
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function ensureDirectoryExistence(filePath) {
|
||||
var dirname = path.dirname(filePath);
|
||||
if (fs.existsSync(dirname)) {
|
||||
return true;
|
||||
}
|
||||
ensureDirectoryExistence(dirname);
|
||||
fs.mkdirSync(dirname);
|
||||
}
|
||||
|
||||
async function writeSkinMetadata(md5, key, data) {
|
||||
const skinMetadataPath = getSkinMetadataPath(md5, key);
|
||||
ensureDirectoryExistence(skinMetadataPath);
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(
|
||||
skinMetadataPath,
|
||||
JSON.stringify(data, null, 2),
|
||||
"utf8",
|
||||
err => {
|
||||
if (err != null) {
|
||||
reject(err);
|
||||
}
|
||||
resolve(skinMetadataPath);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function getFileMd5(filePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
md5File(filePath, (err, hash) => {
|
||||
if (err) reject(err);
|
||||
|
||||
resolve(hash);
|
||||
});
|
||||
});
|
||||
}
|
||||
const Utils = require("./utils");
|
||||
|
||||
async function extractTextData(path) {
|
||||
const reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g;
|
||||
|
|
@ -99,8 +45,12 @@ async function extractTextData(path) {
|
|||
|
||||
async function writeTextData(skinPath) {
|
||||
const data = await extractTextData(skinPath);
|
||||
const md5 = await getFileMd5(skinPath);
|
||||
const skinMetadataPath = await writeSkinMetadata(md5, "extracted-data", data);
|
||||
const md5 = await Utils.getFileMd5(skinPath);
|
||||
const skinMetadataPath = await Utils.writeSkinMetadata(
|
||||
md5,
|
||||
"extracted-data",
|
||||
data
|
||||
);
|
||||
console.log("Done", skinMetadataPath);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,5 +58,6 @@ function getFileMd5(filePath) {
|
|||
|
||||
module.exports = {
|
||||
getSkinMetadata,
|
||||
writeSkinMetadata
|
||||
writeSkinMetadata,
|
||||
getFileMd5
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue