chg operator || to ??
This commit is contained in:
parent
dafce3ebf6
commit
c81f4651ab
@ -65,11 +65,11 @@ export const read_setting_from_file = ()=>{
|
|||||||
export function get_setting():SettingConfig{
|
export function get_setting():SettingConfig{
|
||||||
if(setting === null){
|
if(setting === null){
|
||||||
setting = read_setting_from_file();
|
setting = read_setting_from_file();
|
||||||
const env = process.env.NODE_ENV || 'development';
|
const env = process.env.NODE_ENV;
|
||||||
if(env != "production" && env != "development"){
|
if(env !== undefined && (env != "production" && env != "development")){
|
||||||
throw new Error("process unknown value in NODE_ENV: must be either \"development\" or \"production\"");
|
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;
|
return setting;
|
||||||
}
|
}
|
||||||
|
@ -90,31 +90,31 @@ export const ContentInfo = (props: {
|
|||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const document = props.document;
|
const document = props.document;
|
||||||
const propclasses = props.classes || {};
|
const propclasses = props.classes ?? {};
|
||||||
const rootName = props.short ? classes.short_root : classes.root;
|
const rootName = props.short ? classes.short_root : classes.root;
|
||||||
const thumbnail_anchor = props.short ? classes.short_thumbnail_anchor : "";
|
const thumbnail_anchor = props.short ? classes.short_thumbnail_anchor : "";
|
||||||
const thumbnail_content = props.short ? classes.short_thumbnail_content :
|
const thumbnail_content = props.short ? classes.short_thumbnail_content :
|
||||||
classes.thumbnail_content;
|
classes.thumbnail_content;
|
||||||
const subinfoContainer = props.short ? classes.short_subinfoContainer :
|
const subinfoContainer = props.short ? classes.short_subinfoContainer :
|
||||||
classes.subinfoContainer;
|
classes.subinfoContainer;
|
||||||
return (<Paper className={propclasses.root || rootName} elevation={4}>
|
return (<Paper className={propclasses.root ?? rootName} elevation={4}>
|
||||||
<Link className={propclasses.thumbnail_anchor || thumbnail_anchor} component={RouterLink} to={{
|
<Link className={propclasses.thumbnail_anchor ?? thumbnail_anchor} component={RouterLink} to={{
|
||||||
pathname:makeContentReaderUrl(document.id)
|
pathname:makeContentReaderUrl(document.id)
|
||||||
}}>
|
}}>
|
||||||
{document.deleted_at === null ?
|
{document.deleted_at === null ?
|
||||||
(<ThumbnailContainer content={document}
|
(<ThumbnailContainer content={document}
|
||||||
className={propclasses.thumbnail_content || thumbnail_content}/>)
|
className={propclasses.thumbnail_content ?? thumbnail_content}/>)
|
||||||
: (<Typography className={propclasses.thumbnail_content || thumbnail_content} variant='h4'>Deleted</Typography>)}
|
: (<Typography className={propclasses.thumbnail_content ?? thumbnail_content} variant='h4'>Deleted</Typography>)}
|
||||||
</Link>
|
</Link>
|
||||||
<Box className={propclasses.infoContainer || classes.infoContainer}>
|
<Box className={propclasses.infoContainer ?? classes.infoContainer}>
|
||||||
<Link variant='h5' color='inherit' component={RouterLink} to={{
|
<Link variant='h5' color='inherit' component={RouterLink} to={{
|
||||||
pathname: props.gallery === undefined ? makeContentReaderUrl(document.id) : makeContentInfoUrl(document.id),
|
pathname: props.gallery === undefined ? makeContentReaderUrl(document.id) : makeContentInfoUrl(document.id),
|
||||||
}}
|
}}
|
||||||
className={propclasses.title || classes.title}>
|
className={propclasses.title ?? classes.title}>
|
||||||
{document.title}
|
{document.title}
|
||||||
</Link>
|
</Link>
|
||||||
<Box className={propclasses.subinfoContainer || subinfoContainer}>
|
<Box className={propclasses.subinfoContainer ?? subinfoContainer}>
|
||||||
{props.short ? (<Box className={propclasses.tag_list || classes.tag_list}>{document.tags.map(x =>
|
{props.short ? (<Box className={propclasses.tag_list ?? classes.tag_list}>{document.tags.map(x =>
|
||||||
(<TagChip key={x} label={x} clickable tagname={x} size="small"></TagChip>)
|
(<TagChip key={x} label={x} clickable tagname={x} size="small"></TagChip>)
|
||||||
)}</Box>) : (
|
)}</Box>) : (
|
||||||
<ComicDetailTag tags={document.tags} classes={({tag_list:classes.tag_list})}></ComicDetailTag>)
|
<ComicDetailTag tags={document.tags} classes={({tag_list:classes.tag_list})}></ComicDetailTag>)
|
||||||
|
@ -201,8 +201,8 @@ export const Headline = (prop: {
|
|||||||
</Drawer>
|
</Drawer>
|
||||||
</Hidden>
|
</Hidden>
|
||||||
</nav>
|
</nav>
|
||||||
<main className={prop.classes?.content || classes.content}>
|
<main className={prop.classes?.content ?? classes.content}>
|
||||||
<div className={prop.classes?.toolbar || classes.toolbar}></div>
|
<div className={prop.classes?.toolbar ?? classes.toolbar}></div>
|
||||||
{prop.children}
|
{prop.children}
|
||||||
</main>
|
</main>
|
||||||
</div>);
|
</div>);
|
||||||
|
@ -28,7 +28,7 @@ export const BackItem = (props:{to?:string})=>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function CommonMenuList(props?:{url?:string}) {
|
export function CommonMenuList(props?:{url?:string}) {
|
||||||
let url = props?.url || "";
|
let url = props?.url ?? "";
|
||||||
return (<NavList>
|
return (<NavList>
|
||||||
{url !== "" && <><BackItem /> <Divider /></>}
|
{url !== "" && <><BackItem /> <Divider /></>}
|
||||||
<NavItem name="All" to="/" icon={<HomeIcon />} />
|
<NavItem name="All" to="/" icon={<HomeIcon />} />
|
||||||
|
@ -81,8 +81,8 @@ export const TagChip = (props:TagChipProp)=>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const inner = clickable ?
|
const inner = clickable ?
|
||||||
(<ColorChip color={getTagColorName(tagname)} clickable={clickable} label={newlabel||label} {...rest}
|
(<ColorChip color={getTagColorName(tagname)} clickable={clickable} label={newlabel??label} {...rest}
|
||||||
component={RouterLink} to={`/search?allow_tag=${tagname}`}></ColorChip>):
|
component={RouterLink} to={`/search?allow_tag=${tagname}`}></ColorChip>):
|
||||||
(<ColorChip color={getTagColorName(tagname)} clickable={clickable} label={newlabel||label} {...rest}></ColorChip>);
|
(<ColorChip color={getTagColorName(tagname)} clickable={clickable} label={newlabel??label} {...rest}></ColorChip>);
|
||||||
return inner;
|
return inner;
|
||||||
}
|
}
|
@ -36,7 +36,7 @@ export const GalleryInfo = (props: GalleryProp)=>{
|
|||||||
load();
|
load();
|
||||||
},[props.diff]);
|
},[props.diff]);
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const queryString = toQueryString(props.option||{});
|
const queryString = toQueryString(props.option??{});
|
||||||
|
|
||||||
if(state.documents === undefined){
|
if(state.documents === undefined){
|
||||||
return (<LoadingCircle/>);
|
return (<LoadingCircle/>);
|
||||||
|
@ -45,11 +45,11 @@ export class ComicReferrer extends createDefaultClass("comic"){
|
|||||||
if(this.desc === undefined){
|
if(this.desc === undefined){
|
||||||
return basebody;
|
return basebody;
|
||||||
}
|
}
|
||||||
let tags:string[] = this.desc.tags || [];
|
let tags:string[] = this.desc.tags ?? [];
|
||||||
tags = tags.concat(this.desc.artist?.map(x=>`artist:${x}`) || []);
|
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.character?.map(x=>`character:${x}`) ?? []);
|
||||||
tags = tags.concat(this.desc.group?.map(x=>`group:${x}`) || []);
|
tags = tags.concat(this.desc.group?.map(x=>`group:${x}`) ?? []);
|
||||||
tags = tags.concat(this.desc.series?.map(x=>`series:${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;
|
const type = this.desc.type instanceof Array ? this.desc.type[0]: this.desc.type;
|
||||||
tags.push(`type:${type}`);
|
tags.push(`type:${type}`);
|
||||||
return {
|
return {
|
||||||
|
@ -38,7 +38,7 @@ export const createDefaultClass = (type:string):ContentFileConstructor=>{
|
|||||||
content_type: cons.content_type,
|
content_type: cons.content_type,
|
||||||
filename: base,
|
filename: base,
|
||||||
tags: [],
|
tags: [],
|
||||||
content_hash: this.hash || await this.getHash(),
|
content_hash: this.hash ?? await this.getHash(),
|
||||||
} as DocumentBody;
|
} as DocumentBody;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -69,12 +69,12 @@ class KnexDocumentAccessor implements DocumentAccessor{
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
async findList(option?:QueryListOption){
|
async findList(option?:QueryListOption){
|
||||||
option = option || {};
|
option = option ?? {};
|
||||||
const allow_tag = option.allow_tag || [];
|
const allow_tag = option.allow_tag ?? [];
|
||||||
const eager_loading = typeof option.eager_loading === "undefined" || option.eager_loading;
|
const eager_loading = option.eager_loading ?? true;
|
||||||
const limit = option.limit || 20;
|
const limit = option.limit ?? 20;
|
||||||
const use_offset = option.use_offset || false;
|
const use_offset = option.use_offset ?? false;
|
||||||
const offset = option.offset || 0;
|
const offset = option.offset ?? 0;
|
||||||
const word = option.word;
|
const word = option.word;
|
||||||
const content_type = option.content_type;
|
const content_type = option.content_type;
|
||||||
const cursor = option.cursor;
|
const cursor = option.cursor;
|
||||||
@ -134,6 +134,9 @@ class KnexDocumentAccessor implements DocumentAccessor{
|
|||||||
idmap[id].tags.push(tag_name);
|
idmap[id].tags.push(tag_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
result.forEach(v=>{v.tags = [];});
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
async findByPath(path:string,filename?:string):Promise<Document[]>{
|
async findByPath(path:string,filename?:string):Promise<Document[]>{
|
||||||
|
@ -12,7 +12,7 @@ class KnexTagAccessor implements TagAccessor{
|
|||||||
this.knex = knex;
|
this.knex = knex;
|
||||||
}
|
}
|
||||||
async getTagAllList(onlyname?:boolean){
|
async getTagAllList(onlyname?:boolean){
|
||||||
onlyname = onlyname || false;
|
onlyname = onlyname ?? false;
|
||||||
const t:DBTags[] = await this.knex.select(onlyname ? "*" : "name").from("tags")
|
const t:DBTags[] = await this.knex.select(onlyname ? "*" : "name").from("tags")
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -22,19 +22,19 @@ export class RecursiveWatcher extends EventEmitter implements IDiffWatcher {
|
|||||||
readonly path: string;
|
readonly path: string;
|
||||||
private watcher: FSWatcher
|
private watcher: FSWatcher
|
||||||
|
|
||||||
constructor(path:string, option?:RecursiveWatcherOption){
|
constructor(path:string, option:RecursiveWatcherOption = {
|
||||||
super();
|
|
||||||
this.path = path;
|
|
||||||
option = option || {
|
|
||||||
watchDir:false,
|
watchDir:false,
|
||||||
watchFile:true,
|
watchFile:true,
|
||||||
}
|
}){
|
||||||
|
super();
|
||||||
|
this.path = path;
|
||||||
this.watcher = watch(path,{
|
this.watcher = watch(path,{
|
||||||
persistent:true,
|
persistent:true,
|
||||||
ignoreInitial:true,
|
ignoreInitial:true,
|
||||||
depth:100,
|
depth:100,
|
||||||
});
|
});
|
||||||
if(option.watchFile === undefined || option.watchFile){
|
option.watchFile ??= true;
|
||||||
|
if(option.watchFile){
|
||||||
this.watcher.on("add",path=>{
|
this.watcher.on("add",path=>{
|
||||||
const cpath = join(this.path,path);
|
const cpath = join(this.path,path);
|
||||||
this.emit("create",cpath);
|
this.emit("create",cpath);
|
||||||
|
@ -24,7 +24,7 @@ const all_middleware = (cont: string|undefined, restarg: string|undefined)=>asyn
|
|||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const rest = "/"+(restarg || "");
|
const rest = "/"+(restarg ?? "");
|
||||||
const result = router.match(rest,"GET");
|
const result = router.match(rest,"GET");
|
||||||
if(!result.route){
|
if(!result.route){
|
||||||
return await next();
|
return await next();
|
||||||
|
@ -25,7 +25,7 @@ const ContentTagIDHandler = (controller: DocumentAccessor) => async (ctx: Contex
|
|||||||
if (document == undefined){
|
if (document == undefined){
|
||||||
return sendError(404,"document does not exist.");
|
return sendError(404,"document does not exist.");
|
||||||
}
|
}
|
||||||
ctx.body = document.tags || [];
|
ctx.body = document.tags;
|
||||||
ctx.type = 'json';
|
ctx.type = 'json';
|
||||||
};
|
};
|
||||||
const ContentQueryHandler = (controller : DocumentAccessor) => async (ctx: Context,next: Next)=>{
|
const ContentQueryHandler = (controller : DocumentAccessor) => async (ctx: Context,next: Next)=>{
|
||||||
|
@ -31,7 +31,7 @@ export const error_handler = async (ctx:Context,next: Next)=>{
|
|||||||
if(err instanceof ClientRequestError){
|
if(err instanceof ClientRequestError){
|
||||||
const body : ErrorFormat= {
|
const body : ErrorFormat= {
|
||||||
code: err.code,
|
code: err.code,
|
||||||
message: code_to_message_table[err.code] || "",
|
message: code_to_message_table[err.code] ?? "",
|
||||||
detail: err.message
|
detail: err.message
|
||||||
}
|
}
|
||||||
ctx.status = err.code;
|
ctx.status = err.code;
|
||||||
@ -44,7 +44,7 @@ export const error_handler = async (ctx:Context,next: Next)=>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const sendError = (code:number,message?:string) =>{
|
export const sendError = (code:number,message?:string) =>{
|
||||||
throw new ClientRequestError(code,message || "");
|
throw new ClientRequestError(code,message ?? "");
|
||||||
}
|
}
|
||||||
|
|
||||||
export default error_handler;
|
export default error_handler;
|
@ -7,7 +7,7 @@ export function ParseQueryNumber(s: string|undefined): number| undefined{
|
|||||||
else return Number.parseInt(s);
|
else return Number.parseInt(s);
|
||||||
}
|
}
|
||||||
export function ParseQueryArray(s: string[]|string|undefined){
|
export function ParseQueryArray(s: string[]|string|undefined){
|
||||||
s = s || [];
|
s = s ?? [];
|
||||||
const r = s instanceof Array ? s : [s];
|
const r = s instanceof Array ? s : [s];
|
||||||
return r.map(x=>decodeURIComponent(x));
|
return r.map(x=>decodeURIComponent(x));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user