diff --git a/.gitignore b/.gitignore index 2e709be..2d08fce 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,6 @@ db.sqlite3 build/** app/** settings.json -*config.json \ No newline at end of file +*config.json + +.pnpm-store/** \ No newline at end of file diff --git a/package.json b/package.json index b0331ba..fd3bb83 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "knex": "^0.95.11", "koa": "^2.13.1", "koa-bodyparser": "^4.3.0", + "koa-compose": "^4.1.0", "koa-router": "^10.0.0", "natural-orderby": "^2.0.3", "node-stream-zip": "^1.12.0", @@ -74,9 +75,8 @@ "@types/tiny-async-pool": "^1.0.0", "electron": "^11.2.0", "electron-builder": "^22.9.1", - "eslint-plugin-node": "^11.1.0", "ts-json-schema-generator": "^0.82.0", "ts-node": "^9.1.1", - "typescript": "^4.1.3" + "typescript": "^4.7.3" } } diff --git a/src/SettingConfig.ts b/src/SettingConfig.ts index 30fff18..ffc19d8 100644 --- a/src/SettingConfig.ts +++ b/src/SettingConfig.ts @@ -7,6 +7,10 @@ export interface SettingConfig { * if true, server will bind on '127.0.0.1' rather than '0.0.0.0' */ localmode: boolean, + /** + * secure only + */ + secure: boolean, /** * guest permission @@ -31,8 +35,8 @@ export interface SettingConfig { forbid_remote_admin_login:boolean, } const default_setting:SettingConfig = { - localmode: true, + secure: true, guest:[], jwt_secretkey:"itsRandom", port:8080, diff --git a/src/client/page/gallery.tsx b/src/client/page/gallery.tsx index e6fd441..77c479d 100644 --- a/src/client/page/gallery.tsx +++ b/src/client/page/gallery.tsx @@ -26,6 +26,7 @@ export const GalleryInfo = (props: GalleryProp) => { const c = await ContentAccessor.findList(props.option); //todo : if c is undefined, retry to fetch 3 times. and show error message. setState({ documents: c }); + setLoadAll(c.length > 0); }) load(); }, [props.diff]); @@ -59,7 +60,13 @@ export const GalleryInfo = (props: GalleryProp) => { ); function loadMore() { let option = {...props.option}; - option.cursor = state.documents[state.documents.length - 1].id; + if(state.documents === undefined || state.documents.length === 0){ + console.log("loadall"); + setLoadAll(true); + return; + } + const prev_documents = state.documents; + option.cursor = prev_documents[prev_documents.length - 1].id; console.log("load more", option); const load = (async () => { const c = await ContentAccessor.findList(option); @@ -67,7 +74,7 @@ export const GalleryInfo = (props: GalleryProp) => { setLoadAll(true); } else{ - setState({ documents: [...state.documents, ...c] }); + setState({ documents: [...prev_documents, ...c] }); } }); load(); diff --git a/src/login.ts b/src/login.ts index 68ae646..6f44ee6 100644 --- a/src/login.ts +++ b/src/login.ts @@ -70,19 +70,19 @@ const publishRefreshToken = ( ); return payload; }; -const setToken = ( +function setToken( ctx: Koa.Context, token_name: string, token_payload: string | null, expiredtime: number, -) => { +) { const setting = get_setting(); if (token_payload === null && !!!ctx.cookies.get(token_name)) { return; } ctx.cookies.set(token_name, token_payload, { httpOnly: true, - secure: !setting.localmode, + secure: setting.secure, sameSite: "strict", expires: new Date(Date.now() + expiredtime * 1000), }); diff --git a/src/route/comic.ts b/src/route/comic.ts index 071e7f8..9f46cd1 100644 --- a/src/route/comic.ts +++ b/src/route/comic.ts @@ -16,19 +16,18 @@ import Router from "koa-router"; let ZipStreamCache: { [path: string]: [ZipAsync, number] } = {}; async function acquireZip(path: string) { - if (ZipStreamCache[path] === undefined) { + if (!(path in ZipStreamCache)) { const ret = await readZip(path); - if (ZipStreamCache[path] === undefined) { - ZipStreamCache[path] = [ret, 1]; + ZipStreamCache[path] = [ret, 1]; //console.log(`acquire ${path} 1`); - return ret; - } - ret.close(); + return ret; + } + else { + const [ret, refCount] = ZipStreamCache[path]; + ZipStreamCache[path] = [ret, refCount + 1]; + //console.log(`acquire ${path} ${refCount + 1}`); + return ret; } - const [ret, refCount] = ZipStreamCache[path]; - ZipStreamCache[path] = [ret, refCount + 1]; - //console.log(`acquire ${path} ${refCount + 1}`); - return ret; } function releaseZip(path: string) { @@ -39,9 +38,10 @@ function releaseZip(path: string) { if (refCount === 1) { ref.close(); delete ZipStreamCache[path]; - return; } - ZipStreamCache[path] = [ref, refCount - 1]; + else{ + ZipStreamCache[path] = [ref, refCount - 1]; + } } async function renderZipImage(ctx: Context, path: string, page: number) {