-
Notifications
You must be signed in to change notification settings - Fork 32
/
utils.ts
26 lines (22 loc) · 809 Bytes
/
utils.ts
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
import * as del from 'del';
import { Collection } from 'lokijs';
const imageFilter = function (req, file, cb) {
// accept image only
if (!file.originalname.match(/\.(jpg|jpeg|png|gif)$/)) {
return cb(new Error('Only image files are allowed!'), false);
}
cb(null, true);
};
const loadCollection = function (colName, db: Loki): Promise<Collection<any>> {
return new Promise(resolve => {
db.loadDatabase({}, () => {
const _collection = db.getCollection(colName) || db.addCollection(colName);
resolve(_collection);
})
});
}
const cleanFolder = function (folderPath) {
// delete files inside folder but not the folder itself
del.sync([`${folderPath}/**`, `!${folderPath}`]);
};
export { imageFilter, loadCollection, cleanFolder }