rudeshark.net/src/remote/activitypub/kernel/create/index.ts

40 lines
816 B
TypeScript
Raw Normal View History

2018-04-06 12:35:23 +02:00
import Resolver from '../../resolver';
import { IRemoteUser } from '../../../../models/user';
import createNote from './note';
import createImage from './image';
2018-04-07 09:14:35 +02:00
import { ICreate } from '../../type';
import { apLogger } from '../../logger';
2018-04-06 12:35:23 +02:00
const logger = apLogger;
2018-04-06 12:35:23 +02:00
2018-04-07 09:14:35 +02:00
export default async (actor: IRemoteUser, activity: ICreate): Promise<void> => {
2018-04-06 12:35:23 +02:00
const uri = activity.id || activity;
logger.info(`Create: ${uri}`);
2018-04-06 12:35:23 +02:00
const resolver = new Resolver();
let object;
try {
object = await resolver.resolve(activity.object);
} catch (e) {
logger.error(`Resolution failed: ${e}`);
2018-04-06 12:35:23 +02:00
throw e;
}
switch (object.type) {
case 'Image':
2018-04-07 09:14:35 +02:00
createImage(actor, object);
2018-04-06 12:35:23 +02:00
break;
case 'Note':
createNote(resolver, actor, object);
break;
default:
logger.warn(`Unknown type: ${object.type}`);
2018-04-06 12:35:23 +02:00
break;
}
};