Enforce URI uniquness

This commit is contained in:
Akihiko Odaki
2018-04-03 23:45:13 +09:00
parent 18f317a4ac
commit fdc81f395d
6 changed files with 82 additions and 48 deletions

View File

@ -6,6 +6,8 @@ import monkDb, { nativeDbConn } from '../db/mongodb';
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
DriveFile.createIndex('metadata.uri', { sparse: true, unique: true });
export default DriveFile;
const getGridFSBucket = async (): Promise<mongodb.GridFSBucket> => {
@ -18,17 +20,21 @@ const getGridFSBucket = async (): Promise<mongodb.GridFSBucket> => {
export { getGridFSBucket };
export type IMetadata = {
properties: any;
userId: mongodb.ObjectID;
folderId: mongodb.ObjectID;
comment: string;
uri: string;
};
export type IDriveFile = {
_id: mongodb.ObjectID;
uploadDate: Date;
md5: string;
filename: string;
contentType: string;
metadata: {
properties: any;
userId: mongodb.ObjectID;
folderId: mongodb.ObjectID;
}
metadata: IMetadata;
};
export function validateFileName(name: string): boolean {