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
|
* @param url URL to fetch
|
||||||
*/
|
*/
|
||||||
export async function signedGet(url: string, user: { id: User["id"] }) {
|
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 keypair = await getUserKeypair(user.id);
|
||||||
|
|
||||||
const req = createSignedGet({
|
const req = createSignedGet({
|
||||||
|
|
|
@ -39,6 +39,11 @@ export default class Resolver {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public reset(): Resolver {
|
||||||
|
this.history = new Set();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public getHistory(): string[] {
|
public getHistory(): string[] {
|
||||||
return Array.from(this.history);
|
return Array.from(this.history);
|
||||||
}
|
}
|
||||||
|
@ -61,15 +66,20 @@ export default class Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value !== "string") {
|
if (typeof value !== "string") {
|
||||||
|
apLogger.debug("Object to resolve is not a string");
|
||||||
if (typeof value.id !== "undefined") {
|
if (typeof value.id !== "undefined") {
|
||||||
const host = extractDbHost(getApId(value));
|
const host = extractDbHost(getApId(value));
|
||||||
if (await shouldBlockInstance(host)) {
|
if (await shouldBlockInstance(host)) {
|
||||||
throw new Error("instance is blocked");
|
throw new Error("instance is blocked");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
apLogger.debug("Returning existing object:");
|
||||||
|
apLogger.debug(JSON.stringify(value, null, 2));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apLogger.debug(`Resolving: ${value}`);
|
||||||
|
|
||||||
if (value.includes("#")) {
|
if (value.includes("#")) {
|
||||||
// URLs with fragment parts cannot be resolved correctly because
|
// URLs with fragment parts cannot be resolved correctly because
|
||||||
// the fragment part does not get transmitted over HTTP(S).
|
// the fragment part does not get transmitted over HTTP(S).
|
||||||
|
@ -107,7 +117,7 @@ export default class Resolver {
|
||||||
this.user = await getInstanceActor();
|
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));
|
apLogger.debug(JSON.stringify(this.user, null, 2));
|
||||||
|
|
||||||
const object = (
|
const object = (
|
||||||
|
|
|
@ -145,8 +145,12 @@ async function fetchAny(
|
||||||
|
|
||||||
return await mergePack(
|
return await mergePack(
|
||||||
me,
|
me,
|
||||||
isActor(object) ? await createPerson(getApId(object), resolver) : null,
|
isActor(object)
|
||||||
isPost(object) ? await createNote(getApId(object), resolver, true) : null,
|
? await createPerson(getApId(object), resolver.reset())
|
||||||
|
: null,
|
||||||
|
isPost(object)
|
||||||
|
? await createNote(getApId(object), resolver.reset(), true)
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue