mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-06 05:38:44 +08:00
Add /api/thumbnail/[id]
This commit is contained in:
22
thumbnail/base.ts
Normal file
22
thumbnail/base.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { join } from "std/path/mod.ts";
|
||||
import { filterFilename } from "../utils.ts";
|
||||
import { EhFile } from "../db.ts";
|
||||
|
||||
export type ThumbnailConfig = {
|
||||
width: number;
|
||||
height: number;
|
||||
quality: number;
|
||||
};
|
||||
|
||||
export function generate_filename(
|
||||
base: string,
|
||||
f: EhFile,
|
||||
cfg: ThumbnailConfig,
|
||||
) {
|
||||
return join(
|
||||
base,
|
||||
filterFilename(
|
||||
`${f.id}-${f.token}-${cfg.width}x${cfg.height}-q${cfg.quality}.jpg`,
|
||||
),
|
||||
);
|
||||
}
|
||||
43
thumbnail/ffmpeg_binary.ts
Normal file
43
thumbnail/ffmpeg_binary.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { ThumbnailConfig } from "./base.ts";
|
||||
|
||||
export async function check_ffmpeg_binary(p: string) {
|
||||
const cmd = new Deno.Command(p, {
|
||||
stdout: "null",
|
||||
stderr: "null",
|
||||
args: ["-h"],
|
||||
});
|
||||
const c = cmd.spawn();
|
||||
const o = await c.output();
|
||||
return o.code === 0;
|
||||
}
|
||||
|
||||
export async function fb_generate_thumbnail(
|
||||
p: string,
|
||||
i: string,
|
||||
o: string,
|
||||
cfg: ThumbnailConfig,
|
||||
) {
|
||||
const args = [
|
||||
"-i",
|
||||
i,
|
||||
"-vf",
|
||||
`scale=${cfg.width}:${cfg.height}`,
|
||||
"-qmin",
|
||||
`${cfg.quality}`,
|
||||
"-qmax",
|
||||
`${cfg.quality}`,
|
||||
o,
|
||||
];
|
||||
const cmd = new Deno.Command(p, { args, stdout: "null", stderr: "piped" });
|
||||
const c = cmd.spawn();
|
||||
const s = await c.output();
|
||||
if (s.code !== 0) {
|
||||
try {
|
||||
const d = (new TextDecoder()).decode(s.stderr);
|
||||
console.log(d);
|
||||
} catch (_) {
|
||||
console.log(s.stderr);
|
||||
}
|
||||
}
|
||||
return s.code === 0;
|
||||
}
|
||||
Reference in New Issue
Block a user