Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retire unicode handling workaround for Author and Series title #3491

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions server/controllers/LibraryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const libraryItemsBookFilters = require('../utils/queries/libraryItemsBookFilter
const libraryItemFilters = require('../utils/queries/libraryItemFilters')
const seriesFilters = require('../utils/queries/seriesFilters')
const fileUtils = require('../utils/fileUtils')
const { asciiOnlyToLowerCase } = require('../utils/index')
const { createNewSortInstance } = require('../libs/fastSort')
const naturalSort = createNewSortInstance({
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
Expand Down Expand Up @@ -809,7 +808,7 @@ class LibraryController {
}

const limit = req.query.limit || 12
const query = asciiOnlyToLowerCase(req.query.q.trim())
const query = req.query.q.trim()

const matches = await libraryItemFilters.search(req.user, req.library, query, limit)
res.json(matches)
Expand Down
3 changes: 1 addition & 2 deletions server/models/Author.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { DataTypes, Model, where, fn, col } = require('sequelize')
const parseNameString = require('../utils/parsers/parseNameString')
const { asciiOnlyToLowerCase } = require('../utils/index')

class Author extends Model {
constructor(values, options) {
Expand Down Expand Up @@ -56,7 +55,7 @@ class Author extends Model {
static async getByNameAndLibrary(authorName, libraryId) {
return this.findOne({
where: [
where(fn('lower', col('name')), asciiOnlyToLowerCase(authorName)),
where(fn('lower', col('name')), authorName.toLowerCase()),
{
libraryId
}
Expand Down
3 changes: 1 addition & 2 deletions server/models/Series.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { DataTypes, Model, where, fn, col } = require('sequelize')

const { getTitlePrefixAtEnd } = require('../utils/index')
const { asciiOnlyToLowerCase } = require('../utils/index')

class Series extends Model {
constructor(values, options) {
Expand Down Expand Up @@ -42,7 +41,7 @@ class Series extends Model {
static async getByNameAndLibrary(seriesName, libraryId) {
return this.findOne({
where: [
where(fn('lower', col('name')), asciiOnlyToLowerCase(seriesName)),
where(fn('lower', col('name')), seriesName.toLowerCase()),
{
libraryId
}
Expand Down
23 changes: 0 additions & 23 deletions server/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,6 @@ module.exports.getTitlePrefixAtEnd = (title) => {
return prefix ? `${sort}, ${prefix}` : title
}

/**
* to lower case for only ascii characters
* used to handle sqlite that doesnt support unicode lower
* @see https://github.com/advplyr/audiobookshelf/issues/2187
*
* @param {string} str
* @returns {string}
*/
module.exports.asciiOnlyToLowerCase = (str) => {
if (!str) return ''

let temp = ''
for (let chars of str) {
let value = chars.charCodeAt()
if (value >= 65 && value <= 90) {
temp += String.fromCharCode(value + 32)
} else {
temp += chars
}
}
return temp
}

/**
* Escape string used in RegExp
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
Expand Down
Loading