Commit 79a4e4fa authored by nanahira's avatar nanahira

finish

parent 5aeea726
Pipeline #745 canceled with stages
in 2 minutes and 28 seconds
...@@ -1402,9 +1402,9 @@ ...@@ -1402,9 +1402,9 @@
} }
}, },
"@types/node": { "@types/node": {
"version": "14.0.9", "version": "14.10.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.9.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.10.3.tgz",
"integrity": "sha512-0sCTiXKXELOBxvZLN4krQ0FPOAA7ij+6WwvD0k/PHd9/KAkr4dXel5J9fh6F4x1FwAQILqAWkmpeuS6mjf1iKA==" "integrity": "sha512-zdN0hor7TLkjAdKTnYW+Y22oIhUUpil5ZD1V1OFq0CR0CLKw+NdR6dkziTfkWRLo6sKzisayoj/GNpNbe4LY9Q=="
}, },
"@types/normalize-package-data": { "@types/normalize-package-data": {
"version": "2.4.0", "version": "2.4.0",
...@@ -1465,6 +1465,11 @@ ...@@ -1465,6 +1465,11 @@
"@types/superagent": "*" "@types/superagent": "*"
} }
}, },
"@types/underscore": {
"version": "1.10.23",
"resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.10.23.tgz",
"integrity": "sha512-vX1NPekXhrLquFWskH2thcvFAha187F/lM6xYOoEMZWwJ/6alSk0/ttmGP/YRqcqtCv0TMbZjYAdZyHAEcuU4g=="
},
"@types/yargs": { "@types/yargs": {
"version": "15.0.5", "version": "15.0.5",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.5.tgz", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.5.tgz",
...@@ -8539,6 +8544,11 @@ ...@@ -8539,6 +8544,11 @@
} }
} }
}, },
"underscore": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.11.0.tgz",
"integrity": "sha512-xY96SsN3NA461qIRKZ/+qox37YXPtSBswMGfiNptr+wrt6ds4HaMw23TP612fEyGekRE6LNRiLYr/aqbHXNedw=="
},
"union-value": { "union-value": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz",
......
...@@ -83,7 +83,6 @@ export class Avatar { ...@@ -83,7 +83,6 @@ export class Avatar {
let content: string; let content: string;
let queryResult: QueryResult[] let queryResult: QueryResult[]
queryResult = await this.db.query("select content from `avatar_cache` where url = ? and size = ? limit 1", [url, size]); queryResult = await this.db.query("select content from `avatar_cache` where url = ? and size = ? limit 1", [url, size]);
console.log(queryResult);
if (queryResult.length) { if (queryResult.length) {
content = queryResult[0].content; content = queryResult[0].content;
buffer = Buffer.from(content, "base64"); buffer = Buffer.from(content, "base64");
...@@ -110,20 +109,21 @@ export class Avatar { ...@@ -110,20 +109,21 @@ export class Avatar {
content content
}); });
} }
const resizedContent: string = await this.processor.addTask("cut", { const resizedContentArray: number[] = await this.processor.addTask("cut", {
image: content, image: buffer.toJSON().data,
filename, filename,
size size
} as CutData); } as CutData);
if(!resizedContent) { if(!resizedContentArray) {
console.error(`Error resizing image of ${username} ${url} with size ${size}.`); console.error(`Error resizing image of ${username} ${url} with size ${size}.`);
return null; return null;
} }
const resizedBuffer = Buffer.from(resizedContentArray);
await this.db.query("insert into `avatar_cache` set ?", { await this.db.query("insert into `avatar_cache` set ?", {
url, url,
size, size,
content: resizedContent content: resizedBuffer.toString("base64")
}); });
return Buffer.from(resizedContent, "base64"); return resizedBuffer;
} }
} }
export interface CutData { export interface CutData {
image: string, // base64 image: number[],
filename: string, filename: string,
size: number size: number
} }
...@@ -8,16 +8,15 @@ export default async function worker() { ...@@ -8,16 +8,15 @@ export default async function worker() {
const processor = new Processor(); const processor = new Processor();
processor.addHandler("cut", async (cutData: CutData) => { processor.addHandler("cut", async (cutData: CutData) => {
try { try {
console.log(cutData.image); const sourceBuffer = Buffer.from(cutData.image);
const buf = Buffer.from(cutData.image); const targetBuffer: Buffer = await magick.promises.convert({
const targetBuffer: Buffer = await util.promisify(magick.convert)({
srcFormat: "PNG", srcFormat: "PNG",
format: "PNG", format: "PNG",
srcData: buf, srcData: sourceBuffer,
width: cutData.size, width: cutData.size,
height: cutData.size height: cutData.size
}); });
return targetBuffer.toString("base64"); return targetBuffer.toJSON().data;
} catch (e) { } catch (e) {
console.error(`Worker ${cluster.worker.id}: Error resizing image to ${cutData.size}: ${e.toString()}`); console.error(`Worker ${cluster.worker.id}: Error resizing image to ${cutData.size}: ${e.toString()}`);
return null; return null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment