16 lines
585 B
TypeScript
16 lines
585 B
TypeScript
const DESKTOP_CLIENT_ID = 'genuine-qingquwang'
|
|
const VISIBLE_ASCII = /^[\x20-\x7E]+$/
|
|
|
|
export function buildDesktopRequestHeaders(version: string): Record<string, string> {
|
|
const clientHeader = `${DESKTOP_CLIENT_ID}/${version}`
|
|
// Fetch 请求头必须是 ByteString,禁止中文等非 ASCII 字符在发请求前触发异常。
|
|
if (!VISIBLE_ASCII.test(clientHeader)) {
|
|
throw new Error('桌面客户端版本标识必须使用 ASCII 字符')
|
|
}
|
|
return {
|
|
Accept: 'application/json',
|
|
'Content-Type': 'application/json',
|
|
'X-Desktop-Client': clientHeader,
|
|
}
|
|
}
|