diff --git a/client/components/Search/BaseList.js b/client/components/Search/BaseList.js index 8db041d..180d556 100644 --- a/client/components/Search/BaseList.js +++ b/client/components/Search/BaseList.js @@ -253,7 +253,7 @@ export default class BaseList { result = await this.api.getAuthorBookList(authorId); } - return (result.books ? JSON.parse(result.books) : []); + return result.books; } catch (e) { this.$root.stdDialog.alert(e.message, 'Ошибка'); } @@ -276,7 +276,7 @@ export default class BaseList { result = await this.api.getSeriesBookList(series); } - return (result.books ? JSON.parse(result.books) : []); + return result.books; } catch (e) { this.$root.stdDialog.alert(e.message, 'Ошибка'); } diff --git a/client/components/Search/authorBooksStorage.js b/client/components/Search/authorBooksStorage.js index 6e6be34..535b641 100644 --- a/client/components/Search/authorBooksStorage.js +++ b/client/components/Search/authorBooksStorage.js @@ -8,6 +8,8 @@ const abStore = localForage.createInstance({ name: 'authorBooksStorage' }); +const storageVersion = '1'; + class AuthorBooksStorage { constructor() { } @@ -17,6 +19,8 @@ class AuthorBooksStorage { } async setData(key, data) { + key += storageVersion; + if (typeof data !== 'string') throw new Error('AuthorBooksStorage: data must be a string'); @@ -25,6 +29,8 @@ class AuthorBooksStorage { } async getData(key) { + key += storageVersion; + const item = await abStore.getItem(key); //обновим addTime @@ -34,9 +40,9 @@ class AuthorBooksStorage { return item; } - async removeData(key) { - await abStore.removeItem(key); - await abStore.removeItem(`addTime-${key}`); + async _removeData(fullKey) { + await abStore.removeItem(fullKey); + await abStore.removeItem(`addTime-${fullKey}`); } async cleanStorage() { @@ -62,7 +68,7 @@ class AuthorBooksStorage { } if (size > maxDataSize && toDel) { - await this.removeData(toDel); + await this._removeData(toDel); } else { break; } diff --git a/server/core/DbSearcher.js b/server/core/DbSearcher.js index 4199208..8ee01ce 100644 --- a/server/core/DbSearcher.js +++ b/server/core/DbSearcher.js @@ -625,14 +625,14 @@ class DbSearcher { const rows = await this.restoreBooks('author', [authorId]); let authorName = ''; - let books = ''; + let books = []; if (rows.length) { authorName = rows[0].name; books = rows[0].books; } - return {author: authorName, books: (books && books.length ? JSON.stringify(books) : '')}; + return {author: authorName, books}; } finally { this.searchFlag--; } @@ -659,7 +659,7 @@ class DbSearcher { where: `return Array.from(@dirtyIndexLR('value', ${db.esc(series)}, ${db.esc(series)}))` }); - let books; + let books = []; if (rows.length && rows[0].rawResult.length) { //выборка книг серии const bookRows = await this.restoreBooks('series', [rows[0].rawResult[0]]) @@ -668,7 +668,7 @@ class DbSearcher { books = bookRows[0].books; } - return {books: (books && books.length ? JSON.stringify(books) : '')}; + return {books}; } finally { this.searchFlag--; } diff --git a/server/core/opds/AuthorPage.js b/server/core/opds/AuthorPage.js index f8cb8f1..e58996a 100644 --- a/server/core/opds/AuthorPage.js +++ b/server/core/opds/AuthorPage.js @@ -79,7 +79,7 @@ class AuthorPage extends BasePage { const bookList = await this.webWorker.getSeriesBookList(query.series); if (bookList.books) { - let books = JSON.parse(bookList.books); + let books = bookList.books; const booksAll = this.filterBooks(books, {del: 0}); const filtered = (query.all ? booksAll : this.filterBooks(books, query)); const sorted = this.sortSeriesBooks(filtered); @@ -122,7 +122,7 @@ class AuthorPage extends BasePage { const bookList = await this.webWorker.getAuthorBookList(0, query.author.substring(1)); if (bookList.books) { - let books = JSON.parse(bookList.books); + let books = bookList.books; books = this.sortBooks(this.filterBooks(books, query)); for (const b of books) { diff --git a/server/core/opds/SeriesPage.js b/server/core/opds/SeriesPage.js index 260592a..15b3d8b 100644 --- a/server/core/opds/SeriesPage.js +++ b/server/core/opds/SeriesPage.js @@ -44,7 +44,7 @@ class SeriesPage extends BasePage { const bookList = await this.webWorker.getSeriesBookList(query.series.substring(1)); if (bookList.books) { - let books = JSON.parse(bookList.books); + let books = bookList.books; const booksAll = this.filterBooks(books, {del: 0}); const filtered = (query.all ? booksAll : this.filterBooks(books, query)); const sorted = this.sortSeriesBooks(filtered);