Rework #6

Merged
monoid merged 38 commits from dev into main 2024-04-17 01:45:37 +09:00
Showing only changes of commit 8eac72c0af - Show all commits

View File

@ -1,7 +1,8 @@
import { extname } from "node:path"; import { extname } from "node:path";
import type { DocumentBody } from "../model/doc"; import type { DocumentBody } from "../model/doc";
import { readAllFromZip, readZip } from "../util/zipwrap"; import { readZip } from "../util/zipwrap";
import { type ContentConstructOption, createDefaultClass, registerContentReferrer } from "./file"; import { type ContentConstructOption, createDefaultClass, registerContentReferrer } from "./file";
import { TextWriter } from "@zip.js/zip.js";
type ComicType = "doujinshi" | "artist cg" | "manga" | "western"; type ComicType = "doujinshi" | "artist cg" | "manga" | "western";
interface ComicDesc { interface ComicDesc {
@ -26,13 +27,17 @@ export class ComicReferrer extends createDefaultClass("comic") {
async initDesc(): Promise<void> { async initDesc(): Promise<void> {
if (this.desc !== undefined) return; if (this.desc !== undefined) return;
const zip = await readZip(this.path); const zip = await readZip(this.path);
const entries = await zip.entries(); const entries = await zip.reader.getEntries();
this.pagenum = Object.keys(entries).filter((x) => ImageExt.includes(extname(x))).length; this.pagenum = entries.filter((x) => ImageExt.includes(extname(x.filename))).length;
const entry = entries["desc.json"]; const entry = entries.find(x=> x.filename === "desc.json");
if (entry === undefined) { if (entry === undefined) {
return; return;
} }
const data = (await readAllFromZip(zip, entry)).toString("utf-8"); if (entry.getData === undefined) {
throw new Error("entry.getData is undefined");
}
const textWriter = new TextWriter();
const data = (await entry.getData(textWriter));
this.desc = JSON.parse(data); this.desc = JSON.parse(data);
if (this.desc === undefined) { if (this.desc === undefined) {
throw new Error(`JSON.parse is returning undefined. ${this.path} desc.json format error`); throw new Error(`JSON.parse is returning undefined. ${this.path} desc.json format error`);