fix(fe/state_updater): return err key intean of void, number

This commit is contained in:
hexxa 2021-12-14 16:06:04 +08:00 committed by Hexxa
parent 64d92a5ebb
commit 6be20f5d76
6 changed files with 64 additions and 79 deletions

View file

@ -107,8 +107,8 @@ export class UserForm extends React.Component<
return updater()
.forceSetPwd(this.state.id, this.state.newPwd1)
.then((ok: boolean) => {
if (ok) {
.then((status: string) => {
if (status === "") {
alertMsg(this.props.msg.pkg.get("update.ok"));
} else {
alertMsg(this.props.msg.pkg.get("update.fail"));
@ -123,11 +123,11 @@ export class UserForm extends React.Component<
setUser = async () => {
return updater()
.setUser(this.props.id, this.state.role, this.state.quota)
.then((ok: boolean) => {
if (!ok) {
alertMsg(this.props.msg.pkg.get("update.fail"));
} else {
.then((status: string) => {
if (status === "") {
alertMsg(this.props.msg.pkg.get("update.ok"));
} else {
alertMsg(this.props.msg.pkg.get("update.fail"));
}
return updater().listUsers();
})
@ -139,13 +139,13 @@ export class UserForm extends React.Component<
delUser = async () => {
return updater()
.delUser(this.state.id)
.then((ok: boolean) => {
if (!ok) {
.then((status: string) => {
if (status !== "") {
alertMsg(this.props.msg.pkg.get("delete.fail"));
}
return updater().listUsers();
})
.then((_: boolean) => {
.then((_: string) => {
this.props.update(updater().updateAdmin);
});
};
@ -345,8 +345,8 @@ export class AdminPane extends React.Component<Props, State, {}> {
addRole = async () => {
return updater()
.addRole(this.state.newRole)
.then((ok: boolean) => {
if (!ok) {
.then((status: string) => {
if (status !== "") {
alertMsg(this.props.msg.pkg.get("add.fail"));
} else {
alertMsg(this.props.msg.pkg.get("add.ok"));
@ -365,8 +365,8 @@ export class AdminPane extends React.Component<Props, State, {}> {
return updater()
.delRole(role)
.then((ok: boolean) => {
if (!ok) {
.then((status: string) => {
if (status !== "") {
this.props.msg.pkg.get("delete.fail");
} else {
this.props.msg.pkg.get("delete.ok");
@ -394,8 +394,8 @@ export class AdminPane extends React.Component<Props, State, {}> {
usedSpace: "0",
preferences: undefined,
})
.then((ok: boolean) => {
if (!ok) {
.then((status: string) => {
if (status !== "") {
alertMsg(this.props.msg.pkg.get("add.fail"));
} else {
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,
bg: this.props.ui.bg,
})
.then((code: number) => {
if (code === 200) {
.then((status: string) => {
if (status === "") {
alertMsg(this.props.msg.pkg.get("update.ok"));
} else {
alertMsg(this.props.msg.pkg.get("update.fail"));
@ -698,9 +698,7 @@ export class BgCfg extends React.Component<BgProps, BgState, {}> {
<div>
<Flexbox
children={List([
<h5 className="title">
{this.props.msg.pkg.get("cfg.bg")}
</h5>,
<h5 className="title">{this.props.msg.pkg.get("cfg.bg")}</h5>,
<span>
<button onClick={this.resetClientCfg} className="margin-r-m">

View file

@ -62,9 +62,9 @@ export class AuthPane extends React.Component<Props, State, {}> {
this.props.login.captchaID,
this.state.captchaInput
)
.then((ok: boolean): Promise<any> => {
.then((status: string): Promise<any> => {
this.setState({ captchaInput: "" });
if (ok) {
if (status === "") {
const params = new URLSearchParams(
document.location.search.substring(1)
);

View file

@ -86,8 +86,8 @@ export class PaneSettings extends React.Component<Props, State, {}> {
syncPreferences = async () => {
updater()
.syncPreferences()
.then((status: number) => {
if (status === 200) {
.then((status: string) => {
if (status === "") {
alertMsg(this.props.msg.pkg.get("update.ok"));
} else {
alertMsg(this.props.msg.pkg.get("update.fail"));
@ -109,8 +109,8 @@ export class PaneSettings extends React.Component<Props, State, {}> {
} else {
return updater()
.setPwd(this.state.oldPwd, this.state.newPwd1)
.then((ok: boolean) => {
if (ok) {
.then((status: string) => {
if (status) {
alertMsg(this.props.msg.pkg.get("update.ok"));
} else {
alertMsg(this.props.msg.pkg.get("update.fail"));
@ -128,8 +128,8 @@ export class PaneSettings extends React.Component<Props, State, {}> {
updater().setLan(lan);
updater()
.syncPreferences()
.then((status: number) => {
if (status === 200) {
.then((status: string) => {
if (status === "") {
alertMsg(this.props.msg.pkg.get("update.ok"));
} else {
alertMsg(this.props.msg.pkg.get("update.fail"));

View file

@ -313,9 +313,9 @@ export class FilesPanel extends React.Component<Props, State, {}> {
this.setState({ showDetail });
};
generateHash = async (filePath: string): Promise<boolean> => {
generateHash = async (filePath: string) => {
alertMsg(this.props.msg.pkg.get("refresh-hint"));
return updater().generateHash(filePath);
updater().generateHash(filePath);
};
addSharing = async () => {

View file

@ -512,40 +512,40 @@ export class Updater {
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);
// 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);
return resp.status === 200;
return resp.status === 200 ? "" : "server.fail";
};
setUser = async (
userID: string,
role: string,
quota: Quota
): Promise<boolean> => {
): Promise<string> => {
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);
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);
return resp.status === 200;
return resp.status === 200 ? "" : "server.fail";
};
listUsers = async (): Promise<boolean> => {
listUsers = async (): Promise<string> => {
const resp = await this.usersClient.listUsers();
if (resp.status !== 200) {
return false;
return "server.fail";
}
const lsRes = resp.data as ListUsersResp;
@ -555,24 +555,24 @@ export class Updater {
});
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);
// TODO: should return uid instead
return resp.status === 200;
// TODO: should return id instead
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);
return resp.status === 200;
return resp.status === 200 ? "" : "server.fail";
};
listRoles = async (): Promise<boolean> => {
listRoles = async (): Promise<string> => {
const resp = await this.usersClient.listRoles();
if (resp.status !== 200) {
return false;
return "server.fail";
}
const lsRes = resp.data as ListRolesResp;
@ -582,7 +582,7 @@ export class Updater {
});
this.props.admin.roles = roles;
return true;
return "";
};
login = async (
@ -590,7 +590,7 @@ export class Updater {
pwd: string,
captchaID: string,
captchaInput: string
): Promise<boolean> => {
): Promise<string> => {
const resp = await this.usersClient.login(
user,
pwd,
@ -598,13 +598,13 @@ export class Updater {
captchaInput
);
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();
this.resetUser();
return resp.status === 200;
return resp.status === 200 ? "" : "server.fail";
};
syncIsAuthed = async (): Promise<string> => {
@ -617,19 +617,6 @@ export class Updater {
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> => {
const resp = await this.usersClient.getCaptchaID();
if (resp.status !== 200) {
@ -639,9 +626,9 @@ export class Updater {
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);
return resp.status === 200;
return resp.status === 200 ? "" : "server.fail";
};
setLan = (lan: string) => {
@ -679,17 +666,17 @@ export class Updater {
return true;
};
generateHash = async (filePath: string): Promise<boolean> => {
generateHash = async (filePath: string): Promise<string> => {
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);
return resp.status;
return resp.status === 200 ? "" : "server.fail";
};
setClientCfg = async (cfg: ClientConfig): Promise<void> => {
setClientCfg = (cfg: ClientConfig) => {
this.props.ui = {
...this.props.ui,
siteName: cfg.siteName,
@ -702,11 +689,11 @@ export class Updater {
this.props.login.preferences = { ...prefer };
};
syncPreferences = async (): Promise<number> => {
syncPreferences = async (): Promise<string> => {
const resp = await this.usersClient.setPreferences(
this.props.login.preferences
);
return resp.status;
return resp.status === 200 ? "" : "server.fail";
};
getClientCfg = async (): Promise<string> => {

View file

@ -39,8 +39,8 @@ export class TopBar extends React.Component<Props, State, {}> {
return updater()
.logout()
.then((ok: boolean) => {
if (ok) {
.then((status: string) => {
if (status === "") {
const params = new URLSearchParams(
document.location.search.substring(1)
);