Commit 092a96e0 authored by nanahira's avatar nanahira

fix

parent ee0cc0ae
Pipeline #3244 failed with stages
in 2 minutes and 39 seconds
...@@ -82,15 +82,23 @@ export class Avatar { ...@@ -82,15 +82,23 @@ export class Avatar {
let buffer: Buffer; let buffer: Buffer;
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]); try {
if (queryResult.length) { queryResult = await this.db.query("select content from `avatar_cache` where url = ? and size = ? limit 1", [url, size]);
} catch (e) {
console.error(`Failed to fetch avatar cache ${url} ${size}: ${e.toString()}`);
}
if (queryResult && queryResult.length) {
content = queryResult[0].content; content = queryResult[0].content;
buffer = Buffer.from(content, "base64"); buffer = Buffer.from(content, "base64");
return buffer; return buffer;
} }
console.error(`Resizing image of ${username} ${url} with size ${size}.`); console.error(`Resizing image of ${username} ${url} with size ${size}.`);
queryResult = await this.db.query("select content from `avatar_cache` where url = ? and size = 0 limit 1", [url, size]); try {
if (queryResult.length) { queryResult = await this.db.query("select content from `avatar_cache` where url = ? and size = 0 limit 1", [url, size]);
} catch (e) {
console.error(`Failed to fetch original avatar cache ${url} ${size}: ${e.toString()}`);
}
if (queryResult && queryResult.length) {
content = queryResult[0].content; content = queryResult[0].content;
buffer = Buffer.from(content, "base64"); buffer = Buffer.from(content, "base64");
} else { } else {
...@@ -103,11 +111,15 @@ export class Avatar { ...@@ -103,11 +111,15 @@ export class Avatar {
return null; return null;
} }
content = buffer.toString("base64"); content = buffer.toString("base64");
await this.db.query("insert into `avatar_cache` set ?", { try {
url, await this.db.query("insert into `avatar_cache` set ?", {
size: 0, url,
content size: 0,
}); content
});
} catch (e) {
console.error(`Failed to save original avatar cache ${url} ${size}: ${e.toString()}`);
}
} }
const resizedContentArray: number[] = await this.processor.addTask("cut", { const resizedContentArray: number[] = await this.processor.addTask("cut", {
image: buffer.toJSON().data, image: buffer.toJSON().data,
...@@ -119,11 +131,15 @@ export class Avatar { ...@@ -119,11 +131,15 @@ export class Avatar {
return null; return null;
} }
const resizedBuffer = Buffer.from(resizedContentArray); const resizedBuffer = Buffer.from(resizedContentArray);
await this.db.query("insert into `avatar_cache` set ?", { try {
url, await this.db.query("insert into `avatar_cache` set ?", {
size, url,
content: resizedBuffer.toString("base64") size,
}); content: resizedBuffer.toString("base64")
});
} catch (e) {
console.error(`Failed to save avatar cache ${url} ${size}: ${e.toString()}`);
}
return resizedBuffer; return resizedBuffer;
} }
} }
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