mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -04:00
Properly handle image cache
This commit is contained in:
parent
af97c52e48
commit
9e3a9af0ef
2
.github/workflows/auth-hurl.yml
vendored
2
.github/workflows/auth-hurl.yml
vendored
@ -48,7 +48,7 @@ jobs:
|
||||
working-directory: ./auth
|
||||
run: |
|
||||
./keibi > logs &
|
||||
wget --retry-connrefused --retry-on-http-error=502 http://localhost:4568/health
|
||||
wget --retry-connrefused --retry-on-http-error=502 http://localhost:4568/auth/health
|
||||
hurl --error-format long --variable host=http://localhost:4568/auth tests/*
|
||||
env:
|
||||
PGHOST: localhost
|
||||
|
@ -131,7 +131,7 @@ export const processImages = async () => {
|
||||
if (evt.channel !== "kyoo_image") return;
|
||||
processAll();
|
||||
});
|
||||
await client.query("listen image");
|
||||
await client.query("listen kyoo_image");
|
||||
|
||||
// start processing old tasks
|
||||
await processAll();
|
||||
@ -139,7 +139,13 @@ export const processImages = async () => {
|
||||
};
|
||||
|
||||
async function downloadImage(id: string, url: string): Promise<string> {
|
||||
// TODO: check if file exists before downloading
|
||||
const low = await getFile(path.join(imageDir, `${id}.low.jpg`))
|
||||
.arrayBuffer()
|
||||
.catch(() => false as const);
|
||||
if (low) {
|
||||
return await getBlurhash(sharp(low));
|
||||
}
|
||||
|
||||
const resp = await fetch(url, {
|
||||
headers: { "User-Agent": `Kyoo v${version}` },
|
||||
});
|
||||
@ -167,20 +173,15 @@ async function downloadImage(id: string, url: string): Promise<string> {
|
||||
await Bun.write(file, buffer, { mode: 0o660 });
|
||||
}),
|
||||
);
|
||||
return await getBlurhash(image);
|
||||
}
|
||||
|
||||
async function getBlurhash(image: sharp.Sharp): Promise<string> {
|
||||
const { data, info } = await image
|
||||
.resize(32, 32, { fit: "inside" })
|
||||
.ensureAlpha()
|
||||
.raw()
|
||||
.toBuffer({ resolveWithObject: true });
|
||||
|
||||
const blurHash = encode(
|
||||
new Uint8ClampedArray(data),
|
||||
info.width,
|
||||
info.height,
|
||||
4,
|
||||
3,
|
||||
);
|
||||
|
||||
return blurHash;
|
||||
return encode(new Uint8ClampedArray(data), info.width, info.height, 4, 3);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user