Skip to content

Commit

Permalink
- Helpers: updated helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
regorxxx committed Jan 28, 2024
1 parent dade245 commit 68bf6bf
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions helpers/helpers_xxx_tags.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
//24/01/24
//28/01/24

/* exported dynamicTags, numericTags, cyclicTags, keyTags, sanitizeTagIds, sanitizeTagValIds, queryCombinations, queryReplaceWithCurrent, checkQuery, getHandleTags, getHandleListTags ,getHandleListTagsV2, getHandleListTagsTyped, cyclicTagsDescriptor, isQuery */

Expand Down Expand Up @@ -127,8 +127,8 @@ function sanitizeTagValIds(val, bSpace = true) {
* @param {{ bToLowerCase: boolean bDebug: boolean }} options - bToLowerCase: value from #strTF# will use lowercase
* @returns {?string}
*/
function queryReplaceWithCurrent(query, handle, tags = {}, options = {bToLowerCase: false, bDebug: false}) {
options = {bToLowerCase: false, bDebug: false, ...options};
function queryReplaceWithCurrent(query, handle, tags = {}, options = { bToLowerCase: false, bDebug: false }) {
options = { bToLowerCase: false, bDebug: false, ...options };
if (options.bDebug) { console.log('Initial query:', query); }
if (!query.length) { console.log('queryReplaceWithCurrent(): query is empty'); return ''; }
// global queries without handle required
Expand Down Expand Up @@ -362,8 +362,11 @@ function checkQuery(query, bAllowEmpty, bAllowSort = false, bAllowPlaylist = fal
try { fb.GetQueryItems(new FbMetadbHandleList(), queryNoSort); } // Test query against empty handle list since it's much faster!
catch (e) { bPass = false; }
if (bPass) {
try { fb.GetQueryItems(new FbMetadbHandleList(), '* HAS \'\' AND ' + _p(queryNoSort)); } // Some expressions only throw inside parentheses!
catch (e) { bPass = false; }
// Allow simple search like 'rock' but don't allow single TF expressions
if (hasQueryExpression(queryNoSort)) {
try { fb.GetQueryItems(new FbMetadbHandleList(), '* HAS \'\' AND ' + _p(queryNoSort)); } // Some expressions only throw inside parentheses!
catch (e) { bPass = false; }
} else if (/\$.*\(.*\)/.test(queryNoSort)) { bPass = false; }
}
if (!bAllowPlaylist && queryNoSort && queryNoSort.match(/.*#(PLAYLIST|playlist)# IS.*/)) { bPass = false; }
return bPass;
Expand Down Expand Up @@ -404,11 +407,14 @@ function getSortObj(queryOrSort) { // {direction: 1, tf: [TFObject], tag: 'ARTIS
return sortObj;
}

function hasQueryExpression(query) {
return query && query.length && ['PRESENT', 'HAS', 'IS', 'LESS', 'GREATER', 'EQUAL', 'MISSING', 'BEFORE', 'AFTER', 'SINCE', 'DURING'].some((key) => query.includes(key));
}

function isQuery(query, bAllowEmpty, bAllowSort = false, bAllowPlaylist = false) {
let bPass = true;
if (query && query.length) {
bPass = ['PRESENT', 'HAS', 'IS', 'LESS', 'GREATER', 'EQUAL', 'MISSING', 'BEFORE', 'AFTER', 'SINCE', 'DURING'].some((key) => query.includes(key))
&& checkQuery(query, false, bAllowSort, bAllowPlaylist);
bPass = hasQueryExpression(query) && checkQuery(query, false, bAllowSort, bAllowPlaylist);
} else if (!bAllowEmpty) { bPass = false; }
return bPass;
}
Expand Down

0 comments on commit 68bf6bf

Please sign in to comment.