blob: 46de24379f0c28bf7050b99029d446461aa7b0e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
import * as mongo from 'mongodb';
import monkDb, { nativeDbConn } from '../db/mongodb';
const DriveFileThumbnail = monkDb.get<IDriveFileThumbnail>('driveFileThumbnails.files');
DriveFileThumbnail.createIndex('metadata.originalId', { sparse: true, unique: true });
export default DriveFileThumbnail;
export const DriveFileThumbnailChunk = monkDb.get('driveFileThumbnails.chunks');
export const getDriveFileThumbnailBucket = async (): Promise<mongo.GridFSBucket> => {
const db = await nativeDbConn();
const bucket = new mongo.GridFSBucket(db, {
bucketName: 'driveFileThumbnails'
});
return bucket;
};
export type IMetadata = {
originalId: mongo.ObjectID;
};
export type IDriveFileThumbnail = {
_id: mongo.ObjectID;
uploadDate: Date;
md5: string;
filename: string;
contentType: string;
metadata: IMetadata;
};
/**
* DriveFileThumbnailを物理削除します
*/
export async function deleteDriveFileThumbnail(driveFile: string | mongo.ObjectID | IDriveFileThumbnail) {
let d: IDriveFileThumbnail;
// Populate
if (mongo.ObjectID.prototype.isPrototypeOf(driveFile)) {
d = await DriveFileThumbnail.findOne({
_id: driveFile
});
} else if (typeof driveFile === 'string') {
d = await DriveFileThumbnail.findOne({
_id: new mongo.ObjectID(driveFile)
});
} else {
d = driveFile as IDriveFileThumbnail;
}
if (d == null) return;
// このDriveFileThumbnailのチャンクをすべて削除
await DriveFileThumbnailChunk.remove({
files_id: d._id
});
// このDriveFileThumbnailを削除
await DriveFileThumbnail.remove({
_id: d._id
});
}
|