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{
|
||||
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;
|
||||
}
|
||||
|
@ -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 (<Paper className={propclasses.root || rootName} elevation={4}>
|
||||
<Link className={propclasses.thumbnail_anchor || thumbnail_anchor} component={RouterLink} to={{
|
||||
return (<Paper className={propclasses.root ?? rootName} elevation={4}>
|
||||
<Link className={propclasses.thumbnail_anchor ?? thumbnail_anchor} component={RouterLink} to={{
|
||||
pathname:makeContentReaderUrl(document.id)
|
||||
}}>
|
||||
{document.deleted_at === null ?
|
||||
(<ThumbnailContainer content={document}
|
||||
className={propclasses.thumbnail_content || thumbnail_content}/>)
|
||||
: (<Typography className={propclasses.thumbnail_content || thumbnail_content} variant='h4'>Deleted</Typography>)}
|
||||
className={propclasses.thumbnail_content ?? thumbnail_content}/>)
|
||||
: (<Typography className={propclasses.thumbnail_content ?? thumbnail_content} variant='h4'>Deleted</Typography>)}
|
||||
</Link>
|
||||
<Box className={propclasses.infoContainer || classes.infoContainer}>
|
||||
<Box className={propclasses.infoContainer ?? classes.infoContainer}>
|
||||
<Link variant='h5' color='inherit' component={RouterLink} to={{
|
||||
pathname: props.gallery === undefined ? makeContentReaderUrl(document.id) : makeContentInfoUrl(document.id),
|
||||
}}
|
||||
className={propclasses.title || classes.title}>
|
||||
className={propclasses.title ?? classes.title}>
|
||||
{document.title}
|
||||
</Link>
|
||||
<Box className={propclasses.subinfoContainer || subinfoContainer}>
|
||||
{props.short ? (<Box className={propclasses.tag_list || classes.tag_list}>{document.tags.map(x =>
|
||||
<Box className={propclasses.subinfoContainer ?? subinfoContainer}>
|
||||
{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>)
|
||||
)}</Box>) : (
|
||||
<ComicDetailTag tags={document.tags} classes={({tag_list:classes.tag_list})}></ComicDetailTag>)
|
||||
|
@ -201,8 +201,8 @@ export const Headline = (prop: {
|
||||
</Drawer>
|
||||
</Hidden>
|
||||
</nav>
|
||||
<main className={prop.classes?.content || classes.content}>
|
||||
<div className={prop.classes?.toolbar || classes.toolbar}></div>
|
||||
<main className={prop.classes?.content ?? classes.content}>
|
||||
<div className={prop.classes?.toolbar ?? classes.toolbar}></div>
|
||||
{prop.children}
|
||||
</main>
|
||||
</div>);
|
||||
|
@ -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 (<NavList>
|
||||
{url !== "" && <><BackItem /> <Divider /></>}
|
||||
<NavItem name="All" to="/" icon={<HomeIcon />} />
|
||||
|
@ -81,8 +81,8 @@ export const TagChip = (props:TagChipProp)=>{
|
||||
}
|
||||
}
|
||||
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>):
|
||||
(<ColorChip color={getTagColorName(tagname)} clickable={clickable} label={newlabel||label} {...rest}></ColorChip>);
|
||||
(<ColorChip color={getTagColorName(tagname)} clickable={clickable} label={newlabel??label} {...rest}></ColorChip>);
|
||||
return inner;
|
||||
}
|
@ -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 (<LoadingCircle/>);
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<Document[]>{
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -22,19 +22,19 @@ export class RecursiveWatcher extends EventEmitter implements IDiffWatcher {
|
||||
readonly path: string;
|
||||
private watcher: FSWatcher
|
||||
|
||||
constructor(path:string, option?:RecursiveWatcherOption){
|
||||
super();
|
||||
this.path = path;
|
||||
option = option || {
|
||||
constructor(path:string, option:RecursiveWatcherOption = {
|
||||
watchDir:false,
|
||||
watchFile:true,
|
||||
}
|
||||
}){
|
||||
super();
|
||||
this.path = path;
|
||||
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);
|
||||
|
@ -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();
|
||||
|
@ -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)=>{
|
||||
|
@ -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;
|
@ -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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user