fix config and gallery

This commit is contained in:
JaeUng 2022-06-20 16:42:31 +09:00 committed by monoid
parent 4443e80b6f
commit 3dbcf56546
6 changed files with 34 additions and 21 deletions

4
.gitignore vendored
View File

@ -12,4 +12,6 @@ db.sqlite3
build/** build/**
app/** app/**
settings.json settings.json
*config.json *config.json
.pnpm-store/**

View File

@ -59,6 +59,7 @@
"knex": "^0.95.11", "knex": "^0.95.11",
"koa": "^2.13.1", "koa": "^2.13.1",
"koa-bodyparser": "^4.3.0", "koa-bodyparser": "^4.3.0",
"koa-compose": "^4.1.0",
"koa-router": "^10.0.0", "koa-router": "^10.0.0",
"natural-orderby": "^2.0.3", "natural-orderby": "^2.0.3",
"node-stream-zip": "^1.12.0", "node-stream-zip": "^1.12.0",
@ -74,9 +75,8 @@
"@types/tiny-async-pool": "^1.0.0", "@types/tiny-async-pool": "^1.0.0",
"electron": "^11.2.0", "electron": "^11.2.0",
"electron-builder": "^22.9.1", "electron-builder": "^22.9.1",
"eslint-plugin-node": "^11.1.0",
"ts-json-schema-generator": "^0.82.0", "ts-json-schema-generator": "^0.82.0",
"ts-node": "^9.1.1", "ts-node": "^9.1.1",
"typescript": "^4.1.3" "typescript": "^4.7.3"
} }
} }

View File

@ -7,6 +7,10 @@ export interface SettingConfig {
* if true, server will bind on '127.0.0.1' rather than '0.0.0.0' * if true, server will bind on '127.0.0.1' rather than '0.0.0.0'
*/ */
localmode: boolean, localmode: boolean,
/**
* secure only
*/
secure: boolean,
/** /**
* guest permission * guest permission
@ -31,8 +35,8 @@ export interface SettingConfig {
forbid_remote_admin_login:boolean, forbid_remote_admin_login:boolean,
} }
const default_setting:SettingConfig = { const default_setting:SettingConfig = {
localmode: true, localmode: true,
secure: true,
guest:[], guest:[],
jwt_secretkey:"itsRandom", jwt_secretkey:"itsRandom",
port:8080, port:8080,

View File

@ -26,6 +26,7 @@ export const GalleryInfo = (props: GalleryProp) => {
const c = await ContentAccessor.findList(props.option); const c = await ContentAccessor.findList(props.option);
//todo : if c is undefined, retry to fetch 3 times. and show error message. //todo : if c is undefined, retry to fetch 3 times. and show error message.
setState({ documents: c }); setState({ documents: c });
setLoadAll(c.length > 0);
}) })
load(); load();
}, [props.diff]); }, [props.diff]);
@ -59,7 +60,13 @@ export const GalleryInfo = (props: GalleryProp) => {
); );
function loadMore() { function loadMore() {
let option = {...props.option}; 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); console.log("load more", option);
const load = (async () => { const load = (async () => {
const c = await ContentAccessor.findList(option); const c = await ContentAccessor.findList(option);
@ -67,7 +74,7 @@ export const GalleryInfo = (props: GalleryProp) => {
setLoadAll(true); setLoadAll(true);
} }
else{ else{
setState({ documents: [...state.documents, ...c] }); setState({ documents: [...prev_documents, ...c] });
} }
}); });
load(); load();

View File

@ -70,19 +70,19 @@ const publishRefreshToken = (
); );
return payload; return payload;
}; };
const setToken = ( function setToken(
ctx: Koa.Context, ctx: Koa.Context,
token_name: string, token_name: string,
token_payload: string | null, token_payload: string | null,
expiredtime: number, expiredtime: number,
) => { ) {
const setting = get_setting(); const setting = get_setting();
if (token_payload === null && !!!ctx.cookies.get(token_name)) { if (token_payload === null && !!!ctx.cookies.get(token_name)) {
return; return;
} }
ctx.cookies.set(token_name, token_payload, { ctx.cookies.set(token_name, token_payload, {
httpOnly: true, httpOnly: true,
secure: !setting.localmode, secure: setting.secure,
sameSite: "strict", sameSite: "strict",
expires: new Date(Date.now() + expiredtime * 1000), expires: new Date(Date.now() + expiredtime * 1000),
}); });

View File

@ -16,19 +16,18 @@ import Router from "koa-router";
let ZipStreamCache: { [path: string]: [ZipAsync, number] } = {}; let ZipStreamCache: { [path: string]: [ZipAsync, number] } = {};
async function acquireZip(path: string) { async function acquireZip(path: string) {
if (ZipStreamCache[path] === undefined) { if (!(path in ZipStreamCache)) {
const ret = await readZip(path); const ret = await readZip(path);
if (ZipStreamCache[path] === undefined) { ZipStreamCache[path] = [ret, 1];
ZipStreamCache[path] = [ret, 1];
//console.log(`acquire ${path} 1`); //console.log(`acquire ${path} 1`);
return ret; return ret;
} }
ret.close(); 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) { function releaseZip(path: string) {
@ -39,9 +38,10 @@ function releaseZip(path: string) {
if (refCount === 1) { if (refCount === 1) {
ref.close(); ref.close();
delete ZipStreamCache[path]; delete ZipStreamCache[path];
return;
} }
ZipStreamCache[path] = [ref, refCount - 1]; else{
ZipStreamCache[path] = [ref, refCount - 1];
}
} }
async function renderZipImage(ctx: Context, path: string, page: number) { async function renderZipImage(ctx: Context, path: string, page: number) {