Auto formatting for Server.js

This commit is contained in:
advplyr 2024-05-05 16:39:38 -05:00
parent a6de76a983
commit 37932f664a

View File

@ -5,7 +5,7 @@ const http = require('http')
const util = require('util') const util = require('util')
const fs = require('./libs/fsExtra') const fs = require('./libs/fsExtra')
const fileUpload = require('./libs/expressFileupload') const fileUpload = require('./libs/expressFileupload')
const cookieParser = require("cookie-parser") const cookieParser = require('cookie-parser')
const { version } = require('../package.json') const { version } = require('../package.json')
@ -180,15 +180,15 @@ class Server {
* so we have to allow cors for specific origins to the /api/items/:id/ebook endpoint * so we have to allow cors for specific origins to the /api/items/:id/ebook endpoint
* The cover image is fetched with XMLHttpRequest in the mobile apps to load into a canvas and extract colors * The cover image is fetched with XMLHttpRequest in the mobile apps to load into a canvas and extract colors
* @see https://ionicframework.com/docs/troubleshooting/cors * @see https://ionicframework.com/docs/troubleshooting/cors
* *
* Running in development allows cors to allow testing the mobile apps in the browser * Running in development allows cors to allow testing the mobile apps in the browser
*/ */
app.use((req, res, next) => { app.use((req, res, next) => {
if (Logger.isDev || req.path.match(/\/api\/items\/([a-z0-9-]{36})\/(ebook|cover)(\/[0-9]+)?/)) { if (Logger.isDev || req.path.match(/\/api\/items\/([a-z0-9-]{36})\/(ebook|cover)(\/[0-9]+)?/)) {
const allowedOrigins = ['capacitor://localhost', 'http://localhost'] const allowedOrigins = ['capacitor://localhost', 'http://localhost']
if (Logger.isDev || allowedOrigins.some(o => o === req.get('origin'))) { if (Logger.isDev || allowedOrigins.some((o) => o === req.get('origin'))) {
res.header('Access-Control-Allow-Origin', req.get('origin')) res.header('Access-Control-Allow-Origin', req.get('origin'))
res.header("Access-Control-Allow-Methods", 'GET, POST, PATCH, PUT, DELETE, OPTIONS') res.header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE, OPTIONS')
res.header('Access-Control-Allow-Headers', '*') res.header('Access-Control-Allow-Headers', '*')
res.header('Access-Control-Allow-Credentials', true) res.header('Access-Control-Allow-Credentials', true)
if (req.method === 'OPTIONS') { if (req.method === 'OPTIONS') {
@ -203,15 +203,17 @@ class Server {
// parse cookies in requests // parse cookies in requests
app.use(cookieParser()) app.use(cookieParser())
// enable express-session // enable express-session
app.use(expressSession({ app.use(
secret: global.ServerSettings.tokenSecret, expressSession({
resave: false, secret: global.ServerSettings.tokenSecret,
saveUninitialized: false, resave: false,
cookie: { saveUninitialized: false,
// also send the cookie if were are not on https (not every use has https) cookie: {
secure: false // also send the cookie if were are not on https (not every use has https)
}, secure: false
})) }
})
)
// init passport.js // init passport.js
app.use(passport.initialize()) app.use(passport.initialize())
// register passport in express-session // register passport in express-session
@ -225,14 +227,16 @@ class Server {
this.server = http.createServer(app) this.server = http.createServer(app)
router.use(fileUpload({ router.use(
defCharset: 'utf8', fileUpload({
defParamCharset: 'utf8', defCharset: 'utf8',
useTempFiles: true, defParamCharset: 'utf8',
tempFileDir: Path.join(global.MetadataPath, 'tmp') useTempFiles: true,
})) tempFileDir: Path.join(global.MetadataPath, 'tmp')
router.use(express.urlencoded({ extended: true, limit: "5mb" })) })
router.use(express.json({ limit: "5mb" })) )
router.use(express.urlencoded({ extended: true, limit: '5mb' }))
router.use(express.json({ limit: '5mb' }))
// Static path to generated nuxt // Static path to generated nuxt
const distPath = Path.join(global.appRoot, '/client/dist') const distPath = Path.join(global.appRoot, '/client/dist')
@ -361,7 +365,7 @@ class Server {
const mediaProgressRemoved = await Database.mediaProgressModel.destroy({ const mediaProgressRemoved = await Database.mediaProgressModel.destroy({
where: { where: {
id: { id: {
[Sequelize.Op.in]: mediaProgressToRemove.map(mp => mp.id) [Sequelize.Op.in]: mediaProgressToRemove.map((mp) => mp.id)
} }
} }
}) })
@ -375,15 +379,18 @@ class Server {
for (const _user of users) { for (const _user of users) {
let hasUpdated = false let hasUpdated = false
if (_user.seriesHideFromContinueListening.length) { if (_user.seriesHideFromContinueListening.length) {
const seriesHiding = (await Database.seriesModel.findAll({ const seriesHiding = (
where: { await Database.seriesModel.findAll({
id: _user.seriesHideFromContinueListening where: {
}, id: _user.seriesHideFromContinueListening
attributes: ['id'], },
raw: true attributes: ['id'],
})).map(se => se.id) raw: true
_user.seriesHideFromContinueListening = _user.seriesHideFromContinueListening.filter(seriesId => { })
if (!seriesHiding.includes(seriesId)) { // Series removed ).map((se) => se.id)
_user.seriesHideFromContinueListening = _user.seriesHideFromContinueListening.filter((seriesId) => {
if (!seriesHiding.includes(seriesId)) {
// Series removed
hasUpdated = true hasUpdated = true
return false return false
} }