mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-29 22:59:20 +09:00
feat(backend): Bearcaps URLに対応 (MisskeyIO#330)
This commit is contained in:
parent
a2cc3b6a12
commit
fa8784c038
@ -150,11 +150,14 @@ export class HttpRequestService {
|
|||||||
controller.abort();
|
controller.abort();
|
||||||
}, timeout);
|
}, timeout);
|
||||||
|
|
||||||
const res = await fetch(url, {
|
const bearcaps = url.startsWith('bear:?') ? this.parseBearcaps(url) : undefined;
|
||||||
|
|
||||||
|
const res = await fetch(bearcaps?.url ?? url, {
|
||||||
method: args.method ?? 'GET',
|
method: args.method ?? 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': this.config.userAgent,
|
'User-Agent': this.config.userAgent,
|
||||||
...(args.headers ?? {}),
|
...(args.headers ?? {}),
|
||||||
|
...(bearcaps?.token ? { Authorization: `Bearer ${bearcaps.token}` } : {}),
|
||||||
},
|
},
|
||||||
body: args.body,
|
body: args.body,
|
||||||
size: args.size ?? 10 * 1024 * 1024,
|
size: args.size ?? 10 * 1024 * 1024,
|
||||||
@ -168,4 +171,17 @@ export class HttpRequestService {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bearcaps https://docs.joinmastodon.org/spec/bearcaps/
|
||||||
|
// bear:?t=<token>&u=https://example.com/foo'
|
||||||
|
// -> GET https://example.com/foo Authorization: Bearer <token>
|
||||||
|
private parseBearcaps(url: string): { url: string, token: string | undefined } | undefined {
|
||||||
|
const params = new URLSearchParams(url.split('?')[1]);
|
||||||
|
if (!params.has('u')) return undefined;
|
||||||
|
|
||||||
|
return {
|
||||||
|
url: params.get('u')!,
|
||||||
|
token: params.get('t') ?? undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user