🔧 Refactoring
This commit is contained in:
@@ -12,7 +12,6 @@ const ComicSchema = mongoose.Schema({
|
|||||||
userAddedMetadata: {
|
userAddedMetadata: {
|
||||||
tags: [],
|
tags: [],
|
||||||
},
|
},
|
||||||
|
|
||||||
comicInfo: {
|
comicInfo: {
|
||||||
blackAndWhite: String,
|
blackAndWhite: String,
|
||||||
characters: [String],
|
characters: [String],
|
||||||
|
|||||||
@@ -37,14 +37,14 @@ export default class ProductsService extends Service {
|
|||||||
params: {},
|
params: {},
|
||||||
async handler(
|
async handler(
|
||||||
ctx: Context<{
|
ctx: Context<{
|
||||||
path: string;
|
imageFile: string | Buffer;
|
||||||
newWidth: number;
|
newWidth: number;
|
||||||
newHeight: number;
|
newHeight: number;
|
||||||
outputPath: string;
|
outputPath: string;
|
||||||
}>
|
}>
|
||||||
) {
|
) {
|
||||||
const resizeResult = await resizeImage(
|
const resizeResult = await resizeImage(
|
||||||
ctx.params.path,
|
ctx.params.imageFile,
|
||||||
ctx.params.outputPath,
|
ctx.params.outputPath,
|
||||||
ctx.params.newWidth,
|
ctx.params.newWidth,
|
||||||
ctx.params.newHeight
|
ctx.params.newHeight
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
const sharp = require("sharp");
|
const sharp = require("sharp");
|
||||||
import { logger } from "./logger.utils";
|
import { logger } from "./logger.utils";
|
||||||
import { explodePath } from "./file.utils";
|
|
||||||
import { isUndefined } from "lodash";
|
|
||||||
|
|
||||||
export const extractMetadataFromImage = async (
|
export const extractMetadataFromImage = async (
|
||||||
imageFilePath: string
|
imageFilePath: string
|
||||||
@@ -15,12 +13,12 @@ export const extractMetadataFromImage = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const resizeImage = async (
|
export const resizeImage = async (
|
||||||
imageFilePath: string,
|
imageFile: string | Buffer,
|
||||||
outputPath: string,
|
outputPath: string,
|
||||||
newWidth: number,
|
newWidth: number,
|
||||||
newHeight?: number
|
newHeight?: number
|
||||||
): Promise<unknown> => {
|
): Promise<unknown> => {
|
||||||
return await sharp(imageFilePath)
|
return await sharp(imageFile)
|
||||||
.resize(newWidth)
|
.resize(newWidth)
|
||||||
.toFile(`${outputPath}`, (err, info) => {
|
.toFile(`${outputPath}`, (err, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ SOFTWARE.
|
|||||||
|
|
||||||
import { createReadStream, createWriteStream } from "fs";
|
import { createReadStream, createWriteStream } from "fs";
|
||||||
const fse = require("fs-extra");
|
const fse = require("fs-extra");
|
||||||
import path from "path";
|
|
||||||
import { default as unzipper } from "unzipper";
|
import { default as unzipper } from "unzipper";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { each, isEmpty, map, remove, indexOf } from "lodash";
|
import { each, isEmpty, map } from "lodash";
|
||||||
import {
|
import {
|
||||||
IExplodedPathResponse,
|
IExplodedPathResponse,
|
||||||
IExtractComicBookCoverErrorResponse,
|
IExtractComicBookCoverErrorResponse,
|
||||||
@@ -47,6 +47,7 @@ import {
|
|||||||
import { logger } from "./logger.utils";
|
import { logger } from "./logger.utils";
|
||||||
import { validateComicBookMetadata } from "../utils/validation.utils";
|
import { validateComicBookMetadata } from "../utils/validation.utils";
|
||||||
import { constructPaths, explodePath } from "../utils/file.utils";
|
import { constructPaths, explodePath } from "../utils/file.utils";
|
||||||
|
import { resizeImage } from "./imagetransformation.utils";
|
||||||
const { writeFile, readFile } = require("fs").promises;
|
const { writeFile, readFile } = require("fs").promises;
|
||||||
const unrarer = require("node-unrar-js");
|
const unrarer = require("node-unrar-js");
|
||||||
|
|
||||||
@@ -99,9 +100,13 @@ export const unrar = async (
|
|||||||
});
|
});
|
||||||
const extractedFile = [...file.files][0];
|
const extractedFile = [...file.files][0];
|
||||||
const fileArrayBuffer = extractedFile.extraction;
|
const fileArrayBuffer = extractedFile.extraction;
|
||||||
await writeFile(
|
// Resize it to the specified width
|
||||||
paths.targetPath + "/" + fileName,
|
const outputFilePath =
|
||||||
fileArrayBuffer
|
paths.targetPath + "/" + fileName;
|
||||||
|
await resizeImage(
|
||||||
|
fileArrayBuffer,
|
||||||
|
outputFilePath,
|
||||||
|
200
|
||||||
);
|
);
|
||||||
let comicBookMetadata = {
|
let comicBookMetadata = {
|
||||||
name: `${fileName}`,
|
name: `${fileName}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user