⚡️ Added MIMEtype key to Comic model
This commit is contained in:
@@ -25,15 +25,13 @@ const RawFileDetailsSchema = mongoose.Schema({
|
|||||||
filePath: String,
|
filePath: String,
|
||||||
fileSize: Number,
|
fileSize: Number,
|
||||||
extension: String,
|
extension: String,
|
||||||
|
mimeType: String,
|
||||||
containedIn: String,
|
containedIn: String,
|
||||||
pageCount: Number,
|
pageCount: Number,
|
||||||
cover: {
|
cover: {
|
||||||
filePath: String,
|
filePath: String,
|
||||||
stats: Object,
|
stats: Object,
|
||||||
},
|
},
|
||||||
calibreMetadata: {
|
|
||||||
coverWriteResult: String,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const LOCGSchema = mongoose.Schema({
|
const LOCGSchema = mongoose.Schema({
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ export default class QueueService extends Service {
|
|||||||
filePath,
|
filePath,
|
||||||
fileSize,
|
fileSize,
|
||||||
extension,
|
extension,
|
||||||
|
mimeType,
|
||||||
cover,
|
cover,
|
||||||
containedIn,
|
containedIn,
|
||||||
comicInfoJSON,
|
comicInfoJSON,
|
||||||
@@ -113,6 +114,7 @@ export default class QueueService extends Service {
|
|||||||
filePath,
|
filePath,
|
||||||
fileSize,
|
fileSize,
|
||||||
extension,
|
extension,
|
||||||
|
mimeType,
|
||||||
containedIn,
|
containedIn,
|
||||||
cover,
|
cover,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ interface RarFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const UNRAR_BIN_PATH = process.env.UNRAR_BIN_PATH || "/usr/local/bin/unrar";
|
const UNRAR_BIN_PATH = process.env.UNRAR_BIN_PATH || "/usr/local/bin/unrar";
|
||||||
|
// errors array
|
||||||
|
const errors = [];
|
||||||
/**
|
/**
|
||||||
* Method that extracts comicInfo.xml file from a .rar archive, if one exists.
|
* Method that extracts comicInfo.xml file from a .rar archive, if one exists.
|
||||||
* Also extracts the first image in the listing, which is assumed to be the cover.
|
* Also extracts the first image in the listing, which is assumed to be the cover.
|
||||||
@@ -71,7 +72,8 @@ const UNRAR_BIN_PATH = process.env.UNRAR_BIN_PATH || "/usr/local/bin/unrar";
|
|||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
export const extractComicInfoXMLFromRar = async (
|
export const extractComicInfoXMLFromRar = async (
|
||||||
filePath: string
|
filePath: string,
|
||||||
|
mimeType: string,
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
// Create the target directory
|
// Create the target directory
|
||||||
@@ -185,6 +187,7 @@ export const extractComicInfoXMLFromRar = async (
|
|||||||
extension,
|
extension,
|
||||||
containedIn: targetDirectory,
|
containedIn: targetDirectory,
|
||||||
fileSize: fse.statSync(filePath).size,
|
fileSize: fse.statSync(filePath).size,
|
||||||
|
mimeType,
|
||||||
cover: {
|
cover: {
|
||||||
filePath: path.relative(
|
filePath: path.relative(
|
||||||
process.cwd(),
|
process.cwd(),
|
||||||
@@ -205,7 +208,8 @@ export const extractComicInfoXMLFromRar = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const extractComicInfoXMLFromZip = async (
|
export const extractComicInfoXMLFromZip = async (
|
||||||
filePath: string
|
filePath: string,
|
||||||
|
mimeType: string,
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
// Create the target directory
|
// Create the target directory
|
||||||
@@ -250,9 +254,7 @@ export const extractComicInfoXMLFromZip = async (
|
|||||||
// Push the first file (cover) to our extraction target
|
// Push the first file (cover) to our extraction target
|
||||||
extractionTargets.push(files[0].name);
|
extractionTargets.push(files[0].name);
|
||||||
filesToWriteToDisk.coverFile = path.basename(files[0].name);
|
filesToWriteToDisk.coverFile = path.basename(files[0].name);
|
||||||
console.log(
|
|
||||||
`sanitized or not, here I am: ${filesToWriteToDisk.coverFile}`
|
|
||||||
);
|
|
||||||
if (!isEmpty(comicInfoXMLFileObject)) {
|
if (!isEmpty(comicInfoXMLFileObject)) {
|
||||||
filesToWriteToDisk.comicInfoXML = comicInfoXMLFileObject[0].name;
|
filesToWriteToDisk.comicInfoXML = comicInfoXMLFileObject[0].name;
|
||||||
extractionTargets.push(filesToWriteToDisk.comicInfoXML);
|
extractionTargets.push(filesToWriteToDisk.comicInfoXML);
|
||||||
@@ -323,6 +325,7 @@ export const extractComicInfoXMLFromZip = async (
|
|||||||
filePath,
|
filePath,
|
||||||
name: fileNameWithoutExtension,
|
name: fileNameWithoutExtension,
|
||||||
extension,
|
extension,
|
||||||
|
mimeType,
|
||||||
containedIn: targetDirectory,
|
containedIn: targetDirectory,
|
||||||
fileSize: fse.statSync(filePath).size,
|
fileSize: fse.statSync(filePath).size,
|
||||||
cover: {
|
cover: {
|
||||||
@@ -347,20 +350,17 @@ export const extractComicInfoXMLFromZip = async (
|
|||||||
export const extractFromArchive = async (filePath: string) => {
|
export const extractFromArchive = async (filePath: string) => {
|
||||||
console.info(`Unrar is located at: ${UNRAR_BIN_PATH}`);
|
console.info(`Unrar is located at: ${UNRAR_BIN_PATH}`);
|
||||||
console.info(`p7zip is located at: ${process.env.SEVENZ_BINARY_PATH}`);
|
console.info(`p7zip is located at: ${process.env.SEVENZ_BINARY_PATH}`);
|
||||||
const { extension } = getFileConstituents(filePath);
|
|
||||||
console.log(
|
|
||||||
`Detected file type is ${extension}, looking for comicinfo.xml...`
|
|
||||||
);
|
|
||||||
const mimeType = await getMimeType(filePath);
|
const mimeType = await getMimeType(filePath);
|
||||||
console.log(`File has the following mime-type: ${mimeType}`);
|
console.log(`File has the following mime-type: ${mimeType}`);
|
||||||
switch (mimeType) {
|
switch (mimeType) {
|
||||||
case "application/x-7z-compressed; charset=binary":
|
case "application/x-7z-compressed; charset=binary":
|
||||||
case "application/zip; charset=binary":
|
case "application/zip; charset=binary":
|
||||||
const cbzResult = await extractComicInfoXMLFromZip(filePath);
|
const cbzResult = await extractComicInfoXMLFromZip(filePath, mimeType);
|
||||||
return Object.assign({}, ...cbzResult);
|
return Object.assign({}, ...cbzResult);
|
||||||
|
|
||||||
case "application/x-rar; charset=binary":
|
case "application/x-rar; charset=binary":
|
||||||
const cbrResult = await extractComicInfoXMLFromRar(filePath);
|
const cbrResult = await extractComicInfoXMLFromRar(filePath, mimeType);
|
||||||
return Object.assign({}, ...cbrResult);
|
return Object.assign({}, ...cbrResult);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -381,13 +381,20 @@ export const uncompressEntireArchive = async (
|
|||||||
filePath: string,
|
filePath: string,
|
||||||
options: any
|
options: any
|
||||||
) => {
|
) => {
|
||||||
const { extension } = getFileConstituents(filePath);
|
const mimeType = await getMimeType(filePath);
|
||||||
switch (extension) {
|
console.log(`File has the following mime-type: ${mimeType}`);
|
||||||
case ".cbz":
|
switch (mimeType) {
|
||||||
case ".cb7":
|
case "application/x-7z-compressed; charset=binary":
|
||||||
return await uncompressZipArchive(filePath, options);
|
case "application/zip; charset=binary":
|
||||||
case ".cbr":
|
return await uncompressZipArchive(filePath, {
|
||||||
return await uncompressRarArchive(filePath, options);
|
...options,
|
||||||
|
mimeType,
|
||||||
|
});
|
||||||
|
case "application/x-rar; charset=binary":
|
||||||
|
return await uncompressRarArchive(filePath, {
|
||||||
|
...options,
|
||||||
|
mimeType,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user