Files
lnreader/src/services/updates/LibraryUpdateQueries.js
T
danisty d260eb1b5e Performance fixes, general fixes and addition of features (#723)
* fix: Fixed images proxied through Cloudflare not loading

* feat: Add utility to render images from Cloudflare proxied sites

* feat(source): Add NOVA (Spanish source)

* fix(source): NovelasLigera display of images and improved display of chapters text

* fix(source): NovelasLigera properly parse metadata

* fix(source): YuukiTls display of novels

* fix(source): TuNovelaLigera missing Cloudflare bypass and not properly getting covers

* fix(source): Other significant changes related to the request of popular novels from sources with no more than 1 page

* fix(source): NOVA not added to source manager

* fix: Remove loading Novel shimmer effect item when nothing is loading

* fix: Properly update chapters and metadata of novels that aren't saved in the local library

* fix: sanitizer doing unnecessary parsing which may add noticable delay to chapter loading

* refac: Add <center> tag to the sanitizer allowed tags

* fix: sanitizer being called each re-render of ReaderScreen plus unnecessary re-render of the WebView

* fix: memoized chapter html conversion to text for TTS, operation can be expensive

* refactor: Moved cloudflareImagesBypass to sources/helpers and fixed NOVA novels summary format
2023-08-02 23:30:44 +05:30

100 lines
2.7 KiB
JavaScript

import { showToast } from '../../hooks/showToast';
import { fetchNovel } from '../Source/source';
import { downloadChapter } from '../../database/queries/ChapterQueries';
import * as SQLite from 'expo-sqlite';
import { getNovel } from '@database/queries/NovelQueries';
const db = SQLite.openDatabase('lnreader.db');
const updateNovelMetadata = async (novelId, novel) => {
const { novelName, novelCover, novelSummary, author, artist, genre, status } =
novel;
db.transaction(tx => {
tx.executeSql(
'UPDATE novels SET novelName = ?, novelCover = ?, novelSummary = ?, author = ?, artist = ?, genre = ?, status = ? WHERE novelId = ?',
[
novelName,
novelCover,
novelSummary,
author,
artist,
genre,
status,
novelId,
],
(txObj, res) => {},
(txObj, error) => showToast(`Error: ${error}`),
);
});
};
const updateNovelCover = async (novelId, novel) => {
const { novelCover } = novel;
db.transaction(tx => {
tx.executeSql(
'UPDATE novels SET novelCover = ? WHERE novelId = ?',
[novelCover, novelId],
(txObj, res) => {},
(txObj, error) => showToast(`Error: ${error}`),
);
});
};
const insertUpdate = async (tx, chapterId, novelId) =>
tx.executeSql(
"INSERT OR IGNORE INTO updates (chapterId, novelId, updateTime) values (?, ?, (datetime('now','localtime')))",
[chapterId, novelId],
(txOBJ, res) => {},
(txOBJ, error) => {},
);
const updateNovel = async (sourceId, novelUrl, novelId, options) => {
const { downloadNewChapters, refreshNovelMetadata } = options;
let novel = await fetchNovel(sourceId, novelUrl);
let forceMetdataUpdate = false;
if (novelId === undefined) {
// novelId will be undefined if novel is not saved in local library
let dbNovel = await getNovel(sourceId, novelUrl);
novelId = dbNovel.novelId;
forceMetdataUpdate = true;
}
if (refreshNovelMetadata || forceMetdataUpdate) {
updateNovelMetadata(novelId, novel);
}
db.transaction(tx => {
novel.chapters.map(chapter => {
const { chapterName, chapterUrl, releaseDate } = chapter;
tx.executeSql(
'INSERT OR IGNORE INTO chapters (chapterUrl, chapterName, releaseDate, novelId) values (?, ?, ?, ?)',
[chapterUrl, chapterName, releaseDate, novelId],
(txObj, { insertId }) => {
if (insertId !== -1) {
if (downloadNewChapters) {
downloadChapter(
sourceId,
novelUrl,
novelId,
chapterUrl,
insertId,
);
}
insertUpdate(tx, insertId, novelId);
}
},
(txObj, error) => {},
);
});
});
};
export { updateNovel };