Add new settings jpn_title to export zip task

This commit is contained in:
2023-06-11 09:34:19 +08:00
parent 28387eda1c
commit f16264dfbc
10 changed files with 48 additions and 12 deletions

View File

@@ -1,8 +1,13 @@
import { Uint8ArrayReader, ZipWriter } from "zipjs/index.js";
import { EhDb, PMeta } from "../db.ts";
import { ExportZipConfig } from "../tasks/export_zip.ts";
import { addZero, configureZipJs } from "../utils.ts";
export function get_export_zip_response(gid: number, db: EhDb) {
export function get_export_zip_response(
gid: number,
db: EhDb,
cfg: ExportZipConfig,
) {
const gmeta = db.get_gmeta_by_gid(gid);
if (!gmeta) return new Response("Gallery not found.", { status: 404 });
const pmetas = db.get_pmeta(gid).sort((a, b) => a.index - b.index);
@@ -114,11 +119,14 @@ export function get_export_zip_response(gid: number, db: EhDb) {
},
type: "bytes",
});
const title = (cfg.jpn_title && gmeta.title_jpn)
? gmeta.title_jpn
: gmeta.title;
return new Response(readable, {
headers: {
"content-type": "application/zip",
"Content-Disposition": `attachment; filename="${
encodeURIComponent(gmeta.title)
encodeURIComponent(title)
}.zip"`,
},
});

View File

@@ -1,5 +1,6 @@
import { Task } from "../task.ts";
import { TaskEventData } from "../task_manager.ts";
import { ExportZipConfig } from "../tasks/export_zip.ts";
import { DiscriminatedUnion } from "../utils.ts";
export type TaskServerSocketData = TaskEventData | { type: "close" } | {
@@ -8,9 +9,12 @@ export type TaskServerSocketData = TaskEventData | { type: "close" } | {
running: number[];
};
type Gid<T extends Record<PropertyKey, unknown>> = ({ gid: number } & T) extends
infer U ? { [Q in keyof U]: U[Q] } : never;
type EventMap = {
new_download_task: { gid: number; token: string };
new_export_zip_task: { gid: number; output?: string };
new_export_zip_task: Gid<ExportZipConfig>;
};
export type TaskClientSocketData = DiscriminatedUnion<"type", EventMap> | {