mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01:00
Update:Remove fast-sort dependency
This commit is contained in:
parent
e06a015d6e
commit
089d4b5cee
11
package-lock.json
generated
11
package-lock.json
generated
@ -16,7 +16,6 @@
|
|||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-fileupload": "^1.2.1",
|
"express-fileupload": "^1.2.1",
|
||||||
"express-rate-limit": "^5.3.0",
|
"express-rate-limit": "^5.3.0",
|
||||||
"fast-sort": "^3.1.1",
|
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"htmlparser2": "^8.0.1",
|
"htmlparser2": "^8.0.1",
|
||||||
@ -795,11 +794,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.5.1.tgz",
|
||||||
"integrity": "sha512-MTjE2eIbHv5DyfuFz4zLYWxpqVhEhkTiwFGuB74Q9CSou2WHO52nlE5y3Zlg6SIsiYUIPj6ifFxnkPz6O3sIUg=="
|
"integrity": "sha512-MTjE2eIbHv5DyfuFz4zLYWxpqVhEhkTiwFGuB74Q9CSou2WHO52nlE5y3Zlg6SIsiYUIPj6ifFxnkPz6O3sIUg=="
|
||||||
},
|
},
|
||||||
"node_modules/fast-sort": {
|
|
||||||
"version": "3.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fast-sort/-/fast-sort-3.2.0.tgz",
|
|
||||||
"integrity": "sha512-EgQtkmWo2Icq6uei57fTrZAKayL9b4OISU1613737AuLcIbAZ57tcOtGaK2A7zO54kk97wOnSw6INDA++rjMAQ=="
|
|
||||||
},
|
|
||||||
"node_modules/finalhandler": {
|
"node_modules/finalhandler": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
|
||||||
@ -2535,11 +2529,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.5.1.tgz",
|
||||||
"integrity": "sha512-MTjE2eIbHv5DyfuFz4zLYWxpqVhEhkTiwFGuB74Q9CSou2WHO52nlE5y3Zlg6SIsiYUIPj6ifFxnkPz6O3sIUg=="
|
"integrity": "sha512-MTjE2eIbHv5DyfuFz4zLYWxpqVhEhkTiwFGuB74Q9CSou2WHO52nlE5y3Zlg6SIsiYUIPj6ifFxnkPz6O3sIUg=="
|
||||||
},
|
},
|
||||||
"fast-sort": {
|
|
||||||
"version": "3.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fast-sort/-/fast-sort-3.2.0.tgz",
|
|
||||||
"integrity": "sha512-EgQtkmWo2Icq6uei57fTrZAKayL9b4OISU1613737AuLcIbAZ57tcOtGaK2A7zO54kk97wOnSw6INDA++rjMAQ=="
|
|
||||||
},
|
|
||||||
"finalhandler": {
|
"finalhandler": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-fileupload": "^1.2.1",
|
"express-fileupload": "^1.2.1",
|
||||||
"express-rate-limit": "^5.3.0",
|
"express-rate-limit": "^5.3.0",
|
||||||
"fast-sort": "^3.1.1",
|
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"htmlparser2": "^8.0.1",
|
"htmlparser2": "^8.0.1",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
const { reqSupportsWebp } = require('../utils/index')
|
const { reqSupportsWebp } = require('../utils/index')
|
||||||
const { createNewSortInstance } = require('fast-sort')
|
const { createNewSortInstance } = require('../libs/fastSort')
|
||||||
|
|
||||||
const naturalSort = createNewSortInstance({
|
const naturalSort = createNewSortInstance({
|
||||||
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
||||||
|
@ -4,7 +4,7 @@ const filePerms = require('../utils/filePerms')
|
|||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
const Library = require('../objects/Library')
|
const Library = require('../objects/Library')
|
||||||
const libraryHelpers = require('../utils/libraryHelpers')
|
const libraryHelpers = require('../utils/libraryHelpers')
|
||||||
const { sort, createNewSortInstance } = require('fast-sort')
|
const { sort, createNewSortInstance } = require('../libs/fastSort')
|
||||||
const naturalSort = createNewSortInstance({
|
const naturalSort = createNewSortInstance({
|
||||||
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
||||||
})
|
})
|
||||||
|
131
server/libs/fastSort/index.js
Normal file
131
server/libs/fastSort/index.js
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
// SOURCE: https://github.com/snovakovic/fast-sort
|
||||||
|
// LICENSE: https://github.com/snovakovic/fast-sort/blob/master/LICENSE
|
||||||
|
|
||||||
|
(function (global, factory) {
|
||||||
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||||
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||||
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['fast-sort'] = {}));
|
||||||
|
}(this, (function (exports) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// >>> INTERFACES <<<
|
||||||
|
// >>> HELPERS <<<
|
||||||
|
var castComparer = function (comparer) { return function (a, b, order) { return comparer(a, b, order) * order; }; };
|
||||||
|
var throwInvalidConfigErrorIfTrue = function (condition, context) {
|
||||||
|
if (condition)
|
||||||
|
throw Error("Invalid sort config: " + context);
|
||||||
|
};
|
||||||
|
var unpackObjectSorter = function (sortByObj) {
|
||||||
|
var _a = sortByObj || {}, asc = _a.asc, desc = _a.desc;
|
||||||
|
var order = asc ? 1 : -1;
|
||||||
|
var sortBy = (asc || desc);
|
||||||
|
// Validate object config
|
||||||
|
throwInvalidConfigErrorIfTrue(!sortBy, 'Expected `asc` or `desc` property');
|
||||||
|
throwInvalidConfigErrorIfTrue(asc && desc, 'Ambiguous object with `asc` and `desc` config properties');
|
||||||
|
var comparer = sortByObj.comparer && castComparer(sortByObj.comparer);
|
||||||
|
return { order: order, sortBy: sortBy, comparer: comparer };
|
||||||
|
};
|
||||||
|
// >>> SORTERS <<<
|
||||||
|
var multiPropertySorterProvider = function (defaultComparer) {
|
||||||
|
return function multiPropertySorter(sortBy, sortByArr, depth, order, comparer, a, b) {
|
||||||
|
var valA;
|
||||||
|
var valB;
|
||||||
|
if (typeof sortBy === 'string') {
|
||||||
|
valA = a[sortBy];
|
||||||
|
valB = b[sortBy];
|
||||||
|
}
|
||||||
|
else if (typeof sortBy === 'function') {
|
||||||
|
valA = sortBy(a);
|
||||||
|
valB = sortBy(b);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var objectSorterConfig = unpackObjectSorter(sortBy);
|
||||||
|
return multiPropertySorter(objectSorterConfig.sortBy, sortByArr, depth, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer, a, b);
|
||||||
|
}
|
||||||
|
var equality = comparer(valA, valB, order);
|
||||||
|
if ((equality === 0 || (valA == null && valB == null)) &&
|
||||||
|
sortByArr.length > depth) {
|
||||||
|
return multiPropertySorter(sortByArr[depth], sortByArr, depth + 1, order, comparer, a, b);
|
||||||
|
}
|
||||||
|
return equality;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
function getSortStrategy(sortBy, comparer, order) {
|
||||||
|
// Flat array sorter
|
||||||
|
if (sortBy === undefined || sortBy === true) {
|
||||||
|
return function (a, b) { return comparer(a, b, order); };
|
||||||
|
}
|
||||||
|
// Sort list of objects by single object key
|
||||||
|
if (typeof sortBy === 'string') {
|
||||||
|
throwInvalidConfigErrorIfTrue(sortBy.includes('.'), 'String syntax not allowed for nested properties.');
|
||||||
|
return function (a, b) { return comparer(a[sortBy], b[sortBy], order); };
|
||||||
|
}
|
||||||
|
// Sort list of objects by single function sorter
|
||||||
|
if (typeof sortBy === 'function') {
|
||||||
|
return function (a, b) { return comparer(sortBy(a), sortBy(b), order); };
|
||||||
|
}
|
||||||
|
// Sort by multiple properties
|
||||||
|
if (Array.isArray(sortBy)) {
|
||||||
|
var multiPropSorter_1 = multiPropertySorterProvider(comparer);
|
||||||
|
return function (a, b) { return multiPropSorter_1(sortBy[0], sortBy, 1, order, comparer, a, b); };
|
||||||
|
}
|
||||||
|
// Unpack object config to get actual sorter strategy
|
||||||
|
var objectSorterConfig = unpackObjectSorter(sortBy);
|
||||||
|
return getSortStrategy(objectSorterConfig.sortBy, objectSorterConfig.comparer || comparer, objectSorterConfig.order);
|
||||||
|
}
|
||||||
|
var sortArray = function (order, ctx, sortBy, comparer) {
|
||||||
|
var _a;
|
||||||
|
if (!Array.isArray(ctx)) {
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
// Unwrap sortBy if array with only 1 value to get faster sort strategy
|
||||||
|
if (Array.isArray(sortBy) && sortBy.length < 2) {
|
||||||
|
_a = sortBy, sortBy = _a[0];
|
||||||
|
}
|
||||||
|
return ctx.sort(getSortStrategy(sortBy, comparer, order));
|
||||||
|
};
|
||||||
|
function createNewSortInstance(opts) {
|
||||||
|
var comparer = castComparer(opts.comparer);
|
||||||
|
return function (_ctx) {
|
||||||
|
var ctx = Array.isArray(_ctx) && !opts.inPlaceSorting
|
||||||
|
? _ctx.slice()
|
||||||
|
: _ctx;
|
||||||
|
return {
|
||||||
|
asc: function (sortBy) {
|
||||||
|
return sortArray(1, ctx, sortBy, comparer);
|
||||||
|
},
|
||||||
|
desc: function (sortBy) {
|
||||||
|
return sortArray(-1, ctx, sortBy, comparer);
|
||||||
|
},
|
||||||
|
by: function (sortBy) {
|
||||||
|
return sortArray(1, ctx, sortBy, comparer);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var defaultComparer = function (a, b, order) {
|
||||||
|
if (a == null)
|
||||||
|
return order;
|
||||||
|
if (b == null)
|
||||||
|
return -order;
|
||||||
|
if (a < b)
|
||||||
|
return -1;
|
||||||
|
if (a > b)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
var sort = createNewSortInstance({
|
||||||
|
comparer: defaultComparer,
|
||||||
|
});
|
||||||
|
var inPlaceSort = createNewSortInstance({
|
||||||
|
comparer: defaultComparer,
|
||||||
|
inPlaceSorting: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
exports.createNewSortInstance = createNewSortInstance;
|
||||||
|
exports.inPlaceSort = inPlaceSort;
|
||||||
|
exports.sort = sort;
|
||||||
|
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
|
||||||
|
})));
|
@ -4,7 +4,7 @@ const PodcastMetadata = require('../metadata/PodcastMetadata')
|
|||||||
const { areEquivalent, copyValue } = require('../../utils/index')
|
const { areEquivalent, copyValue } = require('../../utils/index')
|
||||||
const abmetadataGenerator = require('../../utils/abmetadataGenerator')
|
const abmetadataGenerator = require('../../utils/abmetadataGenerator')
|
||||||
const { readTextFile } = require('../../utils/fileUtils')
|
const { readTextFile } = require('../../utils/fileUtils')
|
||||||
const { createNewSortInstance } = require('fast-sort')
|
const { createNewSortInstance } = require('../../libs/fastSort')
|
||||||
const naturalSort = createNewSortInstance({
|
const naturalSort = createNewSortInstance({
|
||||||
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const { sort, createNewSortInstance } = require('fast-sort')
|
const { sort, createNewSortInstance } = require('../libs/fastSort')
|
||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
const naturalSort = createNewSortInstance({
|
const naturalSort = createNewSortInstance({
|
||||||
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
||||||
|
Loading…
Reference in New Issue
Block a user