Skip to content

Commit

Permalink
refactor(admin): 为所有的 outputProblem 加上 await
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Dec 8, 2024
1 parent 9f34250 commit c2cb69f
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion admin/src/app/context/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function buildContext(opt: Required<buildOptions>, f: API) {

/**
* 设置登录状态并刷新 user
* @param account 账号密码信息
* @param r 登录接口返回的数据
* @returns true 表示登录成功,其它情况表示错误信息
*/
async login(r: Return<Token,never>) {
Expand Down
2 changes: 1 addition & 1 deletion admin/src/components/form/upload/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default function(props: Props): JSX.Element {

const ret = await ctx.api.upload<Array<string>>(props.action, data);
if (!ret.ok) {
ctx.outputProblem(ret.body);
await ctx.outputProblem(ret.body);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions admin/src/components/table/remote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function buildPagingLoadFunc<T extends object, Q extends Query>(ctx: AppContext,
return async (q: Q): Promise<Page<T> | undefined> => {
const ret = await ctx.api.get<Page<T>>(path + query2Search(q));
if (!ret.ok) {
ctx.outputProblem(ret.body);
await ctx.outputProblem(ret.body);
return { count: 0, current: [] };
}
return ret.body;
Expand All @@ -89,7 +89,7 @@ function buildNoPagingLoadFunc<T extends object, Q extends Query>(ctx: AppContex
return async (q: Q): Promise<Array<T> | undefined> => {
const ret = await ctx.api.get<Array<T>>(path + query2Search(q));
if (!ret.ok) {
ctx.outputProblem(ret.body);
await ctx.outputProblem(ret.body);
return [];
}
return ret.body;
Expand Down
2 changes: 1 addition & 1 deletion admin/src/core/api/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('API token', () => {
expect(t).toEqual('access');

fetchMock.mockResponseOnce(JSON.stringify(Object.assign({}, token)));
t = await f.getToken();
await f.getToken();
await sleep(1000);// 过期,但未过刷新令牌时间。会刷新令牌。
t = await f.getToken();
expect(t).toEqual('access');
Expand Down
3 changes: 1 addition & 2 deletions admin/src/core/api/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export class CacheImplement implements Cache {
}

async matchAll(_?: RequestInfo | URL, __?: CacheQueryOptions): Promise<ReadonlyArray<Response>> {
const arr: Readonly<Array<Response>> = [];
return arr;
return [];
}

async put(_: RequestInfo | URL, __: Response): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion admin/src/core/locale/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const durations: Array<[number, keyof Intl.DurationInput]> = [
] as const;

export function parseDuration(val?: number | string): Intl.DurationInput {
if (!val) { return { nanoseconds: 0 }; };
if (!val) { return { nanoseconds: 0 }; }

if (typeof val === 'string') {
if (isNaN(Number(val))) {
Expand Down
2 changes: 1 addition & 1 deletion admin/src/core/locale/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class Locale {
get unitStyle(): UnitStyle { return this.#unitStyle; }

/**
* 创建 {@link Intl#DateFormat} 对象
* 创建 {@link Intl#DateTimeFormat} 对象
*/
dateTimeFormat(o: Intl.DateTimeFormatOptions): Intl.DateTimeFormat {
return new Intl.DateTimeFormat(this.locale, o);
Expand Down
2 changes: 1 addition & 1 deletion admin/src/messages/cmn-Hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const messages: Messages = {
content: '内容',
ip: 'IP',
ua: 'UA',
uaInfo: '浏览器: {browser}({browserVersion}) 系统: {os}({osVersion}) 内核: {kernal}({kernalVersion})',
uaInfo: '浏览器: {browser}({browserVersion}) 系统: {os}({osVersion}) 内核: {kernel}({kernelVersion})',

profile: '个人信息',
name: '姓名',
Expand Down
4 changes: 2 additions & 2 deletions admin/src/messages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ const messages = {
content: 'content',
ip: 'IP',
ua: 'user agent',
uaInfo: 'browser: {browser}({browserVersion}) os: {os}({osVersion}) kernal: {kernal}({kernalVersion})',
uaInfo: 'browser: {browser}({browserVersion}) os: {os}({osVersion}) kernel: {kernel}({kernelVersion})',

profile: 'profle',
profile: 'profile',
name: 'name',
nickname: 'nickname',
pickAvatar: 'pick avatar',
Expand Down
8 changes: 4 additions & 4 deletions admin/src/pages/admins/admins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ export default function(props: Props): JSX.Element {
<Button icon rounded palette='error' title={ctx.locale().t('_i.page.admin.lockUser')} onClick={async()=>{
const r = await ctx.api.post(`/admins/${obj!['id']}/locked`);
if (!r.ok) {
ctx.outputProblem(r.body);
await ctx.outputProblem(r.body);
return;
}
ref.refresh();
await ref.refresh();
}}>lock</Button>
</Show>

<Show when={obj?.state === 'locked'}>
<Button icon rounded palette='tertiary' title={ctx.locale().t('_i.page.admin.unlockUser')} onClick={async()=>{
const r = await ctx.api.delete(`/admins/${obj!['id']}/locked`);
if (!r.ok) {
ctx.outputProblem(r.body);
await ctx.outputProblem(r.body);
return;
}
ref.refresh();
await ref.refresh();
}}>lock_open_right</Button>
</Show>

Expand Down
4 changes: 2 additions & 2 deletions admin/src/pages/admins/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export default function(): JSX.Element {
form.setPreset(r1.body!);
form.setObject(r1.body!);
} else {
ctx.outputProblem(r1.body);
await ctx.outputProblem(r1.body);
}

const r2 = await ctx.api.get<Array<Passport>>('/passports');
if (!r2.ok) {
ctx.outputProblem(r2.body);
await ctx.outputProblem(r2.body);
return;
}
setPassports(r2.body!);
Expand Down
2 changes: 1 addition & 1 deletion admin/src/pages/current/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function Login(props: Props): JSX.Element {
onMount(async () => {
const r = await ctx.api.get<Array<Passport>>('/passports');
if (!r.ok) {
ctx.outputProblem(r.body);
await ctx.outputProblem(r.body);
return;
}
setPassports(r.body!.map((v)=>[v.id,v.desc]));
Expand Down
2 changes: 1 addition & 1 deletion admin/src/pages/current/passport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Pwd implements PassportComponents {
return undefined;
}

ctx.refetchUser();
await ctx.refetchUser();
return undefined;
})}>
<form class="flex flex-col gap-2">
Expand Down
4 changes: 2 additions & 2 deletions admin/src/pages/current/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function(props: Props): JSX.Element {
onMount(async () => {
const r = await ctx.api.get<Array<Passport>>('/passports');
if (!r.ok) {
ctx.outputProblem(r.body);
await ctx.outputProblem(r.body);
return;
}
setPassports(r.body!);
Expand All @@ -95,7 +95,7 @@ export default function(props: Props): JSX.Element {
setAvatar(ret[0]);
const r = await ctx.api.patch('/info', { 'avatar': ret[0] });
if (!r.ok) {
ctx.outputProblem(r.body);
await ctx.outputProblem(r.body);
return;
}
await ctx.refetchUser();
Expand Down
4 changes: 2 additions & 2 deletions admin/src/pages/current/securitylogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export default function() {
browserVersion: info.browser.version,
os: info.os.name,
osVersion: info.os.version,
kernal: info.engine.name,
kernalVersion: info.engine.version,
kernel: info.engine.name,
kernelVersion: info.engine.version,
});
} },
{ id: 'created', label: ctx.locale().t('_i.page.created'), content:(_: string, val?: string)=>{
Expand Down
8 changes: 4 additions & 4 deletions admin/src/pages/members/members.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ export default function(props: Props): JSX.Element {
<Button icon rounded palette='error' title={ctx.locale().t('_i.page.admin.lockUser')} onClick={async()=>{
const r = await ctx.api.post(`/members/${obj!['id']}/locked`);
if (!r.ok) {
ctx.outputProblem(r.body);
await ctx.outputProblem(r.body);
return;
}
ref.refresh();
await ref.refresh();
}}>lock</Button>
</Show>

<Show when={obj?.state === 'locked'}>
<Button icon rounded palette='tertiary' title={ctx.locale().t('_i.page.admin.unlockUser')} onClick={async()=>{
const r = await ctx.api.delete(`/members/${obj!['id']}/locked`);
if (!r.ok) {
ctx.outputProblem(r.body);
await ctx.outputProblem(r.body);
return;
}
ref.refresh();
await ref.refresh();
}}>lock_open_right</Button>
</Show>

Expand Down
2 changes: 1 addition & 1 deletion admin/src/pages/roles/roles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function Roles(props: Props): JSX.Element {
await ctx.outputProblem(ret.body);
return;
}
tableRef.refresh();
await tableRef.refresh();
};

const edit = (id: string) => {
Expand Down
2 changes: 1 addition & 1 deletion admin/src/pages/roles/selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function<M extends boolean>(props: Props<M>): JSX.Element {
onMount(async () => {
const r = await ctx.api.get<Array<Role>>('/roles');
if (!r.ok) {
ctx.outputProblem(r.body);
await ctx.outputProblem(r.body);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions admin/src/pages/system/info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function(): JSX.Element {
<ConfirmButton palette='secondary' disabled={backup()?.cron===''} onClick={async()=>{
const ret = await ctx.api.post('/system/backup');
if (!ret.ok) {
ctx.outputProblem(ret.body);
await ctx.outputProblem(ret.body);
return;
}
await refetch();
Expand All @@ -113,7 +113,7 @@ export default function(): JSX.Element {
<ConfirmButton kind='flat' palette='error' onClick={async()=>{
const ret = await ctx.api.delete('/system/backup/'+item.path);
if (!ret.ok) {
ctx.outputProblem(ret.body);
await ctx.outputProblem(ret.body);
return;
}
await refetch();
Expand Down

0 comments on commit c2cb69f

Please sign in to comment.