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 @@
}
},
"@types/node": {
"version": "14.0.9",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.9.tgz",
"integrity": "sha512-0sCTiXKXELOBxvZLN4krQ0FPOAA7ij+6WwvD0k/PHd9/KAkr4dXel5J9fh6F4x1FwAQILqAWkmpeuS6mjf1iKA=="
"version": "14.10.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.10.3.tgz",
"integrity": "sha512-zdN0hor7TLkjAdKTnYW+Y22oIhUUpil5ZD1V1OFq0CR0CLKw+NdR6dkziTfkWRLo6sKzisayoj/GNpNbe4LY9Q=="
},
"@types/normalize-package-data": {
"version": "2.4.0",
......@@ -1465,6 +1465,11 @@
"@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": {
"version": "15.0.5",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.5.tgz",
......@@ -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": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz",
......
......@@ -83,7 +83,6 @@ export class Avatar {
let content: string;
let queryResult: QueryResult[]
queryResult = await this.db.query("select content from `avatar_cache` where url = ? and size = ? limit 1", [url, size]);
console.log(queryResult);
if (queryResult.length) {
content = queryResult[0].content;
buffer = Buffer.from(content, "base64");
......@@ -110,20 +109,21 @@ export class Avatar {
content
});
}
const resizedContent: string = await this.processor.addTask("cut", {
image: content,
const resizedContentArray: number[] = await this.processor.addTask("cut", {
image: buffer.toJSON().data,
filename,
size
} as CutData);
if(!resizedContent) {
if(!resizedContentArray) {
console.error(`Error resizing image of ${username} ${url} with size ${size}.`);
return null;
}
const resizedBuffer = Buffer.from(resizedContentArray);
await this.db.query("insert into `avatar_cache` set ?", {
url,
size,
content: resizedContent
content: resizedBuffer.toString("base64")
});
return Buffer.from(resizedContent, "base64");
return resizedBuffer;
}
}
export interface CutData {
image: string, // base64
image: number[],
filename: string,
size: number
}
......@@ -8,16 +8,15 @@ export default async function worker() {
const processor = new Processor();
processor.addHandler("cut", async (cutData: CutData) => {
try {
console.log(cutData.image);
const buf = Buffer.from(cutData.image);
const targetBuffer: Buffer = await util.promisify(magick.convert)({
const sourceBuffer = Buffer.from(cutData.image);
const targetBuffer: Buffer = await magick.promises.convert({
srcFormat: "PNG",
format: "PNG",
srcData: buf,
srcData: sourceBuffer,
width: cutData.size,
height: cutData.size
});
return targetBuffer.toString("base64");
return targetBuffer.toJSON().data;
} catch (e) {
console.error(`Worker ${cluster.worker.id}: Error resizing image to ${cutData.size}: ${e.toString()}`);
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