student_2333 1d7100a053
fix
2024-04-30 13:05:08 +08:00

38 lines
818 B
TypeScript

import { log } from './log'
export interface IdMusicSignPostData {
type: 'qq' | '163'
id: string | number
}
export interface CustomMusicSignPostData {
type: 'custom'
url: string
audio: string
title: string
image?: string
singer?: string
}
export type MusicSignPostData = IdMusicSignPostData | CustomMusicSignPostData
export class MusicSign {
private readonly url: string
constructor(url: string) {
this.url = url
}
async sign(postData: MusicSignPostData): Promise<any> {
const resp = await fetch(this.url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(postData),
})
if (!resp.ok) throw new Error(resp.statusText)
const data = await resp.json()
log('音乐消息生成成功', data)
return data
}
}