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

42 lines
1.2 KiB
TypeScript
Raw Normal View History

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