mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 16:25:13 +00:00
AP Delate Activityの修正 (#6512)
This commit is contained in:
parent
6eff6ee451
commit
5f8fb43cc9
2 changed files with 42 additions and 12 deletions
|
@ -1,26 +1,48 @@
|
||||||
import Resolver from '../../resolver';
|
|
||||||
import deleteNote from './note';
|
import deleteNote from './note';
|
||||||
import { IRemoteUser } from '../../../../models/entities/user';
|
import { IRemoteUser } from '../../../../models/entities/user';
|
||||||
import { IDelete, getApId, validPost } from '../../type';
|
import { IDelete, getApId, isTombstone, IObject, validPost, validActor } from '../../type';
|
||||||
import { apLogger } from '../../logger';
|
import { toSingle } from '../../../../prelude/array';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 削除アクティビティを捌きます
|
* 削除アクティビティを捌きます
|
||||||
*/
|
*/
|
||||||
export default async (actor: IRemoteUser, activity: IDelete): Promise<void> => {
|
export default async (actor: IRemoteUser, activity: IDelete): Promise<string> => {
|
||||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||||
throw new Error('invalid actor');
|
throw new Error('invalid actor');
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolver = new Resolver();
|
// 削除対象objectのtype
|
||||||
|
let formarType: string | undefined;
|
||||||
|
|
||||||
const object = await resolver.resolve(activity.object);
|
if (typeof activity.object === 'string') {
|
||||||
|
// typeが不明だけど、どうせ消えてるのでremote resolveしない
|
||||||
const uri = getApId(object);
|
formarType = undefined;
|
||||||
|
|
||||||
if (validPost.includes(object.type) || object.type === 'Tombstone') {
|
|
||||||
deleteNote(actor, uri);
|
|
||||||
} else {
|
} else {
|
||||||
apLogger.warn(`Unknown type: ${object.type}`);
|
const object = activity.object as IObject;
|
||||||
|
if (isTombstone(object)) {
|
||||||
|
formarType = toSingle(object.formerType);
|
||||||
|
} else {
|
||||||
|
formarType = toSingle(object.type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const uri = getApId(activity.object);
|
||||||
|
|
||||||
|
// type不明でもactorとobjectが同じならばそれはPersonに違いない
|
||||||
|
if (!formarType && actor.uri === uri) {
|
||||||
|
formarType = 'Person';
|
||||||
|
}
|
||||||
|
|
||||||
|
// それでもなかったらおそらくNote
|
||||||
|
if (!formarType) {
|
||||||
|
formarType = 'Note';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validPost.includes(formarType)) {
|
||||||
|
return await deleteNote(actor, uri);
|
||||||
|
} else if (validActor.includes(formarType)) {
|
||||||
|
return `Delete Actor is not implanted`;
|
||||||
|
} else {
|
||||||
|
return `Unknown type ${formarType}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -119,6 +119,14 @@ interface IQuestionChoice {
|
||||||
replies?: ICollection;
|
replies?: ICollection;
|
||||||
_misskey_votes?: number;
|
_misskey_votes?: number;
|
||||||
}
|
}
|
||||||
|
export interface ITombstone extends IObject {
|
||||||
|
type: 'Tombstone';
|
||||||
|
formerType?: string;
|
||||||
|
deleted?: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isTombstone = (object: IObject): object is ITombstone =>
|
||||||
|
object.type === 'Tombstone';
|
||||||
|
|
||||||
export const validActor = ['Person', 'Service', 'Group', 'Organization', 'Application'];
|
export const validActor = ['Person', 'Service', 'Group', 'Organization', 'Application'];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue