From 405cb0c22a963efd90955a3cab8477f3da80e38e Mon Sep 17 00:00:00 2001 From: monoid Date: Mon, 1 Feb 2021 22:21:42 +0900 Subject: [PATCH] fix early logout bug --- package.json | 2 +- src/client/page/gallery.tsx | 18 ++++++++++++++---- src/client/state.tsx | 12 ++++++------ src/login.ts | 2 +- src/server.ts | 24 +++++++++++++++++++++--- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index a0d55e4..68dfd37 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "app:build:win64": "electron-builder --win --x64" }, "build": { - "asar": false, + "asar": true, "files": [ "build/**/*", "node_modules/**/*", diff --git a/src/client/page/gallery.tsx b/src/client/page/gallery.tsx index a531a4b..7762d82 100644 --- a/src/client/page/gallery.tsx +++ b/src/client/page/gallery.tsx @@ -1,7 +1,7 @@ import React, { useContext, useEffect, useState } from 'react'; -import { Headline, CommonMenuList,LoadingCircle, ContentInfo, NavList, NavItem } from '../component/mod'; +import { Headline, CommonMenuList,LoadingCircle, ContentInfo, NavList, NavItem, TagChip } from '../component/mod'; -import { Box, Paper, Link, useMediaQuery, Portal, List, ListItem, ListItemIcon, Tooltip, ListItemText } from '@material-ui/core'; +import { Box, Paper, Link, useMediaQuery, Portal, List, ListItem, ListItemIcon, Tooltip, ListItemText, Typography, Chip } from '@material-ui/core'; import {useTheme, makeStyles, Theme} from '@material-ui/core/styles'; import ContentAccessor,{QueryListOption, Document} from '../accessor/document'; import {Link as RouterLink} from 'react-router-dom'; @@ -42,7 +42,15 @@ export const GalleryInfo = (props: GalleryProp)=>{ return (); } else{ - return ({ + return ( + {props.option !== undefined && props.diff !== "" && + search for + {props.option.word !== undefined && } + {props.option.content_type !== undefined && } + {props.option.allow_tag !== undefined && props.option.allow_tag.map(x=>( + ))} + } + { state.documents.map(x=>{ return (); @@ -56,7 +64,9 @@ export const Gallery = ()=>{ const location = useLocation(); const query = QueryStringToMap(location.search); const menu_list = CommonMenuList({url:location.search}); - + let option: QueryListOption = query; + option.allow_tag = typeof option.allow_tag === "string" ? [option.allow_tag] : option.allow_tag; + option.limit = typeof query['limit'] === "string" ? parseInt(query['limit']) : undefined; return ( ) diff --git a/src/client/state.tsx b/src/client/state.tsx index b16d4e8..e03c1a8 100644 --- a/src/client/state.tsx +++ b/src/client/state.tsx @@ -1,5 +1,5 @@ import React, { createContext, useRef, useState } from 'react'; - +export const BackLinkContext = createContext({backLink:"",setBackLink:(s:string)=>{} }); export const UserContext = createContext({ username: "", permission: [] as string[], @@ -10,7 +10,7 @@ export const UserContext = createContext({ type LoginLocalStorage = { username: string, permission: string[], - refreshExpired: number + accessExpired: number }; let localObj: LoginLocalStorage | null = null; @@ -21,7 +21,7 @@ export const getInitialValue = async () => { const storage = storagestr !== null ? JSON.parse(storagestr) as LoginLocalStorage | null : null; localObj = storage; } - if (localObj !== null && localObj.refreshExpired > Math.floor(Date.now() / 1000)) { + if (localObj !== null && localObj.accessExpired > Math.floor(Date.now() / 1000)) { return { username: localObj.username, permission: localObj.permission, @@ -36,12 +36,12 @@ export const getInitialValue = async () => { localObj = { username: r.username, permission: r.permission, - refreshExpired: r.refreshExpired + accessExpired: r.accessExpired } } else { localObj = { - refreshExpired: 0, + accessExpired: 0, username: "", permission: r.permission } @@ -59,7 +59,7 @@ export const doLogout = async () => { try { const res = await req.json(); localObj = { - refreshExpired: 0, + accessExpired: 0, username: "", permission: res["permission"] } diff --git a/src/login.ts b/src/login.ts index cebdd65..2f3dce6 100644 --- a/src/login.ts +++ b/src/login.ts @@ -137,7 +137,7 @@ export const createLoginMiddleware = (userController: UserAccessor) => ctx.body = { username: user.username, permission: userPermission, - refreshExpired: (Math.floor(Date.now() / 1000) + refreshExpiredTime), + accessExpired : (Math.floor(Date.now() / 1000) + accessExpiredTime), }; console.log(`${username} logined`); return; diff --git a/src/server.ts b/src/server.ts index 86fb577..4bc12f3 100644 --- a/src/server.ts +++ b/src/server.ts @@ -81,7 +81,17 @@ class ServerApplication{ } private serve_index(router:Router){ const serveindex = (url:string)=>{ - router.get(url, (ctx)=>{ctx.type = 'html'; ctx.body = this.index_html;}) + router.get(url, (ctx)=>{ + ctx.type = 'html'; ctx.body = this.index_html; + const setting = get_setting(); + ctx.set('x-content-type-options','no-sniff'); + if(setting.mode === "development"){ + ctx.set('cache-control','no-cache'); + } + else{ + ctx.set('cache-control','public, max-age=3600'); + } + }) } serveindex('/'); serveindex('/doc/:rest(.*)'); @@ -92,11 +102,19 @@ class ServerApplication{ serveindex('/setting'); } private serve_static_file(router: Router){ - const setting = get_setting(); const static_file_server = (path:string,type:string) => { router.get('/'+path,async (ctx,next)=>{ + const setting = get_setting(); ctx.type = type; ctx.body = createReadStream(path); - })} + ctx.set('x-content-type-options','no-sniff'); + if(setting.mode === "development"){ + ctx.set('cache-control','no-cache'); + } + else{ + ctx.set('cache-control','public, max-age=3600'); + } + })}; + const setting = get_setting(); static_file_server('dist/css/style.css','css'); static_file_server('dist/js/bundle.js','js'); if(setting.mode === "development")