fix: read comic meta data
This commit is contained in:
parent
385391334a
commit
8eac72c0af
@ -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`);
|
||||||
|
Loading…
Reference in New Issue
Block a user