mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-06-27 00:34:50 +08:00
use thunk to get targetName
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import { RootState, store } from '../../app/store';
|
||||
import { AppThunk } from '../../app/store';
|
||||
import { baseUrl } from '../../utils/urls';
|
||||
|
||||
export default async function getTargetName(platformName: string, target: string) {
|
||||
const url = `${baseUrl}target_name?platformName=${platformName}&target=${target}`;
|
||||
const state = store.getState() as RootState;
|
||||
const authToken = state.auth.token;
|
||||
const res = await fetch(url, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
},
|
||||
});
|
||||
const resObj = await res.json();
|
||||
return resObj.targetName as string;
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
export const getTargetName =
|
||||
(platformName: string, target: string): AppThunk<Promise<string>> => async (_, getState) => {
|
||||
const url = `${baseUrl}target_name?platformName=${platformName}&target=${target}`;
|
||||
const state = getState();
|
||||
const authToken = state.auth.token;
|
||||
const res = await fetch(url, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
},
|
||||
});
|
||||
const resObj = await res.json();
|
||||
return resObj.targetName as string;
|
||||
};
|
||||
|
||||
export default getTargetName;
|
||||
|
||||
Reference in New Issue
Block a user