🔧 Orchestrating return values from uncompression methods
This commit is contained in:
@@ -80,6 +80,7 @@ export default class QueueService extends Service {
|
|||||||
} = getFileConstituents(job.data.fileObject.filePath);
|
} = getFileConstituents(job.data.fileObject.filePath);
|
||||||
const targetDirectory = `${USERDATA_DIRECTORY}/covers/${fileNameWithoutExtension}`;
|
const targetDirectory = `${USERDATA_DIRECTORY}/covers/${fileNameWithoutExtension}`;
|
||||||
const foo = await extractFromArchive(job.data.fileObject.filePath, targetDirectory, extension );
|
const foo = await extractFromArchive(job.data.fileObject.filePath, targetDirectory, extension );
|
||||||
|
console.log("JAADASD!@#!@#@!", foo);
|
||||||
|
|
||||||
// infer any issue-related metadata from the filename
|
// infer any issue-related metadata from the filename
|
||||||
// const { inferredIssueDetails } = refineQuery(result.name);
|
// const { inferredIssueDetails } = refineQuery(result.name);
|
||||||
|
|||||||
@@ -137,20 +137,24 @@ export const extractComicInfoXMLFromRar = async (
|
|||||||
filePath: string,
|
filePath: string,
|
||||||
fileToExtract: string
|
fileToExtract: string
|
||||||
) => {
|
) => {
|
||||||
try {
|
const result = {
|
||||||
// Create the target directory
|
filePath,
|
||||||
const directoryOptions = {
|
};
|
||||||
mode: 0o2775,
|
// Create the target directory
|
||||||
};
|
const directoryOptions = {
|
||||||
const { fileNameWithoutExtension } = getFileConstituents(filePath);
|
mode: 0o2775,
|
||||||
const targetDirectory = `${USERDATA_DIRECTORY}/covers/${fileNameWithoutExtension}`;
|
};
|
||||||
await fse.ensureDir(targetDirectory, directoryOptions);
|
const { fileNameWithoutExtension, extension, fileNameWithExtension } =
|
||||||
console.info(`%s was created.`, targetDirectory);
|
getFileConstituents(filePath);
|
||||||
|
const targetDirectory = `${USERDATA_DIRECTORY}/covers/${fileNameWithoutExtension}`;
|
||||||
|
await fse.ensureDir(targetDirectory, directoryOptions);
|
||||||
|
console.info(`%s was created.`, targetDirectory);
|
||||||
|
|
||||||
const archive = new Unrar({
|
const archive = new Unrar({
|
||||||
path: path.resolve(filePath),
|
path: path.resolve(filePath),
|
||||||
bin: `/usr/local/bin/unrar`, // this will change depending on Docker base OS
|
bin: `/usr/local/bin/unrar`, // this will change depending on Docker base OS
|
||||||
});
|
});
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
archive.list(async (err, entries) => {
|
archive.list(async (err, entries) => {
|
||||||
remove(entries, ({ type }) => type === "Directory");
|
remove(entries, ({ type }) => type === "Directory");
|
||||||
const comicInfoXML = remove(
|
const comicInfoXML = remove(
|
||||||
@@ -175,13 +179,25 @@ export const extractComicInfoXMLFromRar = async (
|
|||||||
if (err) {
|
if (err) {
|
||||||
console.log("Failed to resize image:");
|
console.log("Failed to resize image:");
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return err;
|
reject(err);
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
"Image file resized with the following parameters: %o",
|
"Image file resized with the following parameters: %o",
|
||||||
info
|
info
|
||||||
);
|
);
|
||||||
return info;
|
// orchestrate result
|
||||||
|
Object.assign(result, {
|
||||||
|
name: fileNameWithoutExtension,
|
||||||
|
extension,
|
||||||
|
containedIn: path.resolve(fileNameWithExtension),
|
||||||
|
cover: {
|
||||||
|
filePath: path.relative(
|
||||||
|
process.cwd(),
|
||||||
|
`${targetDirectory}/${files[0].name}`
|
||||||
|
),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
resolve(result);
|
||||||
});
|
});
|
||||||
// ComicInfo.xml extraction and parsing to JSON
|
// ComicInfo.xml extraction and parsing to JSON
|
||||||
if (!isUndefined(comicInfoXML[0])) {
|
if (!isUndefined(comicInfoXML[0])) {
|
||||||
@@ -200,12 +216,11 @@ export const extractComicInfoXMLFromRar = async (
|
|||||||
comicInfoString
|
comicInfoString
|
||||||
);
|
);
|
||||||
console.log(comicInfoJSON);
|
console.log(comicInfoJSON);
|
||||||
|
Object.assign(result, { comicInfo: comicInfoJSON });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
});
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractComicInfoXMLFromZip = async (
|
export const extractComicInfoXMLFromZip = async (
|
||||||
@@ -277,13 +292,15 @@ export const extractComicInfoXMLFromZip = async (
|
|||||||
);
|
);
|
||||||
comicInfoExtractionStream.on("end", async (data) => {
|
comicInfoExtractionStream.on("end", async (data) => {
|
||||||
console.log(`${comicInfoXML[0].file} was extracted.`);
|
console.log(`${comicInfoXML[0].file} was extracted.`);
|
||||||
const xml = await fs.readFile(`${targetDirectory}/${comicInfoXML[0].file}`);
|
const xml = await fs.readFile(
|
||||||
const comicInfoJSON = await convertXMLToJSON(xml.toString());
|
`${targetDirectory}/${comicInfoXML[0].file}`
|
||||||
|
);
|
||||||
|
const comicInfoJSON = await convertXMLToJSON(
|
||||||
|
xml.toString()
|
||||||
|
);
|
||||||
console.log(comicInfoJSON);
|
console.log(comicInfoJSON);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user