mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-25 10:19:06 +01:00
[backend] Fix resolver cannot parse some follows and notes request
This commit is contained in:
parent
e9ef70e272
commit
3824767cc9
1 changed files with 29 additions and 9 deletions
|
@ -24,6 +24,7 @@ import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||||
import renderFollow from "@/remote/activitypub/renderer/follow.js";
|
import renderFollow from "@/remote/activitypub/renderer/follow.js";
|
||||||
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
|
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
|
||||||
import { apLogger } from "@/remote/activitypub/logger.js";
|
import { apLogger } from "@/remote/activitypub/logger.js";
|
||||||
|
import { In, IsNull, Not } from "typeorm";
|
||||||
|
|
||||||
export default class Resolver {
|
export default class Resolver {
|
||||||
private history: Set<string>;
|
private history: Set<string>;
|
||||||
|
@ -154,7 +155,7 @@ export default class Resolver {
|
||||||
return Notes.findOneByOrFail({ id: parsed.id }).then((note) => {
|
return Notes.findOneByOrFail({ id: parsed.id }).then((note) => {
|
||||||
if (parsed.rest === "activity") {
|
if (parsed.rest === "activity") {
|
||||||
// this refers to the create activity and not the note itself
|
// this refers to the create activity and not the note itself
|
||||||
return renderActivity(renderCreate(renderNote(note)));
|
return renderActivity(renderCreate(renderNote(note), note));
|
||||||
} else {
|
} else {
|
||||||
return renderNote(note);
|
return renderNote(note);
|
||||||
}
|
}
|
||||||
|
@ -176,15 +177,34 @@ export default class Resolver {
|
||||||
(reaction) => renderActivity(renderLike(reaction, { uri: null })),
|
(reaction) => renderActivity(renderLike(reaction, { uri: null })),
|
||||||
);
|
);
|
||||||
case "follows":
|
case "follows":
|
||||||
// rest should be <followee id>
|
// if rest is a <followee id>
|
||||||
if (parsed.rest == null || !/^\w+$/.test(parsed.rest))
|
if (parsed.rest != null && /^\w+$/.test(parsed.rest)) {
|
||||||
throw new Error("resolveLocal: invalid follow URI");
|
|
||||||
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
[parsed.id, parsed.rest].map((id) => Users.findOneByOrFail({ id })),
|
[parsed.id, parsed.rest].map((id) => Users.findOneByOrFail({ id })),
|
||||||
).then(([follower, followee]) =>
|
).then(([follower, followee]) =>
|
||||||
renderActivity(renderFollow(follower, followee, url)),
|
renderActivity(renderFollow(follower, followee, url)),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Another situation is there is only requestId, then obtained object from database.
|
||||||
|
const followRequest = FollowRequests.findOneBy({
|
||||||
|
id: parsed.id,
|
||||||
|
});
|
||||||
|
if (followRequest == null) {
|
||||||
|
throw new Error("resolveLocal: invalid follow URI");
|
||||||
|
}
|
||||||
|
const follower = Users.findOneBy({
|
||||||
|
id: followRequest.followerId,
|
||||||
|
host: IsNull(),
|
||||||
|
});
|
||||||
|
const followee = Users.findOneBy({
|
||||||
|
id: followRequest.followeeId,
|
||||||
|
host: Not(IsNull()),
|
||||||
|
});
|
||||||
|
if (follower == null || followee == null) {
|
||||||
|
throw new Error("resolveLocal: invalid follow URI");
|
||||||
|
}
|
||||||
|
return renderActivity(renderFollow(follower, followee, url));
|
||||||
default:
|
default:
|
||||||
throw new Error(`resolveLocal: type ${type} unhandled`);
|
throw new Error(`resolveLocal: type ${type} unhandled`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue