diff options
| author | Pitu <[email protected]> | 2019-03-14 23:13:51 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2019-03-14 23:13:51 +0900 |
| commit | af9d752eaf80a7ee2eef6ab3fafd97e4004572ed (patch) | |
| tree | 5869ff3dece158409953980f200b79b13f7716ab /src/api/utils/Util.js | |
| parent | What are strings even (diff) | |
| download | host.fuwn.me-af9d752eaf80a7ee2eef6ab3fafd97e4004572ed.tar.xz host.fuwn.me-af9d752eaf80a7ee2eef6ab3fafd97e4004572ed.zip | |
Add uuid package
Diffstat (limited to 'src/api/utils/Util.js')
| -rw-r--r-- | src/api/utils/Util.js | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/api/utils/Util.js b/src/api/utils/Util.js index a8e1754..1776f3e 100644 --- a/src/api/utils/Util.js +++ b/src/api/utils/Util.js @@ -19,12 +19,17 @@ const crypto = require('crypto'); const sharp = require('sharp'); const ffmpeg = require('fluent-ffmpeg'); const Zip = require('adm-zip'); +const uuidv4 = require('uuid/v4'); const imageExtensions = ['.jpg', '.jpeg', '.bmp', '.gif', '.png', '.webp']; const videoExtensions = ['.webm', '.mp4', '.wmv', '.avi', '.mov']; const blockedExtensions = process.env.BLOCKED_EXTENSIONS.split(','); class Util { + static uuid() { + return uuidv4(); + } + static isExtensionBlocked(extension) { return blockedExtensions.includes(extension); } @@ -171,9 +176,13 @@ class Util { static async deleteAllFilesFromAlbum(id) { try { - const files = await db.table('files').where({ albumId: id }); - for (const file of files) { - await this.deleteFile(file.name, true) + const fileAlbums = await db.table('albumsFiles').where({ albumId: id }); + for (const fileAlbum of fileAlbums) { + const file = await db.table('files') + .where({ id: fileAlbum.fileId }) + .first(); + if (!file) continue; + await this.deleteFile(file.name, true); } } catch (error) { log.error(error); @@ -184,7 +193,22 @@ class Util { try { const files = await db.table('files').where({ userId: id }); for (const file of files) { - await this.deleteFile(file.name, true) + await this.deleteFile(file.name, true); + } + } catch (error) { + log.error(error); + } + } + + static async deleteAllFilesFromTag(id) { + try { + const fileTags = await db.table('fileTags').where({ tagId: id }); + for (const fileTag of fileTags) { + const file = await db.table('files') + .where({ id: fileTag.fileId }) + .first(); + if (!file) continue; + await this.deleteFile(file.name, true); } } catch (error) { log.error(error); |