fix(fe/state_updater): return err key intean of void, number
This commit is contained in:
parent
64d92a5ebb
commit
6be20f5d76
6 changed files with 64 additions and 79 deletions
|
@ -107,8 +107,8 @@ export class UserForm extends React.Component<
|
||||||
|
|
||||||
return updater()
|
return updater()
|
||||||
.forceSetPwd(this.state.id, this.state.newPwd1)
|
.forceSetPwd(this.state.id, this.state.newPwd1)
|
||||||
.then((ok: boolean) => {
|
.then((status: string) => {
|
||||||
if (ok) {
|
if (status === "") {
|
||||||
alertMsg(this.props.msg.pkg.get("update.ok"));
|
alertMsg(this.props.msg.pkg.get("update.ok"));
|
||||||
} else {
|
} else {
|
||||||
alertMsg(this.props.msg.pkg.get("update.fail"));
|
alertMsg(this.props.msg.pkg.get("update.fail"));
|
||||||
|
@ -123,11 +123,11 @@ export class UserForm extends React.Component<
|
||||||
setUser = async () => {
|
setUser = async () => {
|
||||||
return updater()
|
return updater()
|
||||||
.setUser(this.props.id, this.state.role, this.state.quota)
|
.setUser(this.props.id, this.state.role, this.state.quota)
|
||||||
.then((ok: boolean) => {
|
.then((status: string) => {
|
||||||
if (!ok) {
|
if (status === "") {
|
||||||
alertMsg(this.props.msg.pkg.get("update.fail"));
|
|
||||||
} else {
|
|
||||||
alertMsg(this.props.msg.pkg.get("update.ok"));
|
alertMsg(this.props.msg.pkg.get("update.ok"));
|
||||||
|
} else {
|
||||||
|
alertMsg(this.props.msg.pkg.get("update.fail"));
|
||||||
}
|
}
|
||||||
return updater().listUsers();
|
return updater().listUsers();
|
||||||
})
|
})
|
||||||
|
@ -139,13 +139,13 @@ export class UserForm extends React.Component<
|
||||||
delUser = async () => {
|
delUser = async () => {
|
||||||
return updater()
|
return updater()
|
||||||
.delUser(this.state.id)
|
.delUser(this.state.id)
|
||||||
.then((ok: boolean) => {
|
.then((status: string) => {
|
||||||
if (!ok) {
|
if (status !== "") {
|
||||||
alertMsg(this.props.msg.pkg.get("delete.fail"));
|
alertMsg(this.props.msg.pkg.get("delete.fail"));
|
||||||
}
|
}
|
||||||
return updater().listUsers();
|
return updater().listUsers();
|
||||||
})
|
})
|
||||||
.then((_: boolean) => {
|
.then((_: string) => {
|
||||||
this.props.update(updater().updateAdmin);
|
this.props.update(updater().updateAdmin);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -345,8 +345,8 @@ export class AdminPane extends React.Component<Props, State, {}> {
|
||||||
addRole = async () => {
|
addRole = async () => {
|
||||||
return updater()
|
return updater()
|
||||||
.addRole(this.state.newRole)
|
.addRole(this.state.newRole)
|
||||||
.then((ok: boolean) => {
|
.then((status: string) => {
|
||||||
if (!ok) {
|
if (status !== "") {
|
||||||
alertMsg(this.props.msg.pkg.get("add.fail"));
|
alertMsg(this.props.msg.pkg.get("add.fail"));
|
||||||
} else {
|
} else {
|
||||||
alertMsg(this.props.msg.pkg.get("add.ok"));
|
alertMsg(this.props.msg.pkg.get("add.ok"));
|
||||||
|
@ -365,8 +365,8 @@ export class AdminPane extends React.Component<Props, State, {}> {
|
||||||
|
|
||||||
return updater()
|
return updater()
|
||||||
.delRole(role)
|
.delRole(role)
|
||||||
.then((ok: boolean) => {
|
.then((status: string) => {
|
||||||
if (!ok) {
|
if (status !== "") {
|
||||||
this.props.msg.pkg.get("delete.fail");
|
this.props.msg.pkg.get("delete.fail");
|
||||||
} else {
|
} else {
|
||||||
this.props.msg.pkg.get("delete.ok");
|
this.props.msg.pkg.get("delete.ok");
|
||||||
|
@ -394,8 +394,8 @@ export class AdminPane extends React.Component<Props, State, {}> {
|
||||||
usedSpace: "0",
|
usedSpace: "0",
|
||||||
preferences: undefined,
|
preferences: undefined,
|
||||||
})
|
})
|
||||||
.then((ok: boolean) => {
|
.then((status: string) => {
|
||||||
if (!ok) {
|
if (status !== "") {
|
||||||
alertMsg(this.props.msg.pkg.get("add.fail"));
|
alertMsg(this.props.msg.pkg.get("add.fail"));
|
||||||
} else {
|
} else {
|
||||||
alertMsg(this.props.msg.pkg.get("add.ok"));
|
alertMsg(this.props.msg.pkg.get("add.ok"));
|
||||||
|
@ -669,8 +669,8 @@ export class BgCfg extends React.Component<BgProps, BgState, {}> {
|
||||||
siteDesc: this.props.ui.siteDesc,
|
siteDesc: this.props.ui.siteDesc,
|
||||||
bg: this.props.ui.bg,
|
bg: this.props.ui.bg,
|
||||||
})
|
})
|
||||||
.then((code: number) => {
|
.then((status: string) => {
|
||||||
if (code === 200) {
|
if (status === "") {
|
||||||
alertMsg(this.props.msg.pkg.get("update.ok"));
|
alertMsg(this.props.msg.pkg.get("update.ok"));
|
||||||
} else {
|
} else {
|
||||||
alertMsg(this.props.msg.pkg.get("update.fail"));
|
alertMsg(this.props.msg.pkg.get("update.fail"));
|
||||||
|
@ -698,9 +698,7 @@ export class BgCfg extends React.Component<BgProps, BgState, {}> {
|
||||||
<div>
|
<div>
|
||||||
<Flexbox
|
<Flexbox
|
||||||
children={List([
|
children={List([
|
||||||
<h5 className="title">
|
<h5 className="title">{this.props.msg.pkg.get("cfg.bg")}</h5>,
|
||||||
{this.props.msg.pkg.get("cfg.bg")}
|
|
||||||
</h5>,
|
|
||||||
|
|
||||||
<span>
|
<span>
|
||||||
<button onClick={this.resetClientCfg} className="margin-r-m">
|
<button onClick={this.resetClientCfg} className="margin-r-m">
|
||||||
|
|
|
@ -62,9 +62,9 @@ export class AuthPane extends React.Component<Props, State, {}> {
|
||||||
this.props.login.captchaID,
|
this.props.login.captchaID,
|
||||||
this.state.captchaInput
|
this.state.captchaInput
|
||||||
)
|
)
|
||||||
.then((ok: boolean): Promise<any> => {
|
.then((status: string): Promise<any> => {
|
||||||
this.setState({ captchaInput: "" });
|
this.setState({ captchaInput: "" });
|
||||||
if (ok) {
|
if (status === "") {
|
||||||
const params = new URLSearchParams(
|
const params = new URLSearchParams(
|
||||||
document.location.search.substring(1)
|
document.location.search.substring(1)
|
||||||
);
|
);
|
||||||
|
|
|
@ -86,8 +86,8 @@ export class PaneSettings extends React.Component<Props, State, {}> {
|
||||||
syncPreferences = async () => {
|
syncPreferences = async () => {
|
||||||
updater()
|
updater()
|
||||||
.syncPreferences()
|
.syncPreferences()
|
||||||
.then((status: number) => {
|
.then((status: string) => {
|
||||||
if (status === 200) {
|
if (status === "") {
|
||||||
alertMsg(this.props.msg.pkg.get("update.ok"));
|
alertMsg(this.props.msg.pkg.get("update.ok"));
|
||||||
} else {
|
} else {
|
||||||
alertMsg(this.props.msg.pkg.get("update.fail"));
|
alertMsg(this.props.msg.pkg.get("update.fail"));
|
||||||
|
@ -109,8 +109,8 @@ export class PaneSettings extends React.Component<Props, State, {}> {
|
||||||
} else {
|
} else {
|
||||||
return updater()
|
return updater()
|
||||||
.setPwd(this.state.oldPwd, this.state.newPwd1)
|
.setPwd(this.state.oldPwd, this.state.newPwd1)
|
||||||
.then((ok: boolean) => {
|
.then((status: string) => {
|
||||||
if (ok) {
|
if (status) {
|
||||||
alertMsg(this.props.msg.pkg.get("update.ok"));
|
alertMsg(this.props.msg.pkg.get("update.ok"));
|
||||||
} else {
|
} else {
|
||||||
alertMsg(this.props.msg.pkg.get("update.fail"));
|
alertMsg(this.props.msg.pkg.get("update.fail"));
|
||||||
|
@ -128,8 +128,8 @@ export class PaneSettings extends React.Component<Props, State, {}> {
|
||||||
updater().setLan(lan);
|
updater().setLan(lan);
|
||||||
updater()
|
updater()
|
||||||
.syncPreferences()
|
.syncPreferences()
|
||||||
.then((status: number) => {
|
.then((status: string) => {
|
||||||
if (status === 200) {
|
if (status === "") {
|
||||||
alertMsg(this.props.msg.pkg.get("update.ok"));
|
alertMsg(this.props.msg.pkg.get("update.ok"));
|
||||||
} else {
|
} else {
|
||||||
alertMsg(this.props.msg.pkg.get("update.fail"));
|
alertMsg(this.props.msg.pkg.get("update.fail"));
|
||||||
|
|
|
@ -313,9 +313,9 @@ export class FilesPanel extends React.Component<Props, State, {}> {
|
||||||
this.setState({ showDetail });
|
this.setState({ showDetail });
|
||||||
};
|
};
|
||||||
|
|
||||||
generateHash = async (filePath: string): Promise<boolean> => {
|
generateHash = async (filePath: string) => {
|
||||||
alertMsg(this.props.msg.pkg.get("refresh-hint"));
|
alertMsg(this.props.msg.pkg.get("refresh-hint"));
|
||||||
return updater().generateHash(filePath);
|
updater().generateHash(filePath);
|
||||||
};
|
};
|
||||||
|
|
||||||
addSharing = async () => {
|
addSharing = async () => {
|
||||||
|
|
|
@ -512,40 +512,40 @@ export class Updater {
|
||||||
return "server.fail";
|
return "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
addUser = async (user: User): Promise<boolean> => {
|
addUser = async (user: User): Promise<string> => {
|
||||||
const resp = await this.usersClient.addUser(user.name, user.pwd, user.role);
|
const resp = await this.usersClient.addUser(user.name, user.pwd, user.role);
|
||||||
// TODO: should return uid instead
|
// TODO: should return uid instead
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
delUser = async (userID: string): Promise<boolean> => {
|
delUser = async (userID: string): Promise<string> => {
|
||||||
const resp = await this.usersClient.delUser(userID);
|
const resp = await this.usersClient.delUser(userID);
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
setUser = async (
|
setUser = async (
|
||||||
userID: string,
|
userID: string,
|
||||||
role: string,
|
role: string,
|
||||||
quota: Quota
|
quota: Quota
|
||||||
): Promise<boolean> => {
|
): Promise<string> => {
|
||||||
const resp = await this.usersClient.setUser(userID, role, quota);
|
const resp = await this.usersClient.setUser(userID, role, quota);
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
setRole = async (userID: string, role: string): Promise<boolean> => {
|
setRole = async (userID: string, role: string): Promise<string> => {
|
||||||
const resp = await this.usersClient.delUser(userID);
|
const resp = await this.usersClient.delUser(userID);
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
forceSetPwd = async (userID: string, pwd: string): Promise<boolean> => {
|
forceSetPwd = async (userID: string, pwd: string): Promise<string> => {
|
||||||
const resp = await this.usersClient.forceSetPwd(userID, pwd);
|
const resp = await this.usersClient.forceSetPwd(userID, pwd);
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
listUsers = async (): Promise<boolean> => {
|
listUsers = async (): Promise<string> => {
|
||||||
const resp = await this.usersClient.listUsers();
|
const resp = await this.usersClient.listUsers();
|
||||||
if (resp.status !== 200) {
|
if (resp.status !== 200) {
|
||||||
return false;
|
return "server.fail";
|
||||||
}
|
}
|
||||||
|
|
||||||
const lsRes = resp.data as ListUsersResp;
|
const lsRes = resp.data as ListUsersResp;
|
||||||
|
@ -555,24 +555,24 @@ export class Updater {
|
||||||
});
|
});
|
||||||
this.props.admin.users = users;
|
this.props.admin.users = users;
|
||||||
|
|
||||||
return true;
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
addRole = async (role: string): Promise<boolean> => {
|
addRole = async (role: string): Promise<string> => {
|
||||||
const resp = await this.usersClient.addRole(role);
|
const resp = await this.usersClient.addRole(role);
|
||||||
// TODO: should return uid instead
|
// TODO: should return id instead
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
delRole = async (role: string): Promise<boolean> => {
|
delRole = async (role: string): Promise<string> => {
|
||||||
const resp = await this.usersClient.delRole(role);
|
const resp = await this.usersClient.delRole(role);
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
listRoles = async (): Promise<boolean> => {
|
listRoles = async (): Promise<string> => {
|
||||||
const resp = await this.usersClient.listRoles();
|
const resp = await this.usersClient.listRoles();
|
||||||
if (resp.status !== 200) {
|
if (resp.status !== 200) {
|
||||||
return false;
|
return "server.fail";
|
||||||
}
|
}
|
||||||
|
|
||||||
const lsRes = resp.data as ListRolesResp;
|
const lsRes = resp.data as ListRolesResp;
|
||||||
|
@ -582,7 +582,7 @@ export class Updater {
|
||||||
});
|
});
|
||||||
this.props.admin.roles = roles;
|
this.props.admin.roles = roles;
|
||||||
|
|
||||||
return true;
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
login = async (
|
login = async (
|
||||||
|
@ -590,7 +590,7 @@ export class Updater {
|
||||||
pwd: string,
|
pwd: string,
|
||||||
captchaID: string,
|
captchaID: string,
|
||||||
captchaInput: string
|
captchaInput: string
|
||||||
): Promise<boolean> => {
|
): Promise<string> => {
|
||||||
const resp = await this.usersClient.login(
|
const resp = await this.usersClient.login(
|
||||||
user,
|
user,
|
||||||
pwd,
|
pwd,
|
||||||
|
@ -598,13 +598,13 @@ export class Updater {
|
||||||
captchaInput
|
captchaInput
|
||||||
);
|
);
|
||||||
this.props.login.authed = resp.status === 200;
|
this.props.login.authed = resp.status === 200;
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
logout = async (): Promise<boolean> => {
|
logout = async (): Promise<string> => {
|
||||||
const resp = await this.usersClient.logout();
|
const resp = await this.usersClient.logout();
|
||||||
this.resetUser();
|
this.resetUser();
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
syncIsAuthed = async (): Promise<string> => {
|
syncIsAuthed = async (): Promise<string> => {
|
||||||
|
@ -617,19 +617,6 @@ export class Updater {
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
// initIsAuthed = async (): Promise<string> => {
|
|
||||||
// const status = await this.isAuthed();
|
|
||||||
// if (status !== "") {
|
|
||||||
// return status;
|
|
||||||
// }
|
|
||||||
// updater().setAuthed(isAuthed);
|
|
||||||
// return
|
|
||||||
// };
|
|
||||||
|
|
||||||
// setAuthed = (isAuthed: boolean) => {
|
|
||||||
// this.props.login.authed = isAuthed;
|
|
||||||
// };
|
|
||||||
|
|
||||||
getCaptchaID = async (): Promise<string> => {
|
getCaptchaID = async (): Promise<string> => {
|
||||||
const resp = await this.usersClient.getCaptchaID();
|
const resp = await this.usersClient.getCaptchaID();
|
||||||
if (resp.status !== 200) {
|
if (resp.status !== 200) {
|
||||||
|
@ -639,9 +626,9 @@ export class Updater {
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
setPwd = async (oldPwd: string, newPwd: string): Promise<boolean> => {
|
setPwd = async (oldPwd: string, newPwd: string): Promise<string> => {
|
||||||
const resp = await this.usersClient.setPwd(oldPwd, newPwd);
|
const resp = await this.usersClient.setPwd(oldPwd, newPwd);
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
setLan = (lan: string) => {
|
setLan = (lan: string) => {
|
||||||
|
@ -679,17 +666,17 @@ export class Updater {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
generateHash = async (filePath: string): Promise<boolean> => {
|
generateHash = async (filePath: string): Promise<string> => {
|
||||||
const resp = await this.filesClient.generateHash(filePath);
|
const resp = await this.filesClient.generateHash(filePath);
|
||||||
return resp.status === 200;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
setClientCfgRemote = async (cfg: ClientConfig): Promise<number> => {
|
setClientCfgRemote = async (cfg: ClientConfig): Promise<string> => {
|
||||||
const resp = await this.settingsClient.setClientCfg(cfg);
|
const resp = await this.settingsClient.setClientCfg(cfg);
|
||||||
return resp.status;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
setClientCfg = async (cfg: ClientConfig): Promise<void> => {
|
setClientCfg = (cfg: ClientConfig) => {
|
||||||
this.props.ui = {
|
this.props.ui = {
|
||||||
...this.props.ui,
|
...this.props.ui,
|
||||||
siteName: cfg.siteName,
|
siteName: cfg.siteName,
|
||||||
|
@ -702,11 +689,11 @@ export class Updater {
|
||||||
this.props.login.preferences = { ...prefer };
|
this.props.login.preferences = { ...prefer };
|
||||||
};
|
};
|
||||||
|
|
||||||
syncPreferences = async (): Promise<number> => {
|
syncPreferences = async (): Promise<string> => {
|
||||||
const resp = await this.usersClient.setPreferences(
|
const resp = await this.usersClient.setPreferences(
|
||||||
this.props.login.preferences
|
this.props.login.preferences
|
||||||
);
|
);
|
||||||
return resp.status;
|
return resp.status === 200 ? "" : "server.fail";
|
||||||
};
|
};
|
||||||
|
|
||||||
getClientCfg = async (): Promise<string> => {
|
getClientCfg = async (): Promise<string> => {
|
||||||
|
|
|
@ -39,8 +39,8 @@ export class TopBar extends React.Component<Props, State, {}> {
|
||||||
|
|
||||||
return updater()
|
return updater()
|
||||||
.logout()
|
.logout()
|
||||||
.then((ok: boolean) => {
|
.then((status: string) => {
|
||||||
if (ok) {
|
if (status === "") {
|
||||||
const params = new URLSearchParams(
|
const params = new URLSearchParams(
|
||||||
document.location.search.substring(1)
|
document.location.search.substring(1)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue