Image for web publish (#3402)

* Image for Web

* Add comment

* Make main to original
This commit is contained in:
MeiMei
2018-11-26 04:25:48 +09:00
committed by syuilo
parent 0863e5d379
commit bcb04924ff
14 changed files with 283 additions and 43 deletions

View File

@ -0,0 +1,29 @@
import * as mongo from 'mongodb';
import monkDb, { nativeDbConn } from '../db/mongodb';
const DriveFileWebpublic = monkDb.get<IDriveFileWebpublic>('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<mongo.GridFSBucket> => {
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;
};

View File

@ -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<IDriveFile>('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<any>(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);
});