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> {
|
|
|
|
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);
|
|
|
|
}
|