monkeeShark/src/remote/activitypub/models/image.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-04-08 19:08:56 +00:00
import * as debug from 'debug';
import uploadFromUrl from '../../../services/drive/upload-from-url';
import { IRemoteUser } from '../../../models/user';
import { IDriveFile } from '../../../models/drive-file';
2018-04-08 20:14:47 +00:00
import Resolver from '../resolver';
2018-04-08 19:08:56 +00:00
const log = debug('misskey:activitypub');
/**
* Imageを作成します
*/
2018-04-08 20:14:47 +00:00
export async function createImage(actor: IRemoteUser, value): Promise<IDriveFile> {
2018-04-19 09:54:34 +00:00
// 投稿者が凍結されていたらスキップ
if (actor.isSuspended) {
return null;
}
2018-04-08 20:14:47 +00:00
const image = await new Resolver().resolve(value);
if (image.url == null) {
throw new Error('invalid image: url not privided');
}
2018-04-08 19:08:56 +00:00
log(`Creating the Image: ${image.url}`);
return await uploadFromUrl(image.url, actor);
}
/**
* Imageを解決します
*
* Misskeyに対象のImageが登録されていればそれを返し
* Misskeyに登録しそれを返します
*/
export async function resolveImage(actor: IRemoteUser, value: any): Promise<IDriveFile> {
// TODO
// リモートサーバーからフェッチしてきて登録
return await createImage(actor, value);
}