fix(fe/state_updater): re-order the steps in the initAll

This commit is contained in:
hexxa 2021-12-20 16:54:04 +08:00 committed by Hexxa
parent 4fb6dd79a3
commit ba17416755
5 changed files with 67 additions and 25 deletions

View file

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

View file

@ -67,7 +67,7 @@ export class StateMgr extends React.Component<Props, State, {}> {
.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);
});

View file

@ -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<any> => {
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<string> => {
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;
};

View file

@ -113,4 +113,9 @@ export const msgs: Map<string, string> = 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",
});

View file

@ -110,5 +110,9 @@ export const msgs: Map<string, string> = 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": "未知错误",
});