diff options
| author | Pitu <[email protected]> | 2019-02-28 23:51:59 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2019-02-28 23:51:59 +0900 |
| commit | 9f5a3d15f55fea03052627f3bd4d97a4284cdf7c (patch) | |
| tree | 7062ca416d14d0d6863ed0acdc76ce65ece768bb /src/api/utils/Util.js | |
| parent | Some stuff (diff) | |
| download | host.fuwn.me-9f5a3d15f55fea03052627f3bd4d97a4284cdf7c.tar.xz host.fuwn.me-9f5a3d15f55fea03052627f3bd4d97a4284cdf7c.zip | |
Purge user's files
Diffstat (limited to 'src/api/utils/Util.js')
| -rw-r--r-- | src/api/utils/Util.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/api/utils/Util.js b/src/api/utils/Util.js index 26edf4b..9e9753c 100644 --- a/src/api/utils/Util.js +++ b/src/api/utils/Util.js @@ -90,6 +90,10 @@ class Util { } static constructFilePublicLink(file) { + /* + TODO: This wont work without a reverse proxy serving both + the site and the API under the same domain. Pls fix. + */ file.url = `${process.env.DOMAIN}/${file.name}`; const thumb = this.getFileThumbnail(file.name); if (thumb) { @@ -175,6 +179,18 @@ class Util { } } + static async deleteAllFilesFromUser(id) { + try { + const files = await db.table('files').where({ userId: id }); + for (const file of files) { + await jetpack.removeAsync(path.join(__dirname, '..', '..', '..', process.env.UPLOAD_FOLDER, file)); + } + await db.table('files').where({ userId: id }).delete(); + } catch (error) { + log.error(error); + } + } + static isAuthorized(req) { if (!req.headers.authorization) return false; const token = req.headers.authorization.split(' ')[1]; |