From bcb04924ff08cc90d046ec7064fa0b89cbf9219e Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Mon, 26 Nov 2018 04:25:48 +0900 Subject: Image for web publish (#3402) * Image for Web * Add comment * Make main to original --- src/models/drive-file-webpublic.ts | 29 +++++++++++++++++ src/models/drive-file.ts | 67 ++++++++++++++++++++++++++++++++++---- 2 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 src/models/drive-file-webpublic.ts (limited to 'src/models') diff --git a/src/models/drive-file-webpublic.ts b/src/models/drive-file-webpublic.ts new file mode 100644 index 0000000000..d087c355d3 --- /dev/null +++ b/src/models/drive-file-webpublic.ts @@ -0,0 +1,29 @@ +import * as mongo from 'mongodb'; +import monkDb, { nativeDbConn } from '../db/mongodb'; + +const DriveFileWebpublic = monkDb.get('driveFileWebpublics.files'); +DriveFileWebpublic.createIndex('metadata.originalId', { sparse: true, unique: true }); +export default DriveFileWebpublic; + +export const DriveFileWebpublicChunk = monkDb.get('driveFileWebpublics.chunks'); + +export const getDriveFileWebpublicBucket = async (): Promise => { + const db = await nativeDbConn(); + const bucket = new mongo.GridFSBucket(db, { + bucketName: 'driveFileWebpublics' + }); + return bucket; +}; + +export type IMetadata = { + originalId: mongo.ObjectID; +}; + +export type IDriveFileWebpublic = { + _id: mongo.ObjectID; + uploadDate: Date; + md5: string; + filename: string; + contentType: string; + metadata: IMetadata; +}; diff --git a/src/models/drive-file.ts b/src/models/drive-file.ts index d0c0905fc2..e4c1598049 100644 --- a/src/models/drive-file.ts +++ b/src/models/drive-file.ts @@ -3,7 +3,7 @@ const deepcopy = require('deepcopy'); import { pack as packFolder } from './drive-folder'; import monkDb, { nativeDbConn } from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; -import getDriveFileUrl from '../misc/get-drive-file-url'; +import getDriveFileUrl, { getOriginalUrl } from '../misc/get-drive-file-url'; const DriveFile = monkDb.get('driveFiles.files'); DriveFile.createIndex('md5'); @@ -28,21 +28,48 @@ export type IMetadata = { _user: any; folderId: mongo.ObjectID; comment: string; + + /** + * リモートインスタンスから取得した場合の元URL + */ uri?: string; + + /** + * URL for web(生成されている場合) or original + * * オブジェクトストレージを利用している or リモートサーバーへの直リンクである 場合のみ + */ url?: string; + + /** + * URL for thumbnail (thumbnailがなければなし) + * * オブジェクトストレージを利用している or リモートサーバーへの直リンクである 場合のみ + */ thumbnailUrl?: string; + + /** + * URL for original (web用が生成されてない場合はurlがoriginalを指す) + * * オブジェクトストレージを利用している or リモートサーバーへの直リンクである 場合のみ + */ + webpublicUrl?: string; + + accessKey?: string; + src?: string; deletedAt?: Date; /** - * このファイルの中身データがMongoDB内に保存されているのか否か + * このファイルの中身データがMongoDB内に保存されていないか否か * オブジェクトストレージを利用している or リモートサーバーへの直リンクである - * な場合は false になります + * な場合は true になります */ withoutChunks?: boolean; storage?: string; - storageProps?: any; + + /*** + * ObjectStorage の格納先の情報 + */ + storageProps?: IStorageProps; isSensitive?: boolean; /** @@ -56,6 +83,25 @@ export type IMetadata = { isRemote?: boolean; }; +export type IStorageProps = { + /** + * ObjectStorage key for original + */ + key: string; + + /*** + * ObjectStorage key for thumbnail (thumbnailがなければなし) + */ + thumbnailKey?: string; + + /*** + * ObjectStorage key for webpublic (webpublicがなければなし) + */ + webpublicKey?: string; + + id?: string; +}; + export type IDriveFile = { _id: mongo.ObjectID; uploadDate: Date; @@ -83,7 +129,8 @@ export function validateFileName(name: string): boolean { export const packMany = ( files: any[], options?: { - detail: boolean + detail?: boolean + self?: boolean, } ) => { return Promise.all(files.map(f => pack(f, options))); @@ -95,11 +142,13 @@ export const packMany = ( export const pack = ( file: any, options?: { - detail: boolean + detail?: boolean, + self?: boolean, } ) => new Promise(async (resolve, reject) => { const opts = Object.assign({ - detail: false + detail: false, + self: false }, options); let _file: any; @@ -165,5 +214,9 @@ export const pack = ( delete _target.isRemote; delete _target._user; + if (opts.self) { + _target.url = getOriginalUrl(_file); + } + resolve(_target); }); -- cgit v1.2.3-freya