mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Add max_length settings to export zip
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
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";
|
||||
import { addZero, configureZipJs, limitFilename } from "../utils.ts";
|
||||
|
||||
export function get_export_zip_response(
|
||||
gid: number,
|
||||
@@ -47,12 +47,13 @@ export function get_export_zip_response(
|
||||
let closed = false;
|
||||
const signalc = new AbortController();
|
||||
const signal = signalc.signal;
|
||||
const maxLength = cfg.max_length || 0;
|
||||
const download_task = async (p: PMeta) => {
|
||||
const f = db.get_files(p.token);
|
||||
if (f.length) {
|
||||
const r = await Deno.readFile(f[0].path, { signal });
|
||||
await zip_writer.add(
|
||||
`${addZero(p.index, l)}_${p.name}`,
|
||||
limitFilename(`${addZero(p.index, l)}_${p.name}`, maxLength),
|
||||
new Uint8ArrayReader(r),
|
||||
{ signal },
|
||||
);
|
||||
|
||||
@@ -12,3 +12,14 @@ export async function parse_bool<T extends boolean | null>(
|
||||
return n !== 0;
|
||||
}
|
||||
}
|
||||
|
||||
export async function parse_int<T extends number | null>(
|
||||
value: FormDataEntryValue | null,
|
||||
def: T,
|
||||
): Promise<number | T> {
|
||||
if (value === null) return def;
|
||||
const v = typeof value === "string" ? value : await value.text();
|
||||
const n = parseInt(v);
|
||||
if (isNaN(n)) return def;
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { assertEquals } from "std/testing/asserts.ts";
|
||||
import { parse_bool } from "./parse_form.ts";
|
||||
import { parse_bool, parse_int } from "./parse_form.ts";
|
||||
|
||||
Deno.test("parse_bool_test", async () => {
|
||||
const f = new FormData();
|
||||
@@ -15,3 +15,15 @@ Deno.test("parse_bool_test", async () => {
|
||||
f.append("e", "tRUE", "a.png");
|
||||
assertEquals(await parse_bool(f.get("e"), null), true);
|
||||
});
|
||||
|
||||
Deno.test("parse_int_test", async () => {
|
||||
const f = new FormData();
|
||||
f.append("a", "d");
|
||||
assertEquals(await parse_int(f.get("a"), null), null);
|
||||
assertEquals(await parse_int(f.get("a"), 1), 1);
|
||||
f.append("c", "1");
|
||||
assertEquals(await parse_int(f.get("c"), null), 1);
|
||||
assertEquals(await parse_int(f.get("c"), 2), 1);
|
||||
f.append("d", "-1");
|
||||
assertEquals(await parse_int(f.get("d"), null), -1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user