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 {
let buffer: Buffer;
let content: string;
let queryResult: QueryResult[]
queryResult = await this.db.query("select content from `avatar_cache` where url = ? and size = ? limit 1", [url, size]);
if (queryResult.length) {
try {
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;
buffer = Buffer.from(content, "base64");
return buffer;
}
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]);
if (queryResult.length) {
try {
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;
buffer = Buffer.from(content, "base64");
} else {
......@@ -103,11 +111,15 @@ export class Avatar {
return null;
}
content = buffer.toString("base64");
await this.db.query("insert into `avatar_cache` set ?", {
url,
size: 0,
content
});
try {
await this.db.query("insert into `avatar_cache` set ?", {
url,
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", {
image: buffer.toJSON().data,
......@@ -119,11 +131,15 @@ export class Avatar {
return null;
}
const resizedBuffer = Buffer.from(resizedContentArray);
await this.db.query("insert into `avatar_cache` set ?", {
url,
size,
content: resizedBuffer.toString("base64")
});
try {
await this.db.query("insert into `avatar_cache` set ?", {
url,
size,
content: resizedBuffer.toString("base64")
});
} catch (e) {
console.error(`Failed to save avatar cache ${url} ${size}: ${e.toString()}`);
}
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