Rework #6
					 1 changed files with 10 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -1,7 +1,8 @@
 | 
			
		|||
import { extname } from "node:path";
 | 
			
		||||
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 { TextWriter } from "@zip.js/zip.js";
 | 
			
		||||
 | 
			
		||||
type ComicType = "doujinshi" | "artist cg" | "manga" | "western";
 | 
			
		||||
interface ComicDesc {
 | 
			
		||||
| 
						 | 
				
			
			@ -26,13 +27,17 @@ export class ComicReferrer extends createDefaultClass("comic") {
 | 
			
		|||
	async initDesc(): Promise<void> {
 | 
			
		||||
		if (this.desc !== undefined) return;
 | 
			
		||||
		const zip = await readZip(this.path);
 | 
			
		||||
		const entries = await zip.entries();
 | 
			
		||||
		this.pagenum = Object.keys(entries).filter((x) => ImageExt.includes(extname(x))).length;
 | 
			
		||||
		const entry = entries["desc.json"];
 | 
			
		||||
		const entries = await zip.reader.getEntries();
 | 
			
		||||
		this.pagenum = entries.filter((x) => ImageExt.includes(extname(x.filename))).length;
 | 
			
		||||
		const entry = entries.find(x=> x.filename === "desc.json");
 | 
			
		||||
		if (entry === undefined) {
 | 
			
		||||
			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);
 | 
			
		||||
		if (this.desc === undefined) {
 | 
			
		||||
			throw new Error(`JSON.parse is returning undefined. ${this.path} desc.json format error`);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue