1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-27 21:18:27 +09:00
misskey/src/remote/activitypub/models/image.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

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