Compare commits

...

18 Commits

Author SHA1 Message Date
advplyr 6f03467f35 Update links in the README 2026-06-29 16:46:33 -05:00
advplyr b2f593f1c4 Update readme organizing docs link & remove api docs link 2026-06-29 16:43:24 -05:00
advplyr 58dcda36a5 Cleanup readme and link to contributing docs 2026-06-29 16:37:54 -05:00
advplyr 354e0bf793 Update readme remove reverse proxy set up and link to docs page 2026-06-29 16:32:41 -05:00
advplyr 2f219ea3cc Merge pull request #5325 from mikiher/file-upload-internal-api
Let next.js handle file uploads through internal-api routes
2026-06-25 17:03:34 -05:00
mikiher 56e60b8420 Server.js: Let next.js handle file uploads through internal-api routes 2026-06-23 14:08:16 +03:00
advplyr 9b92b5de34 Merge pull request #5318 from mikiher/match-update-episode-enclosure
Enhance PodcastController to handle enclosure updates
2026-06-20 17:06:32 -05:00
mikiher 3417c0c721 Enhance PodcastController to handle enclosure updates, allowing for null values and object structure validation for enclosure properties. 2026-06-18 12:39:50 +03:00
advplyr cbda0360aa Merge pull request #5291 from mikiher/allowed-dev-origins
Read AllowedDevOrigins from dev.js into ALLOWED_DEV_ORIGINS env var
2026-06-04 15:13:34 -05:00
mikiher 036bc081f0 index.js: Read AllowedDevOrigins from dev,js into ALLOWED_DEV_ORIGINS env var 2026-06-04 14:03:59 +03:00
advplyr e70e4b9d40 Fix typo on onTest notification body 2026-05-30 15:43:50 -05:00
advplyr aacdcc47ec Version bump v2.35.1 2026-05-28 15:22:55 -05:00
advplyr 499b52b4dd Update Sequelize where query for User username/email case insensitive 2026-05-28 14:49:49 -05:00
advplyr 1bad2d9072 Cleanup abmetadata file parsing & fix server crash #5268 #4287 #5142 2026-05-27 17:33:14 -05:00
advplyr c009db9f28 Merge pull request #5256 from nichwall/fix-bookauthor-collision-on-rename
Fix duplicate bookAuthor creation when renaming authors
2026-05-22 15:43:13 -05:00
advplyr 325469c5a5 Merge pull request #5255 from nichwall/refresh-token-uniqueness
Add unique UUID to access and refresh tokens
2026-05-22 15:39:01 -05:00
Nicholas Wallace c97b36e11c Add ignoreDuplicates for bookAuthor when renaming to respect unique index 2026-05-21 21:06:17 -07:00
Nicholas Wallace e944b2a2f5 Add unique UUID to access and refresh tokens 2026-05-21 17:08:39 -07:00
16 changed files with 191 additions and 324 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "audiobookshelf-client",
"version": "2.35.0",
"version": "2.35.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "audiobookshelf-client",
"version": "2.35.0",
"version": "2.35.1",
"license": "ISC",
"dependencies": {
"@nuxtjs/axios": "^5.13.6",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "audiobookshelf-client",
"version": "2.35.0",
"version": "2.35.1",
"buildNumber": 1,
"description": "Self-hosted audiobook and podcast client",
"main": "index.js",
+5
View File
@@ -31,6 +31,11 @@ if (isDev || options['prod-with-dev-env']) {
if (devEnv.AllowIframe) process.env.ALLOW_IFRAME = '1'
if (devEnv.BackupPath) process.env.BACKUP_PATH = devEnv.BackupPath
if (devEnv.ReactClientPath) process.env.REACT_CLIENT_PATH = devEnv.ReactClientPath
if (devEnv.AllowedDevOrigins) {
process.env.ALLOWED_DEV_ORIGINS = Array.isArray(devEnv.AllowedDevOrigins)
? devEnv.AllowedDevOrigins.join(',')
: String(devEnv.AllowedDevOrigins)
}
process.env.SOURCE = 'local'
process.env.ROUTER_BASE_PATH = devEnv.RouterBasePath ?? '/audiobookshelf'
}
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "audiobookshelf",
"version": "2.35.0",
"version": "2.35.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "audiobookshelf",
"version": "2.35.0",
"version": "2.35.1",
"license": "GPL-3.0",
"dependencies": {
"axios": "^0.27.2",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "audiobookshelf",
"version": "2.35.0",
"version": "2.35.1",
"buildNumber": 1,
"description": "Self-hosted audiobook and podcast server",
"main": "index.js",
+15 -273
View File
@@ -6,9 +6,9 @@
<br />
<a href="https://audiobookshelf.org/docs">Documentation</a>
·
<a href="https://audiobookshelf.org/guides">User Guides</a>
·
<a href="https://audiobookshelf.org/support">Support</a>
·
<a href="https://audiobooks.dev/">Demo</a>
</p>
</div>
@@ -57,21 +57,17 @@ Try it out on the [Google Play Store](https://play.google.com/store/apps/details
Using Test Flight: https://testflight.apple.com/join/wiic7QIW **_(beta is full)_**
### Build your own tools & clients
Check out the [API documentation](https://api.audiobookshelf.org/)
<br />
<img alt="Library Screenshot" src="https://github.com/advplyr/audiobookshelf/raw/master/images/DemoLibrary.png" />
<br />
# Organizing your audiobooks
# Organizing your media
#### Directory structure and folder names are important to Audiobookshelf!
See [documentation](https://audiobookshelf.org/docs#book-directory-structure) for supported directory structure, folder naming conventions, and audio file metadata usage.
See [library docs](https://audiobookshelf.org/docs/category/libraries) for supported directory structures, folder naming conventions, and audio file metadata usage.
<br />
@@ -87,275 +83,24 @@ See [install docs](https://www.audiobookshelf.org/docs)
#### Note: Using a subfolder is supported with no additional changes but the path must be `/audiobookshelf` (this is not changeable). See [discussion](https://github.com/advplyr/audiobookshelf/discussions/3535)
### NGINX Proxy Manager
See [reverse proxy docs](https://audiobookshelf.org/docs/category/reverse-proxy)
Toggle websockets support.
<img alt="NGINX Web socket" src="https://user-images.githubusercontent.com/67830747/153679106-b2a7f5b9-0702-48c6-9740-b26b401986e9.png" />
### NGINX Reverse Proxy
Add this to the site config file on your nginx server after you have changed the relevant parts in the <> brackets, and inserted your certificate paths.
```bash
server {
listen 443 ssl;
server_name <sub>.<domain>.<tld>;
access_log /var/log/nginx/audiobookshelf.access.log;
error_log /var/log/nginx/audiobookshelf.error.log;
ssl_certificate /path/to/certificate;
ssl_certificate_key /path/to/key;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_pass http://<URL_to_forward_to>;
proxy_redirect http:// https://;
# Prevent 413 Request Entity Too Large error
# by increasing the maximum allowed size of the client request body
# For example, set it to 10 GiB
client_max_body_size 10240M;
}
}
```
### Apache Reverse Proxy
Add this to the site config file on your Apache server after you have changed the relevant parts in the <> brackets, and inserted your certificate paths.
For this to work you must enable at least the following mods using `a2enmod`:
- `ssl`
- `proxy`
- `proxy_http`
- `proxy_balancer`
- `proxy_wstunnel`
- `rewrite`
```bash
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName <sub>.<domain>.<tld>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
ProxyPass / http://localhost:<audiobookshelf_port>/
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/?(.*) "ws://localhost:<audiobookshelf_port>/$1" [P,L]
# unless you're doing something special this should be generated by a
# tool like certbot by let's encrypt
SSLCertificateFile /path/to/cert/file
SSLCertificateKeyFile /path/to/key/file
</VirtualHost>
</IfModule>
```
If using Apache >= 2.4.47 you can use the following, without having to use any of the `RewriteEngine`, `RewriteCond`, or `RewriteRule` directives. For example:
```xml
<Location /audiobookshelf>
ProxyPreserveHost on
ProxyPass http://localhost:<audiobookshelf_port>/audiobookshelf upgrade=websocket
ProxyPassReverse http://localhost:<audiobookshelf_port>/audiobookshelf
</Location>
```
Some SSL certificates like those signed by Let's Encrypt require ACME validation. To allow Let's Encrypt to write and confirm the ACME challenge, edit your VirtualHost definition to prevent proxying traffic that queries `/.well-known` and instead serve that directly:
```bash
<VirtualHost *:443>
# ...
# create the directory structure /.well-known/acme-challenges
# within DocumentRoot and give the HTTP user recursive write
# access to it.
DocumentRoot /path/to/local/directory
ProxyPreserveHost On
ProxyPass /.well-known !
ProxyPass / http://localhost:<audiobookshelf_port>/
# ...
</VirtualHost>
```
### SWAG Reverse Proxy
[See LinuxServer.io config sample](https://github.com/linuxserver/reverse-proxy-confs/blob/master/audiobookshelf.subdomain.conf.sample)
### Synology NAS Reverse Proxy Setup (DSM 7+/Quickconnect)
1. **Open Control Panel**
- Navigate to `Login Portal > Advanced`.
2. **General Tab**
- Click `Reverse Proxy` > `Create`.
| Setting | Value |
| ------------------ | -------------- |
| Reverse Proxy Name | audiobookshelf |
3. **Source Configuration**
| Setting | Value |
| ---------------------- | ---------------------------------------- |
| Protocol | HTTPS |
| Hostname | `<sub>.<quickconnectdomain>.synology.me` |
| Port | 443 |
| Access Control Profile | Leave as is |
- Example Hostname: `audiobookshelf.mydomain.synology.me`
4. **Destination Configuration**
| Setting | Value |
| -------- | ----------- |
| Protocol | HTTP |
| Hostname | Your NAS IP |
| Port | 13378 |
5. **Custom Header Tab**
- Go to `Create > Websocket`.
- Configure Headers (leave as is):
| Header Name | Value |
| ----------- | --------------------- |
| Upgrade | `$http_upgrade` |
| Connection | `$connection_upgrade` |
6. **Advanced Settings Tab**
- Leave as is.
### [Traefik Reverse Proxy](https://doc.traefik.io/traefik/)
Middleware relating to CORS will cause the app to report Unknown Error when logging in. To prevent this don't apply any of the following headers to the router for this site:
<ul>
<li>accessControlAllowMethods</li>
<li>accessControlAllowOriginList</li>
<li>accessControlMaxAge</li>
</ul>
From [@Dondochaka](https://discord.com/channels/942908292873723984/942914154254176257/945074590374318170) and [@BeastleeUK](https://discord.com/channels/942908292873723984/942914154254176257/970366039294611506) <br />
### Example Caddyfile - [Caddy Reverse Proxy](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy)
```
subdomain.domain.com {
encode gzip zstd
reverse_proxy <LOCAL_IP>:<PORT>
}
```
### HAProxy
Below is a generic HAProxy config, using `audiobookshelf.YOUR_DOMAIN.COM`.
To use `http2`, `ssl` is needed.
```make
global
# ... (your global settings go here)
defaults
mode http
# ... (your default settings go here)
frontend my_frontend
# Bind to port 443, enable SSL, and specify the certificate list file
bind :443 name :443 ssl crt-list /path/to/cert.crt_list alpn h2,http/1.1
mode http
# Define an ACL for subdomains starting with "audiobookshelf"
acl is_audiobookshelf hdr_beg(host) -i audiobookshelf
# Use the ACL to route traffic to audiobookshelf_backend if the condition is met,
# otherwise, use the default_backend
use_backend audiobookshelf_backend if is_audiobookshelf
default_backend default_backend
backend audiobookshelf_backend
mode http
# ... (backend settings for audiobookshelf go here)
# Define the server for the audiobookshelf backend
server audiobookshelf_server 127.0.0.99:13378
backend default_backend
mode http
# ... (default backend settings go here)
# Define the server for the default backend
server default_server 127.0.0.123:8081
```
### pfSense and HAProxy
For pfSense the inputs are graphical, and `Health checking` is enabled.
#### Frontend, Default backend, access control lists and actions
##### Access Control lists
| Name | Expression | CS | Not | Value |
| :------------: | :---------------: | :-: | :-: | :-------------: |
| audiobookshelf | Host starts with: | | | audiobookshelf. |
##### Actions
The `condition acl names` needs to match the name above `audiobookshelf`.
| Action | Parameters | Condition acl names |
| :-----------: | :------------: | :-----------------: |
| `Use Backend` | audiobookshelf | audiobookshelf |
#### Backend
The `Name` needs to match the `Parameters` above `audiobookshelf`.
| Name | audiobookshelf |
| ---- | -------------- |
##### Server list:
| Name | Expression | CS | Not | Value |
| :------------: | :---------------: | :-: | :-: | :-------------: |
| audiobookshelf | Host starts with: | | | audiobookshelf. |
##### Health checking:
Health checking is enabled by default. `Http check method` of `OPTIONS` is not supported on Audiobookshelf. If Health check fails, data will not be forwared. Need to do one of following:
- To disable: Change `Health check method` to `none`.
- To make Health checking function: Change `Http check method` to `HEAD` or `GET`.
# Run from source
<br />
# Contributing
This application is built using [NodeJs](https://nodejs.org/).
See [contributing docs](https://audiobookshelf.org/docs/contributing/general/)
### Localization
Thank you to [Weblate](https://hosted.weblate.org/engage/audiobookshelf/) for hosting our localization infrastructure pro-bono. If you want to see Audiobookshelf in your language, please help us localize. Additional information on helping with the translations [here](https://www.audiobookshelf.org/faq#how-do-i-help-with-translations). <a href="https://hosted.weblate.org/engage/audiobookshelf/"> <img src="https://hosted.weblate.org/widget/audiobookshelf/abs-web-client/multi-auto.svg" alt="Translation status" /> </a>
Thank you to [Weblate](https://hosted.weblate.org/engage/audiobookshelf/) for hosting our localization infrastructure pro-bono. If you want to see Audiobookshelf in your language, please help us localize. Additional information on helping with the translations [here](https://www.audiobookshelf.org/faq#how-do-i-help-with-translations).
<a href="https://hosted.weblate.org/engage/audiobookshelf/"> <img src="https://hosted.weblate.org/widget/audiobookshelf/abs-web-client/multi-auto.svg" alt="Translation status" /> </a>
<br />
# Run from source
This application is built using [NodeJs](https://nodejs.org/).
### Dev Container Setup
@@ -447,6 +192,3 @@ If you are using VSCode, this project includes a couple of pre-defined targets t
- `Debug client (nuxt)`—Run the client with live reload.
- `Debug server and client (nuxt)`—Runs both the preceding two debug targets.
# How to Support
[See the incomplete "How to Support" page](https://www.audiobookshelf.org/support)
+2
View File
@@ -302,7 +302,9 @@ class Server {
this.server = http.createServer(app)
// Skip file upload parsing for internal-api routes (Next.js proxies read multipart bodies).
router.use(
/^(?!\/internal-api).*/,
fileUpload({
defCharset: 'utf8',
defParamCharset: 'utf8',
+3
View File
@@ -1,4 +1,5 @@
const { Op } = require('sequelize')
const uuid = require('uuid')
const Database = require('../Database')
const Logger = require('../Logger')
@@ -115,6 +116,7 @@ class TokenManager {
const payload = {
userId: user.id,
username: user.username,
jti: uuid.v4(),
type: 'access'
}
const options = {
@@ -138,6 +140,7 @@ class TokenManager {
const payload = {
userId: user.id,
username: user.username,
jti: uuid.v4(),
type: 'refresh'
}
const options = {
+1 -1
View File
@@ -149,7 +149,7 @@ class AuthorController {
})
if (libraryItems.length) {
await Database.bookAuthorModel.removeByIds(req.author.id) // Remove all old BookAuthor
await Database.bookAuthorModel.bulkCreate(bookAuthorsToCreate) // Create all new BookAuthor
await Database.bookAuthorModel.bulkCreate(bookAuthorsToCreate, { ignoreDuplicates: true }) // Create all new unique BookAuthor
for (const libraryItem of libraryItems) {
await libraryItem.saveMetadataFile()
}
+11
View File
@@ -437,6 +437,17 @@ class PodcastController {
}
updatePayload[key] = req.body[key]
} else if (key === 'enclosure') {
const enclosure = req.body.enclosure
if (enclosure === null) {
updatePayload.enclosureURL = null
updatePayload.enclosureSize = null
updatePayload.enclosureType = null
} else if (typeof enclosure === 'object' && typeof enclosure.url === 'string') {
updatePayload.enclosureURL = enclosure.url
updatePayload.enclosureType = typeof enclosure.type === 'string' ? enclosure.type : null
updatePayload.enclosureSize = enclosure.length !== undefined && enclosure.length !== null ? enclosure.length : null
}
} else if (key === 'chapters' && Array.isArray(req.body[key]) && req.body[key].every((ch) => typeof ch === 'object' && ch.title && ch.start)) {
updatePayload[key] = req.body[key]
} else if (key === 'publishedAt' && typeof req.body[key] === 'number') {
+2 -10
View File
@@ -352,11 +352,7 @@ class User extends Model {
if (cachedUser) return cachedUser
const user = await this.findOne({
where: {
username: {
[sequelize.Op.like]: username
}
},
where: sequelize.where(sequelize.fn('lower', sequelize.col('username')), username.toLowerCase()),
include: this.sequelize.models.mediaProgress
})
@@ -377,11 +373,7 @@ class User extends Model {
if (cachedUser) return cachedUser
const user = await this.findOne({
where: {
email: {
[sequelize.Op.like]: email
}
},
where: sequelize.where(sequelize.fn('lower', sequelize.col('email')), email.toLowerCase()),
include: this.sequelize.models.mediaProgress
})
+4 -3
View File
@@ -5,7 +5,7 @@ const { LogLevel } = require('../utils/constants')
const abmetadataGenerator = require('../utils/generators/abmetadataGenerator')
class AbsMetadataFileScanner {
constructor() { }
constructor() {}
/**
* Check for metadata.json file and set book metadata
@@ -32,7 +32,8 @@ class AbsMetadataFileScanner {
if (metadataText) {
libraryScan.addLog(LogLevel.INFO, `Found metadata file "${metadataFilePath}"`)
const abMetadata = abmetadataGenerator.parseJson(metadataText) || {}
const abMetadata = abmetadataGenerator.parseJson(metadataText, 'book') || {}
for (const key in abMetadata) {
// TODO: When to override with null or empty arrays?
if (abMetadata[key] === undefined || abMetadata[key] === null) continue
@@ -71,7 +72,7 @@ class AbsMetadataFileScanner {
if (metadataText) {
libraryScan.addLog(LogLevel.INFO, `Found metadata file "${metadataFilePath}"`)
const abMetadata = abmetadataGenerator.parseJson(metadataText) || {}
const abMetadata = abmetadataGenerator.parseJson(metadataText, 'podcast') || {}
for (const key in abMetadata) {
if (abMetadata[key] === undefined || abMetadata[key] === null) continue
if (key === 'tags' && !abMetadata.tags?.length) continue
+3
View File
@@ -825,6 +825,9 @@ class BookScanner {
const metadataFilePath = Path.join(metadataPath, `metadata.${global.ServerSettings.metadataFileFormat}`)
/**
* Keys must match abmetadataGenerator.js
*/
const jsonObject = {
tags: libraryItem.media.tags || [],
chapters: libraryItem.media.chapters?.map((c) => ({ ...c })) || [],
+3
View File
@@ -425,6 +425,9 @@ class PodcastScanner {
const metadataFilePath = Path.join(metadataPath, `metadata.${global.ServerSettings.metadataFileFormat}`)
/**
* Keys must match abmetadataGenerator.js
*/
const jsonObject = {
tags: libraryItem.media.tags || [],
title: libraryItem.media.title,
+124 -19
View File
@@ -1,7 +1,51 @@
const Logger = require('../../Logger')
const parseSeriesString = require('../parsers/parseSeriesString')
function parseJsonMetadataText(text) {
const mediaTypeKeys = {
book: {
tags: 'stringArray',
title: 'string',
subtitle: 'string',
authors: 'stringArray',
narrators: 'stringArray',
series: 'stringArray',
genres: 'stringArray',
publishedYear: 'string',
publishedDate: 'string',
publisher: 'string',
description: 'string',
isbn: 'string',
asin: 'string',
language: 'string',
explicit: 'boolean',
abridged: 'boolean'
},
podcast: {
tags: 'stringArray',
title: 'string',
author: 'string',
description: 'string',
releaseDate: 'string',
genres: 'stringArray',
feedURL: 'string',
imageURL: 'string',
itunesPageURL: 'string',
itunesId: 'string',
itunesArtistId: 'string',
asin: 'string',
language: 'string',
explicit: 'boolean',
podcastType: 'string'
}
}
/**
*
* @param {string} text
* @param {"book" | "podcast"} mediaType
* @returns {Object}
*/
function parseJsonMetadataText(text, mediaType) {
try {
const abmetadataData = JSON.parse(text)
@@ -19,28 +63,41 @@ function parseJsonMetadataText(text) {
}
delete abmetadataData.metadata
if (abmetadataData.series?.length) {
abmetadataData.series = [...new Set(abmetadataData.series.map((t) => t?.trim()).filter((t) => t))]
abmetadataData.series = abmetadataData.series.map((series) => parseSeriesString.parse(series))
const expectedKeys = mediaTypeKeys[mediaType]
if (!expectedKeys) {
Logger.error(`[abmetadataGenerator] Invalid media type "${mediaType}"`)
return null
}
// clean tags & remove dupes
if (abmetadataData.tags?.length) {
abmetadataData.tags = [...new Set(abmetadataData.tags.map((t) => t?.trim()).filter((t) => t))]
const validated = {}
for (const key in expectedKeys) {
const expectedType = expectedKeys[key]
if (!(key in abmetadataData)) continue
const validatedValue = validateMetadataValue(key, abmetadataData[key], expectedType)
if (validatedValue !== undefined) {
validated[key] = validatedValue
}
}
if (abmetadataData.chapters?.length) {
abmetadataData.chapters = cleanChaptersArray(abmetadataData.chapters, abmetadataData.title)
if (validated.series?.length) {
validated.series = validated.series.map((series) => parseSeriesString.parse(series)).filter(Boolean)
}
// clean remove dupes
if (abmetadataData.authors?.length) {
abmetadataData.authors = [...new Set(abmetadataData.authors.map((t) => t?.trim()).filter((t) => t))]
if (mediaType === 'book' && 'chapters' in abmetadataData) {
if (abmetadataData.chapters === null) {
validated.chapters = []
} else if (Array.isArray(abmetadataData.chapters)) {
const cleanedChapters = cleanChaptersArray(abmetadataData.chapters, validated.title ?? abmetadataData.title)
if (cleanedChapters) {
validated.chapters = cleanedChapters
}
} else {
Logger.warn(`[abmetadataGenerator] Invalid metadata key "chapters" expected array, got ${typeof abmetadataData.chapters}`)
}
}
if (abmetadataData.narrators?.length) {
abmetadataData.narrators = [...new Set(abmetadataData.narrators.map((t) => t?.trim()).filter((t) => t))]
}
if (abmetadataData.genres?.length) {
abmetadataData.genres = [...new Set(abmetadataData.genres.map((t) => t?.trim()).filter((t) => t))]
}
return abmetadataData
return validated
} catch (error) {
Logger.error(`[abmetadataGenerator] Invalid metadata.json JSON`, error)
return null
@@ -48,6 +105,54 @@ function parseJsonMetadataText(text) {
}
module.exports.parseJson = parseJsonMetadataText
/**
* @param {string} key
* @param {*} value
* @param {string} expectedType
* @returns {*|undefined} undefined excludes the key
*/
function validateMetadataValue(key, value, expectedType) {
if (expectedType === 'string') {
if (value === null) return null
if (typeof value === 'number') return String(value)
if (typeof value === 'string') return value
Logger.warn(`[abmetadataGenerator] Invalid metadata key "${key}" expected string, got ${typeof value}`)
return undefined
}
if (expectedType === 'boolean') {
if (value === null) return null
if (typeof value === 'boolean') return value
if (typeof value === 'string') {
const lower = value.toLowerCase()
if (lower === 'true') return true
if (lower === 'false') return false
}
Logger.warn(`[abmetadataGenerator] Invalid metadata key "${key}" expected boolean, got ${typeof value}`)
return undefined
}
// Filter empty strings and deduplicate
if (expectedType === 'stringArray') {
if (value === null) return []
if (!Array.isArray(value)) {
Logger.warn(`[abmetadataGenerator] Invalid metadata key "${key}" expected string array, got ${typeof value}`)
return undefined
}
const cleanedArray = value.filter((t) => typeof t === 'string')
return [...new Set(cleanedArray.map((t) => t.trim()).filter((t) => t))]
}
Logger.warn(`[abmetadataGenerator] Unknown expected type "${expectedType}" for key "${key}"`)
return undefined
}
/**
* @param {Object[]} chaptersArray
* @param {string} mediaTitle
* @returns {Object[]}
*/
function cleanChaptersArray(chaptersArray, mediaTitle) {
const chapters = []
let index = 0
+1 -1
View File
@@ -100,7 +100,7 @@ module.exports.notificationData = {
variables: ['version'],
defaults: {
title: 'Test Notification on Abs {{version}}',
body: 'Test notificataion body for abs {{version}}.'
body: 'Test notification body for abs {{version}}.'
},
testData: {
version: 'v' + version