Fix AP resolver history on reuse for authorized fetch
This commit is contained in:
parent
d9fc2c061d
commit
b20298ceb1
3 changed files with 18 additions and 4 deletions
|
@ -36,7 +36,7 @@ export default async (user: { id: User["id"] }, url: string, object: any) => {
|
|||
* @param url URL to fetch
|
||||
*/
|
||||
export async function signedGet(url: string, user: { id: User["id"] }) {
|
||||
apLogger.debug("running signedGet on url: " + url);
|
||||
apLogger.debug(`Running signedGet on url: ${url}`);
|
||||
const keypair = await getUserKeypair(user.id);
|
||||
|
||||
const req = createSignedGet({
|
||||
|
|
|
@ -39,6 +39,11 @@ export default class Resolver {
|
|||
this.user = user;
|
||||
}
|
||||
|
||||
public reset(): Resolver {
|
||||
this.history = new Set();
|
||||
return this;
|
||||
}
|
||||
|
||||
public getHistory(): string[] {
|
||||
return Array.from(this.history);
|
||||
}
|
||||
|
@ -61,15 +66,20 @@ export default class Resolver {
|
|||
}
|
||||
|
||||
if (typeof value !== "string") {
|
||||
apLogger.debug("Object to resolve is not a string");
|
||||
if (typeof value.id !== "undefined") {
|
||||
const host = extractDbHost(getApId(value));
|
||||
if (await shouldBlockInstance(host)) {
|
||||
throw new Error("instance is blocked");
|
||||
}
|
||||
}
|
||||
apLogger.debug("Returning existing object:");
|
||||
apLogger.debug(JSON.stringify(value, null, 2));
|
||||
return value;
|
||||
}
|
||||
|
||||
apLogger.debug(`Resolving: ${value}`);
|
||||
|
||||
if (value.includes("#")) {
|
||||
// URLs with fragment parts cannot be resolved correctly because
|
||||
// the fragment part does not get transmitted over HTTP(S).
|
||||
|
@ -107,7 +117,7 @@ export default class Resolver {
|
|||
this.user = await getInstanceActor();
|
||||
}
|
||||
|
||||
apLogger.debug("getting object from remote, authenticated as user:");
|
||||
apLogger.debug("Getting object from remote, authenticated as user:");
|
||||
apLogger.debug(JSON.stringify(this.user, null, 2));
|
||||
|
||||
const object = (
|
||||
|
|
|
@ -145,8 +145,12 @@ async function fetchAny(
|
|||
|
||||
return await mergePack(
|
||||
me,
|
||||
isActor(object) ? await createPerson(getApId(object), resolver) : null,
|
||||
isPost(object) ? await createNote(getApId(object), resolver, true) : null,
|
||||
isActor(object)
|
||||
? await createPerson(getApId(object), resolver.reset())
|
||||
: null,
|
||||
isPost(object)
|
||||
? await createNote(getApId(object), resolver.reset(), true)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue