mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Update:Remove read-chunk dependency
This commit is contained in:
parent
78079b2e60
commit
416db7c981
84
package-lock.json
generated
84
package-lock.json
generated
@ -27,7 +27,6 @@
|
||||
"node-ffprobe": "^3.0.0",
|
||||
"node-stream-zip": "^1.15.0",
|
||||
"proper-lockfile": "^4.1.2",
|
||||
"read-chunk": "^3.1.0",
|
||||
"recursive-readdir-async": "^1.1.8",
|
||||
"socket.io": "^4.4.1",
|
||||
"xml2js": "^0.4.23"
|
||||
@ -1514,22 +1513,6 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/p-finally": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
|
||||
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/p-try": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
|
||||
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/parseurl": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
||||
@ -1551,14 +1534,6 @@
|
||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
||||
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
||||
},
|
||||
"node_modules/pify": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz",
|
||||
"integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/process-nextick-args": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||
@ -1642,18 +1617,6 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/read-chunk": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/read-chunk/-/read-chunk-3.2.0.tgz",
|
||||
"integrity": "sha512-CEjy9LCzhmD7nUpJ1oVOE6s/hBkejlcJEgLQHVnQznOSilOPb+kpKktlLfFDK3/WP43+F80xkUTM2VOkYoSYvQ==",
|
||||
"dependencies": {
|
||||
"pify": "^4.0.1",
|
||||
"with-open-file": "^0.1.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/readable-stream": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
|
||||
@ -1997,19 +1960,6 @@
|
||||
"which": "bin/which"
|
||||
}
|
||||
},
|
||||
"node_modules/with-open-file": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/with-open-file/-/with-open-file-0.1.7.tgz",
|
||||
"integrity": "sha512-ecJS2/oHtESJ1t3ZfMI3B7KIDKyfN0O16miWxdn30zdh66Yd3LsRFebXZXq6GU4xfxLf6nVxp9kIqElb5fqczA==",
|
||||
"dependencies": {
|
||||
"p-finally": "^1.0.0",
|
||||
"p-try": "^2.1.0",
|
||||
"pify": "^4.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
@ -3199,16 +3149,6 @@
|
||||
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz",
|
||||
"integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg=="
|
||||
},
|
||||
"p-finally": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
|
||||
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4="
|
||||
},
|
||||
"p-try": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
|
||||
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ=="
|
||||
},
|
||||
"parseurl": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
||||
@ -3224,11 +3164,6 @@
|
||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
||||
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
||||
},
|
||||
"pify": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz",
|
||||
"integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g=="
|
||||
},
|
||||
"process-nextick-args": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||
@ -3291,15 +3226,6 @@
|
||||
"unpipe": "1.0.0"
|
||||
}
|
||||
},
|
||||
"read-chunk": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/read-chunk/-/read-chunk-3.2.0.tgz",
|
||||
"integrity": "sha512-CEjy9LCzhmD7nUpJ1oVOE6s/hBkejlcJEgLQHVnQznOSilOPb+kpKktlLfFDK3/WP43+F80xkUTM2VOkYoSYvQ==",
|
||||
"requires": {
|
||||
"pify": "^4.0.1",
|
||||
"with-open-file": "^0.1.6"
|
||||
}
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
|
||||
@ -3559,16 +3485,6 @@
|
||||
"isexe": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"with-open-file": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/with-open-file/-/with-open-file-0.1.7.tgz",
|
||||
"integrity": "sha512-ecJS2/oHtESJ1t3ZfMI3B7KIDKyfN0O16miWxdn30zdh66Yd3LsRFebXZXq6GU4xfxLf6nVxp9kIqElb5fqczA==",
|
||||
"requires": {
|
||||
"p-finally": "^1.0.0",
|
||||
"p-try": "^2.1.0",
|
||||
"pify": "^4.0.1"
|
||||
}
|
||||
},
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
|
@ -46,7 +46,6 @@
|
||||
"node-ffprobe": "^3.0.0",
|
||||
"node-stream-zip": "^1.15.0",
|
||||
"proper-lockfile": "^4.1.2",
|
||||
"read-chunk": "^3.1.0",
|
||||
"recursive-readdir-async": "^1.1.8",
|
||||
"socket.io": "^4.4.1",
|
||||
"xml2js": "^0.4.23"
|
||||
|
42
server/libs/readChunk/index.js
Normal file
42
server/libs/readChunk/index.js
Normal file
@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
// https://github.com/sindresorhus/read-chunk
|
||||
|
||||
const fs = require('fs');
|
||||
const pify = require('./pify');
|
||||
const withOpenFile = require('./withOpenFile');
|
||||
|
||||
const fsReadP = pify(fs.read, { multiArgs: true });
|
||||
|
||||
const readChunk = (filePath, startPosition, length) => {
|
||||
const buffer = Buffer.alloc(length);
|
||||
|
||||
return withOpenFile(filePath, 'r', fileDescriptor =>
|
||||
fsReadP(fileDescriptor, buffer, 0, length, startPosition)
|
||||
)
|
||||
.then(([bytesRead, buffer]) => {
|
||||
if (bytesRead < length) {
|
||||
buffer = buffer.slice(0, bytesRead);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = readChunk;
|
||||
// TODO: Remove this for the next major release
|
||||
module.exports.default = readChunk;
|
||||
|
||||
module.exports.sync = (filePath, startPosition, length) => {
|
||||
let buffer = Buffer.alloc(length);
|
||||
|
||||
const bytesRead = withOpenFile.sync(filePath, 'r', fileDescriptor =>
|
||||
fs.readSync(fileDescriptor, buffer, 0, length, startPosition)
|
||||
);
|
||||
|
||||
if (bytesRead < length) {
|
||||
buffer = buffer.slice(0, bytesRead);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
};
|
70
server/libs/readChunk/pify.js
Normal file
70
server/libs/readChunk/pify.js
Normal file
@ -0,0 +1,70 @@
|
||||
'use strict'
|
||||
|
||||
// https://github.com/sindresorhus/pify
|
||||
|
||||
const processFn = (fn, options) => function (...args) {
|
||||
const P = options.promiseModule;
|
||||
|
||||
return new P((resolve, reject) => {
|
||||
if (options.multiArgs) {
|
||||
args.push((...result) => {
|
||||
if (options.errorFirst) {
|
||||
if (result[0]) {
|
||||
reject(result);
|
||||
} else {
|
||||
result.shift();
|
||||
resolve(result);
|
||||
}
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
} else if (options.errorFirst) {
|
||||
args.push((error, result) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
args.push(resolve);
|
||||
}
|
||||
|
||||
fn.apply(this, args);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = (input, options) => {
|
||||
options = Object.assign({
|
||||
exclude: [/.+(Sync|Stream)$/],
|
||||
errorFirst: true,
|
||||
promiseModule: Promise
|
||||
}, options);
|
||||
|
||||
const objType = typeof input;
|
||||
if (!(input !== null && (objType === 'object' || objType === 'function'))) {
|
||||
throw new TypeError(`Expected \`input\` to be a \`Function\` or \`Object\`, got \`${input === null ? 'null' : objType}\``);
|
||||
}
|
||||
|
||||
const filter = key => {
|
||||
const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);
|
||||
return options.include ? options.include.some(match) : !options.exclude.some(match);
|
||||
};
|
||||
|
||||
let ret;
|
||||
if (objType === 'function') {
|
||||
ret = function (...args) {
|
||||
return options.excludeMain ? input(...args) : processFn(input, options).apply(this, args);
|
||||
};
|
||||
} else {
|
||||
ret = Object.create(Object.getPrototypeOf(input));
|
||||
}
|
||||
|
||||
for (const key in input) { // eslint-disable-line guard-for-in
|
||||
const property = input[key];
|
||||
ret[key] = typeof property === 'function' && filter(key) ? processFn(property, options) : property;
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
41
server/libs/readChunk/withOpenFile.js
Normal file
41
server/libs/readChunk/withOpenFile.js
Normal file
@ -0,0 +1,41 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const pify = require('./pify')
|
||||
const pTry = (fn, ...arguments_) => new Promise(resolve => {
|
||||
resolve(fn(...arguments_));
|
||||
})
|
||||
const pFinally = (promise, onFinally) => {
|
||||
onFinally = onFinally || (() => { });
|
||||
|
||||
return promise.then(
|
||||
val => new Promise(resolve => {
|
||||
resolve(onFinally());
|
||||
}).then(() => val),
|
||||
err => new Promise(resolve => {
|
||||
resolve(onFinally());
|
||||
}).then(() => {
|
||||
throw err;
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
const fsP = pify(fs)
|
||||
|
||||
module.exports = (...args) => {
|
||||
const callback = args.pop()
|
||||
return fsP
|
||||
.open(...args)
|
||||
.then(fd => pFinally(pTry(callback, fd), _ => fsP.close(fd)))
|
||||
}
|
||||
|
||||
module.exports.sync = (...args) => {
|
||||
const callback = args.pop()
|
||||
const fd = fs.openSync(...args)
|
||||
try {
|
||||
return callback(fd)
|
||||
} finally {
|
||||
fs.closeSync(fd)
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ const fs = require('fs-extra')
|
||||
const Path = require('path')
|
||||
const axios = require('axios')
|
||||
const Logger = require('../Logger')
|
||||
const readChunk = require('read-chunk')
|
||||
const readChunk = require('../libs/readChunk')
|
||||
const imageType = require('image-type')
|
||||
const filePerms = require('../utils/filePerms')
|
||||
|
||||
|
@ -8,7 +8,7 @@ const Stream = require('../objects/Stream')
|
||||
const Logger = require('../Logger')
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const uaParserJs = require('../libs/uaParserJs')
|
||||
const uaParserJs = require('../libs/uaParser')
|
||||
const requestIp = require('../libs/requestIp')
|
||||
|
||||
class PlaybackSessionManager {
|
||||
|
Loading…
Reference in New Issue
Block a user