mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Update /api/thumbnail
This commit is contained in:
@@ -22,20 +22,75 @@ export type ThumbnailConfig = {
|
||||
height: number;
|
||||
quality: number;
|
||||
method: ThumbnailGenMethod;
|
||||
align: ThumbnailAlign;
|
||||
};
|
||||
|
||||
export function gen_thumbnail_config_params(cfg: ThumbnailConfig) {
|
||||
return {
|
||||
width: cfg.width.toString(),
|
||||
height: cfg.height.toString(),
|
||||
quality: cfg.quality.toString(),
|
||||
method: cfg.method.toString(),
|
||||
align: cfg.align.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
export function parse_thumbnail_method(s: string | null) {
|
||||
if (s === null) return ThumbnailGenMethod.Unknown;
|
||||
const t = s.toLowerCase();
|
||||
switch (t) {
|
||||
case "cover":
|
||||
return ThumbnailGenMethod.Cover;
|
||||
case "contain":
|
||||
return ThumbnailGenMethod.Contain;
|
||||
case "fill":
|
||||
return ThumbnailGenMethod.Fill;
|
||||
default:
|
||||
return ThumbnailGenMethod.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
export function parse_thumbnail_align(s: string | null) {
|
||||
if (s === null) return ThumbnailAlign.Left;
|
||||
const t = s.toLowerCase();
|
||||
switch (t) {
|
||||
case "center":
|
||||
return ThumbnailAlign.Center;
|
||||
case "right":
|
||||
case "bottom":
|
||||
return ThumbnailAlign.Right;
|
||||
default:
|
||||
return ThumbnailAlign.Left;
|
||||
}
|
||||
}
|
||||
|
||||
export function generate_filename(
|
||||
base: string,
|
||||
f: EhFile,
|
||||
cfg: ThumbnailConfig,
|
||||
) {
|
||||
let method = "";
|
||||
let balign = "";
|
||||
let align = "";
|
||||
switch (cfg.align) {
|
||||
case ThumbnailAlign.Left:
|
||||
balign = "-left";
|
||||
break;
|
||||
case ThumbnailAlign.Center:
|
||||
balign = "-center";
|
||||
break;
|
||||
case ThumbnailAlign.Right:
|
||||
balign = "-right";
|
||||
break;
|
||||
}
|
||||
switch (cfg.method) {
|
||||
case ThumbnailGenMethod.Cover:
|
||||
method = "-cover";
|
||||
align = balign;
|
||||
break;
|
||||
case ThumbnailGenMethod.Contain:
|
||||
method = "-contain";
|
||||
align = balign;
|
||||
break;
|
||||
case ThumbnailGenMethod.Fill:
|
||||
method = "-fill";
|
||||
@@ -44,7 +99,7 @@ export function generate_filename(
|
||||
return join(
|
||||
base,
|
||||
filterFilename(
|
||||
`${f.id}-${f.token}-${cfg.width}x${cfg.height}-q${cfg.quality}${method}.jpg`,
|
||||
`${f.id}-${f.token}-${cfg.width}x${cfg.height}-q${cfg.quality}${method}${align}.jpg`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference lib="deno.unstable" />
|
||||
import { Struct } from "pwn/mod.ts";
|
||||
import { ThumbnailAlign, ThumbnailGenMethod } from "./base.ts";
|
||||
import { ThumbnailAlign, ThumbnailConfig, ThumbnailGenMethod } from "./base.ts";
|
||||
|
||||
let libSuffix = "";
|
||||
let libPrefix = "lib";
|
||||
@@ -78,3 +78,25 @@ export async function gen_thumbnail(
|
||||
if (re.e) return get_error(ore);
|
||||
return;
|
||||
}
|
||||
|
||||
export async function fa_generate_thumbnail(
|
||||
i: string,
|
||||
o: string,
|
||||
cfg: ThumbnailConfig,
|
||||
) {
|
||||
let method = cfg.method;
|
||||
if (method === ThumbnailGenMethod.Unknown) method = ThumbnailGenMethod.Fill;
|
||||
const re = await gen_thumbnail(
|
||||
i,
|
||||
o,
|
||||
cfg.width,
|
||||
cfg.height,
|
||||
method,
|
||||
cfg.align,
|
||||
cfg.quality,
|
||||
);
|
||||
if (re) {
|
||||
console.error(re);
|
||||
}
|
||||
return re === undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user