diff --git a/src/client/web/src/common/localstorage.ts b/src/client/web/src/common/localstorage.ts index 8701037..6f38d4f 100644 --- a/src/client/web/src/common/localstorage.ts +++ b/src/client/web/src/common/localstorage.ts @@ -1,10 +1,35 @@ -export class LocalStorage { - static get(key: string): string { - const val = window.localStorage.getItem(key); - return val && val != "undefined" && val != "null" ? val : ""; +export interface ILocalStorage { + get: (key: string) => string; + set: (key: string, val: string) => void; +} + +export const errNoLocalStorage = "local storage is not supported"; + +class LocalStorage { + constructor() {} + + get(key: string): string { + if (window != null && window.localStorage != null) { + const val = window.localStorage.getItem(key); + return val && val != "undefined" && val != "null" ? val : ""; + } + + return ""; } - static set(key: string, val: string): boolean { - window.localStorage.setItem(key, val); - return true; + + set(key: string, val: string) { + if (window != null && window.localStorage != null) { + window.localStorage.setItem(key, val); + } else { + console.error(errNoLocalStorage); + } } } + +var localStorage: LocalStorage; +export const Storage = () => { + if (localStorage == null) { + localStorage = new LocalStorage(); + } + return localStorage; +}; diff --git a/src/client/web/src/components/state_mgr.tsx b/src/client/web/src/components/state_mgr.tsx index a1ef1af..736455e 100644 --- a/src/client/web/src/components/state_mgr.tsx +++ b/src/client/web/src/components/state_mgr.tsx @@ -67,7 +67,7 @@ export class StateMgr extends React.Component { .initAll(query) .then((status: string) => { if (status !== "") { - alertMsg(getErrMsg(state.msg.pkg, "op.fail", status.toString())); + alertMsg(getErrMsg(state.msg.pkg, "op.fail", status)); } this.update(updater().updateAll); }); diff --git a/src/client/web/src/components/state_updater.ts b/src/client/web/src/components/state_updater.ts index a925525..c62b851 100644 --- a/src/client/web/src/components/state_updater.ts +++ b/src/client/web/src/components/state_updater.ts @@ -31,7 +31,6 @@ import { SettingsClient } from "../client/settings"; import { UploadEntry, UploadState } from "../worker/interface"; import { Up } from "../worker/upload_mgr"; import { alertMsg } from "../common/env"; -import { LocalStorage } from "../common/localstorage"; import { controlName as panelTabs } from "./root_frame"; import { settingsTabsCtrl } from "./dialog_settings"; import { settingsDialogCtrl } from "./layers"; @@ -371,10 +370,7 @@ export class Updater { }; initStateForVisitor = async (): Promise => { - const statuses = await Promise.all([ - this.getClientCfg(), - this.syncIsSharing(this.props.filesInfo.dirPath.join("/")), - ]); + const statuses = await Promise.all([this.getClientCfg()]); if (statuses.join("") !== "") { return statuses.join(";"); } @@ -449,22 +445,30 @@ export class Updater { return isAuthedStatus; } - const statuses = await Promise.all([this.self(), this.initCwd(params)]); - if (statuses.join("") !== "") { - return statuses.join(";"); - } - - this.initUITree(); - const syncCwdStatus = await this.syncCwd(); - if (syncCwdStatus !== "") { - return syncCwdStatus; - } - const getCapStatus = await this.getCaptchaID(); if (getCapStatus !== "") { return getCapStatus; } + const selfStatuses = await Promise.all([this.self(), this.initCwd(params)]); + if (selfStatuses.join("") !== "") { + return selfStatuses.join(";"); + } + + this.initUITree(); + + const cwdStatus = await this.syncCwd(); + if (cwdStatus !== "") { + return cwdStatus; + } + + const isSharingStatus = await this.syncIsSharing( + this.props.filesInfo.dirPath.join("/") + ); + if (isSharingStatus !== "") { + return isSharingStatus; + } + if (this.props.login.userRole === roleAdmin) { return this.initStateForAdmin(); } else if (this.props.login.userRole === roleVisitor) { @@ -500,6 +504,7 @@ export class Updater { self = async (): Promise => { const resp = await this.usersClient.self(); + if (resp.status === 200) { this.props.login.userID = resp.data.id; this.props.login.userName = resp.data.name; @@ -508,7 +513,10 @@ export class Updater { this.props.login.quota = resp.data.quota; this.props.login.preferences = resp.data.preferences; return ""; + } else if (resp.status === 401) { + return ""; } + this.resetUser(); return errServer; }; diff --git a/src/client/web/src/i18n/en_US.ts b/src/client/web/src/i18n/en_US.ts index d63b4e6..22e71a6 100644 --- a/src/client/web/src/i18n/en_US.ts +++ b/src/client/web/src/i18n/en_US.ts @@ -113,4 +113,9 @@ export const msgs: Map = Map({ "control.settingsTabs.preferencePane": "Preference", "upload.add.fail": "Some files conflict with uploading files, please check.", "server.fail": "The operation failed in the server", + "err.updater": "updater error", + "err.uploadMgr": "upload Manager error", + "err.server": "The operation failed in the server", + "err.script.cors": "script error with CORS", + "err.unknown": "unknown error", }); diff --git a/src/client/web/src/i18n/zh_CN.ts b/src/client/web/src/i18n/zh_CN.ts index eb392eb..0bd9713 100644 --- a/src/client/web/src/i18n/zh_CN.ts +++ b/src/client/web/src/i18n/zh_CN.ts @@ -110,5 +110,9 @@ export const msgs: Map = Map({ "control.settingsTabs.managementPane": "管理", "control.settingsTabs.preferencePane": "设置", "upload.add.fail": "有些文件与上传任务冲突,请检查", - "server.fail": "操作在服务器端失败", + "err.updater": "updater错误", + "err.uploadMgr": "upload Manager错误", + "err.server": "服务器端操作失败", + "err.script.cors": "跨域脚本错误", + "err.unknown": "未知错误", });