yumechi-no-kuni/src/remote/activitypub/models/image.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

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