forked from FoundKeyGang/FoundKey
server: implement moveTo property on actors
Co-authored-by: Mary Strodl <ipadlover8322@gmail.com>
This commit is contained in:
parent
d7db1bc34e
commit
07488d6a32
1 changed files with 24 additions and 3 deletions
|
@ -42,7 +42,7 @@ const summaryLength = 2048;
|
|||
* @param x Fetched object
|
||||
* @param uri Fetch target URI
|
||||
*/
|
||||
function validateActor(x: IObject, uri: string): IActor {
|
||||
async function validateActor(x: IObject, uri: string, resolver?: Resolver): IActor {
|
||||
const expectHost = toPuny(new URL(uri).hostname);
|
||||
|
||||
if (x == null) {
|
||||
|
@ -57,6 +57,25 @@ function validateActor(x: IObject, uri: string): IActor {
|
|||
throw new Error('invalid Actor: wrong id');
|
||||
}
|
||||
|
||||
if (x.movedTo !== undefined) {
|
||||
if (!(typeof x.movedTo === 'string' && x.movedTo.length > 0)) {
|
||||
throw new Error('invalid Actor: wrong movedTo');
|
||||
}
|
||||
if (x.movedTo === uri) {
|
||||
throw new Error('invalid Actor: moved to self');
|
||||
}
|
||||
await resolvePerson(x.movedTo, resolver)
|
||||
.then(moveTarget => {
|
||||
x.movedTo = moveTarget.id
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
// Can't find the move target for some reason.
|
||||
// Don't treat the actor as invalid, just ignore the movedTo.
|
||||
logger.warn(`cannot find move target "${x.movedTo}", error: ${err.toString()}`);
|
||||
delete x.movedTo;
|
||||
});
|
||||
}
|
||||
|
||||
if (!(typeof x.inbox === 'string' && x.inbox.length > 0)) {
|
||||
throw new Error('invalid Actor: wrong inbox');
|
||||
}
|
||||
|
@ -143,7 +162,7 @@ export async function createPerson(uri: string, resolver?: Resolver = new Resolv
|
|||
|
||||
const object = hint ?? await resolver.resolve(uri) as any;
|
||||
|
||||
const person = validateActor(object, uri);
|
||||
const person = await validateActor(object, uri, resolver);
|
||||
|
||||
logger.info(`Creating the Person: ${person.id}`);
|
||||
|
||||
|
@ -183,6 +202,7 @@ export async function createPerson(uri: string, resolver?: Resolver = new Resolv
|
|||
isBot,
|
||||
isCat: (person as any).isCat === true,
|
||||
showTimelineReplies: false,
|
||||
movedToId: person.movedTo,
|
||||
})) as IRemoteUser;
|
||||
|
||||
await transactionalEntityManager.save(new UserProfile({
|
||||
|
@ -299,7 +319,7 @@ export async function updatePerson(uri: string, resolver?: Resolver = new Resolv
|
|||
|
||||
const object = hint || await resolver.resolve(uri);
|
||||
|
||||
const person = validateActor(object, uri);
|
||||
const person = await validateActor(object, uri, resolver);
|
||||
|
||||
logger.info(`Updating the Person: ${person.id}`);
|
||||
|
||||
|
@ -340,6 +360,7 @@ export async function updatePerson(uri: string, resolver?: Resolver = new Resolv
|
|||
isCat: (person as any).isCat === true,
|
||||
isLocked: !!person.manuallyApprovesFollowers,
|
||||
isExplorable: !!person.discoverable,
|
||||
movedToId: person.movedTo,
|
||||
} as Partial<User>;
|
||||
|
||||
if (avatar) {
|
||||
|
|
Loading…
Reference in a new issue