nullobsi ffb9646ce9
Add image description support (#7518)
* recieve image descriptions under the name property

* fix other components

* use comment for alt and title

* allow editing of file comment

* allow editing of file comment in note dialog

* federate note comments

* use file instead of this

* backend should accept comment on update

* update now actually accepts comment

* allow multiline descriptions

* image should also have description attached

* Update locales/ja-JP.yml

Co-authored-by: rinsuki <428rinsuki+git@gmail.com>

* Use custom component with side-by-side image

* improve usability on mobile devices

* revert changes

* Update post-form-attaches.vue

* Update drive.file.vue

* Update media-caption.vue

Co-authored-by: rinsuki <428rinsuki+git@gmail.com>
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2021-05-28 09:38:09 +09:00

61 lines
1.8 KiB
TypeScript

import uploadFromUrl from '../../../services/drive/upload-from-url';
import { IRemoteUser } from '../../../models/entities/user';
import Resolver from '../resolver';
import { fetchMeta } from '@/misc/fetch-meta';
import { apLogger } from '../logger';
import { DriveFile } from '../../../models/entities/drive-file';
import { DriveFiles } from '../../../models';
const logger = apLogger;
/**
* Imageを作成します。
*/
export async function createImage(actor: IRemoteUser, value: any): Promise<DriveFile> {
// 投稿者が凍結されていたらスキップ
if (actor.isSuspended) {
throw new Error('actor has been suspended');
}
const image = await new Resolver().resolve(value) as any;
if (image.url == null) {
throw new Error('invalid image: url not privided');
}
logger.info(`Creating the Image: ${image.url}`);
const instance = await fetchMeta();
const cache = instance.cacheRemoteFiles;
let file = await uploadFromUrl(image.url, actor, null, image.url, image.sensitive, false, !cache, image.name);
if (file.isLink) {
// URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、
// URLを更新する
if (file.url !== image.url) {
await DriveFiles.update({ id: file.id }, {
url: image.url,
uri: image.url
});
file = await DriveFiles.findOneOrFail(file.id);
}
}
return file;
}
/**
* Imageを解決します。
*
* Misskeyに対象のImageが登録されていればそれを返し、そうでなければ
* リモートサーバーからフェッチしてMisskeyに登録しそれを返します。
*/
export async function resolveImage(actor: IRemoteUser, value: any): Promise<DriveFile> {
// TODO
// リモートサーバーからフェッチしてきて登録
return await createImage(actor, value);
}