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"
},
"build": {
"asar": false,
"asar": true,
"files": [
"build/**/*",
"node_modules/**/*",

View File

@ -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 (<LoadingCircle/>);
}
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=>{
return (<ContentInfo document={x} key={x.id}
gallery={`/search?${queryString}`} short/>);
@ -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 (<Headline menu={menu_list}>
<GalleryInfo diff={location.search} option={query}></GalleryInfo>
</Headline>)

View File

@ -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"]
}

View File

@ -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;

View File

@ -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")