Enforce URI uniquness
This commit is contained in:
@ -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 {
|
||||
|
@ -11,6 +11,8 @@ import { pack as packFile } from './drive-file';
|
||||
|
||||
const Post = db.get<IPost>('posts');
|
||||
|
||||
Post.createIndex('uri', { sparse: true, unique: true });
|
||||
|
||||
export default Post;
|
||||
|
||||
export function isValidText(text: string): boolean {
|
||||
@ -49,6 +51,7 @@ export type IPost = {
|
||||
heading: number;
|
||||
speed: number;
|
||||
};
|
||||
uri: string;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1,15 +0,0 @@
|
||||
import * as mongodb from 'mongodb';
|
||||
import db from '../db/mongodb';
|
||||
|
||||
const RemoteUserObject = db.get<IRemoteUserObject>('remoteUserObjects');
|
||||
|
||||
export default RemoteUserObject;
|
||||
|
||||
export type IRemoteUserObject = {
|
||||
_id: mongodb.ObjectID;
|
||||
uri: string;
|
||||
object: {
|
||||
$ref: string;
|
||||
$id: mongodb.ObjectID;
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user