From 5b0d105e21c6a73e30804eb6a156d3246f52616e Mon Sep 17 00:00:00 2001 From: advplyr Date: Tue, 27 Jun 2023 15:56:33 -0500 Subject: [PATCH] Remove deprecated /s/ and /ebook/ api routes --- client/nuxt.config.js | 1 - server/Server.js | 34 ----------------- server/objects/files/AudioTrack.js | 9 ++--- server/objects/files/VideoTrack.js | 3 +- server/routers/StaticRouter.js | 59 ------------------------------ 5 files changed, 4 insertions(+), 102 deletions(-) delete mode 100644 server/routers/StaticRouter.js diff --git a/client/nuxt.config.js b/client/nuxt.config.js index 29773e1a..2494fa26 100644 --- a/client/nuxt.config.js +++ b/client/nuxt.config.js @@ -71,7 +71,6 @@ module.exports = { ], proxy: { - '/s/': { target: process.env.NODE_ENV !== 'production' ? 'http://localhost:3333' : '/' }, '/api/': { target: process.env.NODE_ENV !== 'production' ? 'http://localhost:3333' : '/' }, '/dev/': { target: 'http://localhost:3333', pathRewrite: { '^/dev/': '' } } }, diff --git a/server/Server.js b/server/Server.js index 40be406e..de4156ce 100644 --- a/server/Server.js +++ b/server/Server.js @@ -22,7 +22,6 @@ const SocketAuthority = require('./SocketAuthority') const ApiRouter = require('./routers/ApiRouter') const HlsRouter = require('./routers/HlsRouter') -const StaticRouter = require('./routers/StaticRouter') const NotificationManager = require('./managers/NotificationManager') const EmailManager = require('./managers/EmailManager') @@ -84,7 +83,6 @@ class Server { // Routers this.apiRouter = new ApiRouter(this) this.hlsRouter = new HlsRouter(this.db, this.auth, this.playbackSessionManager) - this.staticRouter = new StaticRouter(this.db) Logger.logManager = this.logManager @@ -170,38 +168,6 @@ class Server { router.use('/api', this.authMiddleware.bind(this), this.apiRouter.router) router.use('/hls', this.authMiddleware.bind(this), this.hlsRouter.router) - // TODO: Deprecated as of 2.2.21 edge - router.use('/s', this.authMiddleware.bind(this), this.staticRouter.router) - - // EBook static file routes - // TODO: Deprecated as of 2.2.21 edge - router.get('/ebook/:library/:folder/*', (req, res) => { - const library = this.db.libraries.find(lib => lib.id === req.params.library) - if (!library) return res.sendStatus(404) - const folder = library.folders.find(fol => fol.id === req.params.folder) - if (!folder) return res.status(404).send('Folder not found') - - // Replace backslashes with forward slashes - const remainingPath = req.params['0'].replace(/\\/g, '/') - - // Prevent path traversal - // e.g. ../../etc/passwd - if (/\/?\.?\.\//.test(remainingPath)) { - Logger.error(`[Server] Invalid path to get ebook "${remainingPath}"`) - return res.sendStatus(403) - } - - // Check file ext is a valid ebook file - const filext = (Path.extname(remainingPath) || '').slice(1).toLowerCase() - if (!globals.SupportedEbookTypes.includes(filext)) { - Logger.error(`[Server] Invalid ebook file ext requested "${remainingPath}"`) - return res.sendStatus(403) - } - - const fullPath = Path.join(folder.fullPath, remainingPath) - res.sendFile(fullPath) - }) - // RSS Feed temp route router.get('/feed/:id', (req, res) => { Logger.info(`[Server] Requesting rss feed ${req.params.id}`) diff --git a/server/objects/files/AudioTrack.js b/server/objects/files/AudioTrack.js index c4cd91c6..b50d3e3f 100644 --- a/server/objects/files/AudioTrack.js +++ b/server/objects/files/AudioTrack.js @@ -1,6 +1,3 @@ -const Path = require('path') -const { encodeUriPath } = require('../../utils/fileUtils') - class AudioTrack { constructor() { this.index = null @@ -22,7 +19,7 @@ class AudioTrack { contentUrl: this.contentUrl, mimeType: this.mimeType, codec: this.codec, - metadata: this.metadata ? this.metadata.toJSON() : null + metadata: this.metadata?.toJSON() || null } } @@ -31,8 +28,8 @@ class AudioTrack { this.startOffset = startOffset this.duration = audioFile.duration this.title = audioFile.metadata.filename || '' - // TODO: Switch to /api/items/:id/file/:fileid - this.contentUrl = Path.join(`${global.RouterBasePath}/s/item/${itemId}`, encodeUriPath(audioFile.metadata.relPath)) + + this.contentUrl = `${global.RouterBasePath}/api/items/${itemId}/file/${audioFile.ino}` this.mimeType = audioFile.mimeType this.codec = audioFile.codec || null this.metadata = audioFile.metadata.clone() diff --git a/server/objects/files/VideoTrack.js b/server/objects/files/VideoTrack.js index a993c77a..b1f1e354 100644 --- a/server/objects/files/VideoTrack.js +++ b/server/objects/files/VideoTrack.js @@ -28,8 +28,7 @@ class VideoTrack { this.index = videoFile.index this.duration = videoFile.duration this.title = videoFile.metadata.filename || '' - // TODO: Switch to /api/items/:id/file/:fileid - this.contentUrl = Path.join(`${global.RouterBasePath}/s/item/${itemId}`, encodeUriPath(videoFile.metadata.relPath)) + this.contentUrl = Path.join(`${global.RouterBasePath}/api/items/${itemId}/file/${videoFile.ino}`, encodeUriPath(videoFile.metadata.relPath)) this.mimeType = videoFile.mimeType this.codec = videoFile.codec this.metadata = videoFile.metadata.clone() diff --git a/server/routers/StaticRouter.js b/server/routers/StaticRouter.js deleted file mode 100644 index bd935ba3..00000000 --- a/server/routers/StaticRouter.js +++ /dev/null @@ -1,59 +0,0 @@ -const express = require('express') -const Path = require('path') -const Logger = require('../Logger') -const { getAudioMimeTypeFromExtname } = require('../utils/fileUtils') - -// TODO: Deprecated as of 2.2.21 edge -class StaticRouter { - constructor(db) { - this.db = db - - this.router = express() - this.router.disable('x-powered-by') - this.init() - } - - init() { - // Library Item static file routes - this.router.get('/item/:id/*', (req, res) => { - const item = this.db.libraryItems.find(ab => ab.id === req.params.id) - if (!item) return res.status(404).send('Item not found with id ' + req.params.id) - - // Replace backslashes with forward slashes - const remainingPath = req.params['0'].replace(/\\/g, '/') - - // Check user has access to this library item - if (!req.user.checkCanAccessLibraryItem(item)) { - Logger.error(`[StaticRouter] User attempted to access library item file without access ${remainingPath}`, req.user) - return res.sendStatus(403) - } - - // Prevent path traversal - // e.g. ../../etc/passwd - if (/\/?\.?\.\//.test(remainingPath)) { - Logger.error(`[StaticRouter] Invalid path to get library item file "${remainingPath}"`) - return res.sendStatus(403) - } - - const fullPath = item.isFile ? item.path : Path.join(item.path, remainingPath) - - // Allow reverse proxy to serve files directly - // See: https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/ - if (global.XAccel) { - Logger.debug(`Use X-Accel to serve static file ${fullPath}`) - return res.status(204).header({ 'X-Accel-Redirect': global.XAccel + fullPath }).send() - } - - let opts = {} - - // Express does not set the correct mimetype for m4b files so use our defined mimetypes if available - const audioMimeType = getAudioMimeTypeFromExtname(Path.extname(fullPath)) - if (audioMimeType) { - opts = { headers: { 'Content-Type': audioMimeType } } - } - - res.sendFile(fullPath, opts) - }) - } -} -module.exports = StaticRouter \ No newline at end of file