Make User-Agent header optional in ModrinthClient

This commit is contained in:
CPTProgrammer 2026-07-06 23:13:17 +08:00
parent a52dd3915e
commit a823863d0b
No known key found for this signature in database

View File

@ -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 响应体。 */