fix early logout bug

This commit is contained in:
monoid 2021-02-01 22:21:42 +09:00
parent 2b5839826b
commit 405cb0c22a
5 changed files with 43 additions and 15 deletions

View File

@ -10,7 +10,7 @@
"app:build:win64": "electron-builder --win --x64" "app:build:win64": "electron-builder --win --x64"
}, },
"build": { "build": {
"asar": false, "asar": true,
"files": [ "files": [
"build/**/*", "build/**/*",
"node_modules/**/*", "node_modules/**/*",

View File

@ -1,7 +1,7 @@
import React, { useContext, useEffect, useState } from 'react'; 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 {useTheme, makeStyles, Theme} from '@material-ui/core/styles';
import ContentAccessor,{QueryListOption, Document} from '../accessor/document'; import ContentAccessor,{QueryListOption, Document} from '../accessor/document';
import {Link as RouterLink} from 'react-router-dom'; import {Link as RouterLink} from 'react-router-dom';
@ -42,7 +42,15 @@ export const GalleryInfo = (props: GalleryProp)=>{
return (<LoadingCircle/>); return (<LoadingCircle/>);
} }
else{ else{
return (<Box className={classes.root}>{ return (<Box className={classes.root}>
{props.option !== undefined && props.diff !== "" && <Box>
<Typography variant="h6">search for</Typography>
{props.option.word !== undefined && <Chip label={"search : "+props.option.word}></Chip>}
{props.option.content_type !== undefined && <Chip label={"type : "+props.option.content_type}></Chip>}
{props.option.allow_tag !== undefined && props.option.allow_tag.map(x=>(
<TagChip key={x} tagname={decodeURI(x)} label={decodeURI(x)}></TagChip>))}
</Box>}
{
state.documents.map(x=>{ state.documents.map(x=>{
return (<ContentInfo document={x} key={x.id} return (<ContentInfo document={x} key={x.id}
gallery={`/search?${queryString}`} short/>); gallery={`/search?${queryString}`} short/>);
@ -56,7 +64,9 @@ export const Gallery = ()=>{
const location = useLocation(); const location = useLocation();
const query = QueryStringToMap(location.search); const query = QueryStringToMap(location.search);
const menu_list = CommonMenuList({url: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 (<Headline menu={menu_list}> return (<Headline menu={menu_list}>
<GalleryInfo diff={location.search} option={query}></GalleryInfo> <GalleryInfo diff={location.search} option={query}></GalleryInfo>
</Headline>) </Headline>)

View File

@ -1,5 +1,5 @@
import React, { createContext, useRef, useState } from 'react'; import React, { createContext, useRef, useState } from 'react';
export const BackLinkContext = createContext({backLink:"",setBackLink:(s:string)=>{} });
export const UserContext = createContext({ export const UserContext = createContext({
username: "", username: "",
permission: [] as string[], permission: [] as string[],
@ -10,7 +10,7 @@ export const UserContext = createContext({
type LoginLocalStorage = { type LoginLocalStorage = {
username: string, username: string,
permission: string[], permission: string[],
refreshExpired: number accessExpired: number
}; };
let localObj: LoginLocalStorage | null = null; let localObj: LoginLocalStorage | null = null;
@ -21,7 +21,7 @@ export const getInitialValue = async () => {
const storage = storagestr !== null ? JSON.parse(storagestr) as LoginLocalStorage | null : null; const storage = storagestr !== null ? JSON.parse(storagestr) as LoginLocalStorage | null : null;
localObj = storage; localObj = storage;
} }
if (localObj !== null && localObj.refreshExpired > Math.floor(Date.now() / 1000)) { if (localObj !== null && localObj.accessExpired > Math.floor(Date.now() / 1000)) {
return { return {
username: localObj.username, username: localObj.username,
permission: localObj.permission, permission: localObj.permission,
@ -36,12 +36,12 @@ export const getInitialValue = async () => {
localObj = { localObj = {
username: r.username, username: r.username,
permission: r.permission, permission: r.permission,
refreshExpired: r.refreshExpired accessExpired: r.accessExpired
} }
} }
else { else {
localObj = { localObj = {
refreshExpired: 0, accessExpired: 0,
username: "", username: "",
permission: r.permission permission: r.permission
} }
@ -59,7 +59,7 @@ export const doLogout = async () => {
try { try {
const res = await req.json(); const res = await req.json();
localObj = { localObj = {
refreshExpired: 0, accessExpired: 0,
username: "", username: "",
permission: res["permission"] permission: res["permission"]
} }

View File

@ -137,7 +137,7 @@ export const createLoginMiddleware = (userController: UserAccessor) =>
ctx.body = { ctx.body = {
username: user.username, username: user.username,
permission: userPermission, permission: userPermission,
refreshExpired: (Math.floor(Date.now() / 1000) + refreshExpiredTime), accessExpired : (Math.floor(Date.now() / 1000) + accessExpiredTime),
}; };
console.log(`${username} logined`); console.log(`${username} logined`);
return; return;

View File

@ -81,7 +81,17 @@ class ServerApplication{
} }
private serve_index(router:Router){ private serve_index(router:Router){
const serveindex = (url:string)=>{ 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('/');
serveindex('/doc/:rest(.*)'); serveindex('/doc/:rest(.*)');
@ -92,11 +102,19 @@ class ServerApplication{
serveindex('/setting'); serveindex('/setting');
} }
private serve_static_file(router: Router){ private serve_static_file(router: Router){
const setting = get_setting();
const static_file_server = (path:string,type:string) => { const static_file_server = (path:string,type:string) => {
router.get('/'+path,async (ctx,next)=>{ router.get('/'+path,async (ctx,next)=>{
const setting = get_setting();
ctx.type = type; ctx.body = createReadStream(path); 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/css/style.css','css');
static_file_server('dist/js/bundle.js','js'); static_file_server('dist/js/bundle.js','js');
if(setting.mode === "development") if(setting.mode === "development")