env file handling + fix error in libnowplaying

This commit is contained in:
Enstrayed
2025-10-26 00:44:54 -07:00
parent 535e3958cb
commit 44ed0e19d0
4 changed files with 38 additions and 29 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@ node_modules/
bun.lockb bun.lockb
todo.txt todo.txt
proto.js proto.js
.env

View File

@@ -7,9 +7,13 @@ import cookieParser from 'cookie-parser'
const app = express() const app = express()
if (!process.env.DATABASE_URL) { if (!process.env.DATABASE_URL) {
console.log("FATAL: DATABASE_URI must be set") try {
process.loadEnvFile("./.env")
} catch {
console.log("FATAL: DATABASE_URL was not defined or found in env file")
process.exit(1) process.exit(1)
} }
}
const db = postgres(process.env.DATABASE_URL) const db = postgres(process.env.DATABASE_URL)

View File

@@ -42,6 +42,7 @@ async function queryLastfm() {
* @returns {object} Object containing response in JSON and HTML (as string) * @returns {object} Object containing response in JSON and HTML (as string)
*/ */
async function queryJellyfin() { async function queryJellyfin() {
try {
return await fetch(`${globalConfig.nowplaying.jellyfin.host}/Sessions`, { return await fetch(`${globalConfig.nowplaying.jellyfin.host}/Sessions`, {
headers: { headers: {
"Authorization": `MediaBrowser Token=${globalConfig.nowplaying.jellyfin.apiKey}` "Authorization": `MediaBrowser Token=${globalConfig.nowplaying.jellyfin.apiKey}`
@@ -66,6 +67,9 @@ async function queryJellyfin() {
return notPlayingAnythingPlaceholder return notPlayingAnythingPlaceholder
}) })
} catch {
return notPlayingAnythingPlaceholder
}
} }
export { queryLastfm, queryJellyfin } export { queryLastfm, queryJellyfin }