From 838d188504848099044df4026e6bb3a3d6a1d52a Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 5 Sep 2021 14:30:33 -0500 Subject: [PATCH] Allow any utf-8 char in genre and tags, fix stream manager user undefined --- client/components/controls/FilterSelect.vue | 1 - client/components/ui/MultiSelect.vue | 3 - client/package.json | 2 +- client/plugins/init.client.js | 103 ++------------------ package.json | 2 +- server/StreamManager.js | 2 +- 6 files changed, 11 insertions(+), 102 deletions(-) diff --git a/client/components/controls/FilterSelect.vue b/client/components/controls/FilterSelect.vue index 1ffcdf34..a246c532 100644 --- a/client/components/controls/FilterSelect.vue +++ b/client/components/controls/FilterSelect.vue @@ -121,7 +121,6 @@ export default { return _sel.text }, genres() { - // return this.$store.state.audiobooks.genres return this.$store.getters['audiobooks/getGenresUsed'] }, tags() { diff --git a/client/components/ui/MultiSelect.vue b/client/components/ui/MultiSelect.vue index 0b2c6855..d09ec5fe 100644 --- a/client/components/ui/MultiSelect.vue +++ b/client/components/ui/MultiSelect.vue @@ -75,7 +75,6 @@ export default { } return this.items.filter((i) => { - // var normie = this.$snakeToNormal(i) var iValue = String(i).toLowerCase() return iValue.includes(this.currentSearch.toLowerCase()) }) @@ -170,7 +169,6 @@ export default { }) }, insertNewItem(item) { - // var kebabItem = this.$normalToSnake(item) this.selected.push(item) this.$emit('input', this.selected) this.textInput = null @@ -183,7 +181,6 @@ export default { if (!this.textInput) return var cleaned = this.textInput.toLowerCase().trim() - // var cleanedKebab = this.$normalToSnake(cleaned) var matchesItem = this.items.find((i) => { return i === cleaned }) diff --git a/client/package.json b/client/package.json index 1e5f1eb9..da780b4d 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "audiobookshelf-client", - "version": "1.0.3", + "version": "1.0.4", "description": "Audiobook manager and player", "main": "index.js", "scripts": { diff --git a/client/plugins/init.client.js b/client/plugins/init.client.js index ca11b4af..fec1527a 100644 --- a/client/plugins/init.client.js +++ b/client/plugins/init.client.js @@ -38,105 +38,13 @@ Vue.prototype.$secondsToTimestamp = (seconds) => { return `${_hours}:${_minutes.toString().padStart(2, '0')}:${_seconds.toString().padStart(2, '0')}` } -Vue.prototype.$snakeToNormal = (snake) => { - if (!snake) { - return '' - } - return String(snake) - .split('_') - .map((t) => t.slice(0, 1).toUpperCase() + t.slice(1)) - .join(' ') -} - -Vue.prototype.$normalToSnake = (normie) => { - if (!normie) return '' - return normie - .trim() - .split(' ') - .map((t) => t.toLowerCase()) - .join('_') -} - -const encode = (text) => encodeURIComponent(Buffer.from(text).toString('base64')) -Vue.prototype.$encode = encode -const decode = (text) => Buffer.from(decodeURIComponent(text), 'base64').toString() -Vue.prototype.$decode = decode - -const availableChars = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" -const getCharCode = (char) => availableChars.indexOf(char) -const getCharFromCode = (code) => availableChars[Number(code)] || -1 -const cleanChar = (char) => getCharCode(char) < 0 ? '?' : char - Vue.prototype.$cleanString = (str) => { if (!str) return '' + // No longer necessary to replace accented chars, full utf-8 charset is supported // replace accented characters: https://stackoverflow.com/a/49901740/7431543 - str = str.normalize('NFD').replace(/[\u0300-\u036f]/g, "") - - var cleaned = '' - for (let i = 0; i < str.length; i++) { - cleaned += cleanChar(str[i]) - } - return cleaned -} - -Vue.prototype.$stringToCode = (str) => { - if (!str) return '' - var numcode = [...str].map(s => { - return String(getCharCode(s)).padStart(2, '0') - }).join('') - return BigInt(numcode).toString(36) -} - -Vue.prototype.$codeToString = (code) => { - if (!code) return '' - var numcode = '' - try { - numcode = [...code].reduce((acc, curr) => { - return BigInt(parseInt(curr, 36)) + BigInt(36) * acc - }, 0n) - } catch (err) { - console.error('numcode fialed', code, err) - } - var numcodestr = String(numcode) - - var remainder = numcodestr.length % 2 - numcodestr = numcodestr.padStart(numcodestr.length - 1 + remainder, '0') - - var finalform = '' - var numChunks = Math.floor(numcodestr.length / 2) - var remaining = numcodestr - for (let i = 0; i < numChunks; i++) { - var chunk = remaining.slice(0, 2) - remaining = remaining.slice(2) - finalform += getCharFromCode(chunk) - } - return finalform -} - -function loadImageBlob(uri) { - return new Promise((resolve) => { - const img = document.createElement('img') - const c = document.createElement('canvas') - const ctx = c.getContext('2d') - img.onload = ({ target }) => { - c.width = target.naturalWidth - c.height = target.naturalHeight - ctx.drawImage(target, 0, 0) - c.toBlob((b) => resolve(b), 'image/jpeg', 0.75) - } - img.crossOrigin = '' - img.src = uri - }) -} - -Vue.prototype.$downloadImage = async (uri, name) => { - var blob = await loadImageBlob(uri) - const a = document.createElement('a') - a.href = URL.createObjectURL(blob) - a.target = '_blank' - a.download = name || 'fotosho-image' - a.click() + // str = str.normalize('NFD').replace(/[\u0300-\u036f]/g, "") + return str.trim() } function isClickedOutsideEl(clickEvent, elToCheckOutside, ignoreSelectors = [], ignoreElems = []) { @@ -195,6 +103,11 @@ Vue.prototype.$sanitizeFilename = (input, replacement = '') => { return sanitized } +const encode = (text) => encodeURIComponent(Buffer.from(text).toString('base64')) +Vue.prototype.$encode = encode +const decode = (text) => Buffer.from(decodeURIComponent(text), 'base64').toString() +Vue.prototype.$decode = decode + export { encode, decode diff --git a/package.json b/package.json index c8390004..7134aacc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "audiobookshelf", - "version": "1.0.3", + "version": "1.0.4", "description": "Self-hosted audiobook server for managing and playing audiobooks.", "main": "index.js", "scripts": { diff --git a/server/StreamManager.js b/server/StreamManager.js index 3a4d0359..9d1f7c41 100644 --- a/server/StreamManager.js +++ b/server/StreamManager.js @@ -122,7 +122,7 @@ class StreamManager { streamUpdate(socket, { currentTime, streamId }) { var client = socket.sheepClient if (!client || !client.stream) { - Logger.error('No stream for client', client.user.id) + Logger.error('No stream for client', (client && client.user) ? client.user.id : 'No Client') return } if (client.stream.id !== streamId) {