Make User-Agent header optional in ModrinthClient
This commit is contained in:
parent
a52dd3915e
commit
a823863d0b
@ -2,19 +2,22 @@
|
||||
export class ModrinthClient {
|
||||
private base = "https://api.modrinth.com/v2";
|
||||
private token: string;
|
||||
private userAgent: string;
|
||||
private userAgent?: string;
|
||||
|
||||
constructor(token: string, userAgent?: string) {
|
||||
this.token = token;
|
||||
this.userAgent = userAgent ?? "";
|
||||
this.userAgent = userAgent;
|
||||
}
|
||||
|
||||
/** 构造通用请求头(Authorization + User-Agent)。 */
|
||||
/** 构造通用请求头(Authorization,以及可选的 User-Agent)。 */
|
||||
private headers(): Record<string, string> {
|
||||
return {
|
||||
const h: Record<string, string> = {
|
||||
Authorization: this.token,
|
||||
"User-Agent": this.userAgent,
|
||||
};
|
||||
if (this.userAgent) {
|
||||
h["User-Agent"] = this.userAgent;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
/** 发送 GET 请求并解析 JSON 响应体。 */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user