From 10c2618ef6bf928710984272db25f1cc51f20d10 Mon Sep 17 00:00:00 2001 From: Bobby Date: Thu, 6 Oct 2022 03:36:34 +0700 Subject: [PATCH] feat: filter uploads by mime types --- controllers/uploadController.js | 20 +++++++++++++++++++- src/js/dashboard.js | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 0b97ab0..8a1f16d 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -1232,6 +1232,7 @@ self.list = async (req, res) => { // Columns with which to use SQLite's NULLS LAST option nullsLast: [ 'userid', + 'type', 'albumid', 'expirydate', 'ip' @@ -1266,7 +1267,7 @@ self.list = async (req, res) => { } if (filters) { - const keywords = [] + const keywords = ['type'] // Only allow filtering by 'albumid' when not listing a specific album's uploads if (isNaN(albumid)) { @@ -1708,6 +1709,23 @@ self.list = async (req, res) => { } }) + // Then, refine using 'type' keys + this.andWhere(function () { + if (filterObj.queries.exclude.type) { + this.whereNotIn('type', filterObj.queries.exclude.type) + } else if (filterObj.queries.type) { + this.orWhereIn('type', filterObj.queries.type) + } + // ... + if ((filterObj.queries.exclude.type && filterObj.flags.typeNull !== false) || + (filterObj.queries.type && filterObj.flags.typeNull) || + (!filterObj.queries.exclude.type && !filterObj.queries.type && filterObj.flags.typeNull)) { + this.orWhereNull('type') + } else if (filterObj.flags.typeNull === false) { + this.whereNotNull('type') + } + }) + // Then, refine using the supplied keywords against their file names this.andWhere(function () { if (!filterObj.queries.text) return diff --git a/src/js/dashboard.js b/src/js/dashboard.js index 1c85560..9cee991 100644 --- a/src/js/dashboard.js +++ b/src/js/dashboard.js @@ -1191,6 +1191,10 @@ page.uploadFiltersHelp = element => { Negation sign works for this key as well. Mixing inclusion and exclusion is not allowed (i.e. is:image -is:video), since the second key will be redundant. + Alternatively, you can filter by their actual mime types using type keys. + For example, type:image/jpeg, type:video/mp4. + Negation sign works for this key as well. + Any leftover keywords which do not use keys (non-keyed keywords) will be matched against the matches' randomly generated and original names. Excluding certain keywords is also supported by adding negation sign before the keywords. @@ -1201,6 +1205,7 @@ page.uploadFiltersHelp = element => { : '- Filter uploads'} using date key, if any. - Refine matches using expiry key, if any. - Refine matches using type-is keys, if any. + - Refine matches using type keys, if any. - Refine matches using ANY non-keyed keywords, if any. - Filter matches using ALL exclusion non-keyed keywords, if any. - Sort matches using sort keys, if any.