Update:Validate ASIN for author, chapter and match requests

This commit is contained in:
advplyr 2024-06-09 13:43:03 -05:00
parent ee501f70ed
commit a018374d26
5 changed files with 72 additions and 45 deletions

View file

@ -1,6 +1,7 @@
const axios = require('axios').default
const htmlSanitizer = require('../utils/htmlSanitizer')
const Logger = require('../Logger')
const { isValidASIN } = require('../utils/index')
class Audible {
#responseTimeout = 30000
@ -81,16 +82,6 @@ class Audible {
}
}
/**
* Test if a search title matches an ASIN. Supports lowercase letters
*
* @param {string} title
* @returns {boolean}
*/
isProbablyAsin(title) {
return /^[0-9A-Za-z]{10}$/.test(title)
}
/**
*
* @param {string} asin
@ -137,11 +128,11 @@ class Audible {
if (!timeout || isNaN(timeout)) timeout = this.#responseTimeout
let items
if (asin) {
if (asin && isValidASIN(asin.toUpperCase())) {
items = [await this.asinSearch(asin, region, timeout)]
}
if (!items && this.isProbablyAsin(title)) {
if (!items && isValidASIN(title.toUpperCase())) {
items = [await this.asinSearch(title, region, timeout)]
}