2018-04-06 12:35:23 +02:00
|
|
|
import Resolver from '../../resolver';
|
2019-04-07 14:50:36 +02:00
|
|
|
import { IRemoteUser } from '../../../../models/entities/user';
|
2018-04-06 12:35:23 +02:00
|
|
|
import createImage from './image';
|
2019-03-06 14:55:47 +01:00
|
|
|
import createNote from './note';
|
2018-04-07 09:14:35 +02:00
|
|
|
import { ICreate } from '../../type';
|
2019-02-03 10:16:57 +01:00
|
|
|
import { apLogger } from '../../logger';
|
2018-04-06 12:35:23 +02:00
|
|
|
|
2019-02-03 10:16:57 +01: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;
|
|
|
|
|
2019-02-03 10:16:57 +01:00
|
|
|
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) {
|
2019-02-03 10:16:57 +01:00
|
|
|
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':
|
2019-03-06 14:55:47 +01:00
|
|
|
case 'Question':
|
2019-03-14 16:23:24 +01:00
|
|
|
case 'Article':
|
2019-03-06 14:55:47 +01:00
|
|
|
createNote(resolver, actor, object);
|
|
|
|
break;
|
|
|
|
|
2018-04-06 12:35:23 +02:00
|
|
|
default:
|
2019-02-03 10:16:57 +01:00
|
|
|
logger.warn(`Unknown type: ${object.type}`);
|
2018-04-06 12:35:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|