diff --git a/src/SettingConfig.ts b/src/SettingConfig.ts index 944f911..30fff18 100644 --- a/src/SettingConfig.ts +++ b/src/SettingConfig.ts @@ -65,11 +65,11 @@ export const read_setting_from_file = ()=>{ export function get_setting():SettingConfig{ if(setting === null){ setting = read_setting_from_file(); - const env = process.env.NODE_ENV || 'development'; - if(env != "production" && env != "development"){ + const env = process.env.NODE_ENV; + if(env !== undefined && (env != "production" && env != "development")){ throw new Error("process unknown value in NODE_ENV: must be either \"development\" or \"production\""); } - setting.mode = env || setting.mode; + setting.mode = env ?? setting.mode; } return setting; } diff --git a/src/client/component/contentinfo.tsx b/src/client/component/contentinfo.tsx index 4c42665..d858a62 100644 --- a/src/client/component/contentinfo.tsx +++ b/src/client/component/contentinfo.tsx @@ -90,31 +90,31 @@ export const ContentInfo = (props: { const classes = useStyles(); const theme = useTheme(); const document = props.document; - const propclasses = props.classes || {}; + const propclasses = props.classes ?? {}; const rootName = props.short ? classes.short_root : classes.root; const thumbnail_anchor = props.short ? classes.short_thumbnail_anchor : ""; const thumbnail_content = props.short ? classes.short_thumbnail_content : classes.thumbnail_content; const subinfoContainer = props.short ? classes.short_subinfoContainer : classes.subinfoContainer; - return ( - + {document.deleted_at === null ? () - : (Deleted)} + className={propclasses.thumbnail_content ?? thumbnail_content}/>) + : (Deleted)} - + + className={propclasses.title ?? classes.title}> {document.title} - - {props.short ? ({document.tags.map(x => + + {props.short ? ({document.tags.map(x => () )}) : ( ) diff --git a/src/client/component/headline.tsx b/src/client/component/headline.tsx index f33c339..1d776b8 100644 --- a/src/client/component/headline.tsx +++ b/src/client/component/headline.tsx @@ -201,8 +201,8 @@ export const Headline = (prop: { -
-
+
+
{prop.children}
); diff --git a/src/client/component/navlist.tsx b/src/client/component/navlist.tsx index 8ca037a..efa8497 100644 --- a/src/client/component/navlist.tsx +++ b/src/client/component/navlist.tsx @@ -28,7 +28,7 @@ export const BackItem = (props:{to?:string})=>{ } export function CommonMenuList(props?:{url?:string}) { - let url = props?.url || ""; + let url = props?.url ?? ""; return ( {url !== "" && <> } } /> diff --git a/src/client/component/tagchip.tsx b/src/client/component/tagchip.tsx index f2cd2cf..1b47bbe 100644 --- a/src/client/component/tagchip.tsx +++ b/src/client/component/tagchip.tsx @@ -81,8 +81,8 @@ export const TagChip = (props:TagChipProp)=>{ } } const inner = clickable ? - (): - (); + (); return inner; } \ No newline at end of file diff --git a/src/client/page/gallery.tsx b/src/client/page/gallery.tsx index 7762d82..2f228f1 100644 --- a/src/client/page/gallery.tsx +++ b/src/client/page/gallery.tsx @@ -36,7 +36,7 @@ export const GalleryInfo = (props: GalleryProp)=>{ load(); },[props.diff]); const classes = useStyles(); - const queryString = toQueryString(props.option||{}); + const queryString = toQueryString(props.option??{}); if(state.documents === undefined){ return (); diff --git a/src/content/comic.ts b/src/content/comic.ts index e245954..74e3772 100644 --- a/src/content/comic.ts +++ b/src/content/comic.ts @@ -45,11 +45,11 @@ export class ComicReferrer extends createDefaultClass("comic"){ if(this.desc === undefined){ return basebody; } - let tags:string[] = this.desc.tags || []; - tags = tags.concat(this.desc.artist?.map(x=>`artist:${x}`) || []); - tags = tags.concat(this.desc.character?.map(x=>`character:${x}`) || []); - tags = tags.concat(this.desc.group?.map(x=>`group:${x}`) || []); - tags = tags.concat(this.desc.series?.map(x=>`series:${x}`) || []); + let tags:string[] = this.desc.tags ?? []; + tags = tags.concat(this.desc.artist?.map(x=>`artist:${x}`) ?? []); + tags = tags.concat(this.desc.character?.map(x=>`character:${x}`) ?? []); + tags = tags.concat(this.desc.group?.map(x=>`group:${x}`) ?? []); + tags = tags.concat(this.desc.series?.map(x=>`series:${x}`) ?? []); const type = this.desc.type instanceof Array ? this.desc.type[0]: this.desc.type; tags.push(`type:${type}`); return { diff --git a/src/content/file.ts b/src/content/file.ts index bad6edc..06a15a9 100644 --- a/src/content/file.ts +++ b/src/content/file.ts @@ -38,7 +38,7 @@ export const createDefaultClass = (type:string):ContentFileConstructor=>{ content_type: cons.content_type, filename: base, tags: [], - content_hash: this.hash || await this.getHash(), + content_hash: this.hash ?? await this.getHash(), } as DocumentBody; return ret; } diff --git a/src/db/doc.ts b/src/db/doc.ts index 4448352..2c0fc0f 100644 --- a/src/db/doc.ts +++ b/src/db/doc.ts @@ -69,12 +69,12 @@ class KnexDocumentAccessor implements DocumentAccessor{ })); } async findList(option?:QueryListOption){ - option = option || {}; - const allow_tag = option.allow_tag || []; - const eager_loading = typeof option.eager_loading === "undefined" || option.eager_loading; - const limit = option.limit || 20; - const use_offset = option.use_offset || false; - const offset = option.offset || 0; + option = option ?? {}; + const allow_tag = option.allow_tag ?? []; + const eager_loading = option.eager_loading ?? true; + const limit = option.limit ?? 20; + const use_offset = option.use_offset ?? false; + const offset = option.offset ?? 0; const word = option.word; const content_type = option.content_type; const cursor = option.cursor; @@ -134,6 +134,9 @@ class KnexDocumentAccessor implements DocumentAccessor{ idmap[id].tags.push(tag_name); } } + else{ + result.forEach(v=>{v.tags = [];}); + } return result; }; async findByPath(path:string,filename?:string):Promise{ diff --git a/src/db/tag.ts b/src/db/tag.ts index 8e24c70..4cf3d31 100644 --- a/src/db/tag.ts +++ b/src/db/tag.ts @@ -12,7 +12,7 @@ class KnexTagAccessor implements TagAccessor{ this.knex = knex; } async getTagAllList(onlyname?:boolean){ - onlyname = onlyname || false; + onlyname = onlyname ?? false; const t:DBTags[] = await this.knex.select(onlyname ? "*" : "name").from("tags") return t; } diff --git a/src/diff/watcher/recursive_watcher.ts b/src/diff/watcher/recursive_watcher.ts index d77e3cb..88ef23d 100644 --- a/src/diff/watcher/recursive_watcher.ts +++ b/src/diff/watcher/recursive_watcher.ts @@ -22,19 +22,19 @@ export class RecursiveWatcher extends EventEmitter implements IDiffWatcher { readonly path: string; private watcher: FSWatcher - constructor(path:string, option?:RecursiveWatcherOption){ + constructor(path:string, option:RecursiveWatcherOption = { + watchDir:false, + watchFile:true, + }){ super(); this.path = path; - option = option || { - watchDir:false, - watchFile:true, - } this.watcher = watch(path,{ persistent:true, ignoreInitial:true, depth:100, }); - if(option.watchFile === undefined || option.watchFile){ + option.watchFile ??= true; + if(option.watchFile){ this.watcher.on("add",path=>{ const cpath = join(this.path,path); this.emit("create",cpath); diff --git a/src/route/all.ts b/src/route/all.ts index d99c3f7..543e3ba 100644 --- a/src/route/all.ts +++ b/src/route/all.ts @@ -24,7 +24,7 @@ const all_middleware = (cont: string|undefined, restarg: string|undefined)=>asyn ctx.status = 404; return; } - const rest = "/"+(restarg || ""); + const rest = "/"+(restarg ?? ""); const result = router.match(rest,"GET"); if(!result.route){ return await next(); diff --git a/src/route/contents.ts b/src/route/contents.ts index 43a8bb7..c8c0b3b 100644 --- a/src/route/contents.ts +++ b/src/route/contents.ts @@ -25,7 +25,7 @@ const ContentTagIDHandler = (controller: DocumentAccessor) => async (ctx: Contex if (document == undefined){ return sendError(404,"document does not exist."); } - ctx.body = document.tags || []; + ctx.body = document.tags; ctx.type = 'json'; }; const ContentQueryHandler = (controller : DocumentAccessor) => async (ctx: Context,next: Next)=>{ diff --git a/src/route/error_handler.ts b/src/route/error_handler.ts index be43a02..3cc0a76 100644 --- a/src/route/error_handler.ts +++ b/src/route/error_handler.ts @@ -31,7 +31,7 @@ export const error_handler = async (ctx:Context,next: Next)=>{ if(err instanceof ClientRequestError){ const body : ErrorFormat= { code: err.code, - message: code_to_message_table[err.code] || "", + message: code_to_message_table[err.code] ?? "", detail: err.message } ctx.status = err.code; @@ -44,7 +44,7 @@ export const error_handler = async (ctx:Context,next: Next)=>{ } export const sendError = (code:number,message?:string) =>{ - throw new ClientRequestError(code,message || ""); + throw new ClientRequestError(code,message ?? ""); } export default error_handler; \ No newline at end of file diff --git a/src/route/util.ts b/src/route/util.ts index a7aa7e3..9eb12df 100644 --- a/src/route/util.ts +++ b/src/route/util.ts @@ -7,7 +7,7 @@ export function ParseQueryNumber(s: string|undefined): number| undefined{ else return Number.parseInt(s); } export function ParseQueryArray(s: string[]|string|undefined){ - s = s || []; + s = s ?? []; const r = s instanceof Array ? s : [s]; return r.map(x=>decodeURIComponent(x)); }