forked from FoundKeyGang/FoundKey
allow redirects in API ap/* endpoints
This commit is contained in:
parent
aa33708b90
commit
275136cf8b
3 changed files with 6 additions and 5 deletions
|
@ -45,7 +45,7 @@ export class Resolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resolve(value: string | IObject): Promise<IObject> {
|
public async resolve(value: string | IObject, allowRedirect = false): Promise<IObject> {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new Error('resolvee is null (or undefined)');
|
throw new Error('resolvee is null (or undefined)');
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ export class Resolver {
|
||||||
)
|
)
|
||||||
// Did we actually get the object that corresponds to the canonical URL?
|
// Did we actually get the object that corresponds to the canonical URL?
|
||||||
// Does the host we requested stuff from actually correspond to the host that owns the activity?
|
// Does the host we requested stuff from actually correspond to the host that owns the activity?
|
||||||
|| !(getApId(object) == null || getApId(object) === value)
|
|| !(getApId(object) == null || getApId(object) === value || allowRedirect)
|
||||||
) {
|
) {
|
||||||
throw new Error('invalid response');
|
throw new Error('invalid response');
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,6 @@ export const paramDef = {
|
||||||
// eslint-disable-next-line import/no-default-export
|
// eslint-disable-next-line import/no-default-export
|
||||||
export default define(meta, paramDef, async (ps) => {
|
export default define(meta, paramDef, async (ps) => {
|
||||||
const resolver = new Resolver();
|
const resolver = new Resolver();
|
||||||
const object = await resolver.resolve(ps.uri);
|
const object = await resolver.resolve(ps.uri, true);
|
||||||
return object;
|
return object;
|
||||||
});
|
});
|
||||||
|
|
|
@ -98,9 +98,10 @@ async function fetchAny(uri: string, me: CacheableLocalUser | null | undefined):
|
||||||
]));
|
]));
|
||||||
if (local != null) return local;
|
if (local != null) return local;
|
||||||
|
|
||||||
// リモートから一旦オブジェクトフェッチ
|
// fetch object from remote
|
||||||
const resolver = new Resolver();
|
const resolver = new Resolver();
|
||||||
const object = await resolver.resolve(uri) as any;
|
// allow redirect
|
||||||
|
const object = await resolver.resolve(uri, true) as any;
|
||||||
|
|
||||||
// /@user のような正規id以外で取得できるURIが指定されていた場合、ここで初めて正規URIが確定する
|
// /@user のような正規id以外で取得できるURIが指定されていた場合、ここで初めて正規URIが確定する
|
||||||
// これはDBに存在する可能性があるため再度DB検索
|
// これはDBに存在する可能性があるため再度DB検索
|
||||||
|
|
Loading…
Reference in a new issue