feat: filter uploads by mime types

This commit is contained in:
Bobby 2022-10-06 03:36:34 +07:00
parent 30db27e524
commit 10c2618ef6
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
2 changed files with 24 additions and 1 deletions

View File

@ -1232,6 +1232,7 @@ self.list = async (req, res) => {
// Columns with which to use SQLite's NULLS LAST option // Columns with which to use SQLite's NULLS LAST option
nullsLast: [ nullsLast: [
'userid', 'userid',
'type',
'albumid', 'albumid',
'expirydate', 'expirydate',
'ip' 'ip'
@ -1266,7 +1267,7 @@ self.list = async (req, res) => {
} }
if (filters) { if (filters) {
const keywords = [] const keywords = ['type']
// Only allow filtering by 'albumid' when not listing a specific album's uploads // Only allow filtering by 'albumid' when not listing a specific album's uploads
if (isNaN(albumid)) { 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 // Then, refine using the supplied keywords against their file names
this.andWhere(function () { this.andWhere(function () {
if (!filterObj.queries.text) return if (!filterObj.queries.text) return

View File

@ -1191,6 +1191,10 @@ page.uploadFiltersHelp = element => {
Negation sign works for this key as well. Negation sign works for this key as well.
Mixing inclusion and exclusion is not allowed (i.e. <code>is:image -is:video</code>), since the second key will be redundant. Mixing inclusion and exclusion is not allowed (i.e. <code>is:image -is:video</code>), since the second key will be redundant.
Alternatively, you can filter by their actual mime types using <b>type</b> keys.
For example, <code>type:image/jpeg</code>, <code>type:video/mp4</code>.
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. 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. Excluding certain keywords is also supported by adding negation sign before the keywords.
@ -1201,6 +1205,7 @@ page.uploadFiltersHelp = element => {
: '- Filter uploads'} using <b>date</b> key, if any. : '- Filter uploads'} using <b>date</b> key, if any.
- Refine matches using <b>expiry</b> key, if any. - Refine matches using <b>expiry</b> key, if any.
- Refine matches using type-<b>is</b> keys, if any. - Refine matches using type-<b>is</b> keys, if any.
- Refine matches using <b>type</b> keys, if any.
- Refine matches using ANY non-keyed keywords, if any. - Refine matches using ANY non-keyed keywords, if any.
- Filter matches using ALL exclusion non-keyed keywords, if any. - Filter matches using ALL exclusion non-keyed keywords, if any.
- Sort matches using <b>sort</b> keys, if any. - Sort matches using <b>sort</b> keys, if any.