forked from liou666/polyglot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
export const getAvatarUrl = (filename: string) => { | ||
return new URL(`../assets/avatars/${filename}`, import.meta.url).href | ||
} | ||
export async function fetchWithTimeout( | ||
url: string, | ||
timeout: number, | ||
options: RequestInit = {}, | ||
): Promise<Response> { | ||
const controller = new AbortController() | ||
const timeoutId = setTimeout(() => { | ||
controller.abort() | ||
// throw new Error(`网络请求 ${url} 已超时`) | ||
}, timeout) | ||
|
||
const { method = 'GET', headers = {}, body } = options | ||
|
||
const response = await fetch(url, { | ||
method, | ||
headers, | ||
body, | ||
signal: controller.signal, | ||
}) | ||
|
||
clearTimeout(timeoutId) | ||
|
||
return response | ||
} |