From aa7d2453171b3a596a1be6676eaf39cc93fe178f Mon Sep 17 00:00:00 2001 From: Pitu Date: Sun, 27 Dec 2020 04:48:03 +0900 Subject: feat: Add hash checking for chunked uploads --- src/api/utils/Util.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/api/utils') diff --git a/src/api/utils/Util.js b/src/api/utils/Util.js index 905f217..e52fac2 100644 --- a/src/api/utils/Util.js +++ b/src/api/utils/Util.js @@ -108,6 +108,17 @@ class Util { return hash; } + static async checkIfFileExists(db, user, hash) { + const exists = await db.table('files') + .where(function() { // eslint-disable-line func-names + if (user) this.where('userId', user.id); + else this.whereNull('userId'); + }) + .where({ hash }) + .first(); + return exists; + } + static getFilenameFromPath(fullPath) { return fullPath.replace(/^.*[\\\/]/, ''); // eslint-disable-line no-useless-escape } -- cgit v1.2.3