Skip to content

Commit

Permalink
Fix chapters status lost problem (#934)
Browse files Browse the repository at this point in the history
* ci: rename workflows

* chore: update translations

* fix: use upsert
  • Loading branch information
he0119 authored Feb 1, 2024
1 parent ad2412e commit e0dbf87
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Build
on:
push:
branches:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Lint
on:
push:
branches:
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/persisted/useNovel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const useNovel = (url: string, pluginId: string) => {
novelSettings?.filter,
).then(chapters => setChapters(chapters));
} else {
throw new Error('Unable to get novel');
throw new Error(getString('updatesScreen.unableToGetNovel'));
}
});
};
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/pluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isUrlAbsolute } from './helpers/isAbsoluteUrl';
import { fetchApi, fetchFile, fetchText } from './helpers/fetch';
import { defaultCover } from './helpers/constants';
import { encode, decode } from 'urlencode';
import { getString } from '@strings/translations';

const packages: Record<string, any> = {
'cheerio': { load },
Expand Down Expand Up @@ -122,7 +123,9 @@ const fetchPlugins = async () => {
.then(res => res.json())
.catch(() => {
throw new Error(
`Plugins host error: ${githubUsername}/${githubRepository}`,
`${getString(
'browseScreen.pluginsHostError',
)}: ${githubUsername}/${githubRepository}`,
);
});
return availablePlugins;
Expand Down
22 changes: 11 additions & 11 deletions src/services/backup/drive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const driveBackupAction = async (taskData?: TaskData) => {
try {
MMKVStorage.set(BACKGROUND_ACTION, BackgoundAction.BACKUP);
if (!taskData) {
throw new Error('No data provided');
throw new Error(getString('backupScreen.noDataProvided'));
}
const { delay, backupFolder } = taskData;
await BackgroundService.updateNotification({
taskDesc: 'Preparing Data',
taskDesc: getString('backupScreen.preparingData'),
progressBar: {
indeterminate: true,
value: 0,
Expand All @@ -34,7 +34,7 @@ const driveBackupAction = async (taskData?: TaskData) => {
.then(() => prepareBackupData(CACHE_DIR_PATH))
.then(() =>
BackgroundService.updateNotification({
taskDesc: 'Uploading Data',
taskDesc: getString('backupScreen.uploadingData'),
progressBar: {
indeterminate: true,
value: 1,
Expand All @@ -57,7 +57,7 @@ const driveBackupAction = async (taskData?: TaskData) => {
})
.then(() =>
BackgroundService.updateNotification({
taskDesc: 'Uploading Downloaded files',
taskDesc: getString('backupScreen.uploadingDownloadedFiles'),
progressBar: {
indeterminate: true,
value: 2,
Expand Down Expand Up @@ -127,7 +127,7 @@ const driveRestoreAction = async (taskData?: TaskData) => {
try {
MMKVStorage.set(BACKGROUND_ACTION, BackgoundAction.RESTORE);
if (!taskData) {
throw new Error('No data provided');
throw new Error(getString('backupScreen.noDataProvided'));
}
const { delay, backupFolder } = taskData;
await sleep(delay);
Expand All @@ -143,10 +143,10 @@ const driveRestoreAction = async (taskData?: TaskData) => {
backupFolder.id,
);
if (!zipDataFile || !zipDownloadFile) {
throw new Error('Invalid backup folder');
throw new Error(getString('backupScreen.invalidBackupFolder'));
}
await BackgroundService.updateNotification({
taskDesc: 'Downloading Data',
taskDesc: getString('backupScreen.downloadingData'),
progressBar: {
indeterminate: true,
value: 0,
Expand All @@ -157,7 +157,7 @@ const driveRestoreAction = async (taskData?: TaskData) => {
.then(() => sleep(delay))
.then(() =>
BackgroundService.updateNotification({
taskDesc: 'Restoring Data',
taskDesc: getString('backupScreen.restoringData'),
progressBar: {
indeterminate: true,
value: 1,
Expand All @@ -169,7 +169,7 @@ const driveRestoreAction = async (taskData?: TaskData) => {
.then(() => sleep(delay))
.then(() =>
BackgroundService.updateNotification({
taskDesc: 'Downloading Downloaded files',
taskDesc: getString('backupScreen.downloadingDownloadedFiles'),
progressBar: {
indeterminate: true,
value: 2,
Expand Down Expand Up @@ -209,8 +209,8 @@ const driveRestoreAction = async (taskData?: TaskData) => {
export const driveRestore = async (backupFolder: DriveFile) => {
return BackgroundService.start(driveRestoreAction, {
taskName: 'Drive Restore',
taskTitle: 'Drive Restore',
taskDesc: 'Preparing',
taskTitle: getString('backupScreen.drive.restore'),
taskDesc: getString('common.preparing'),
taskIcon: { name: 'notification_icon', type: 'drawable' },
color: '#00adb5',
parameters: { delay: 500, backupFolder },
Expand Down
20 changes: 10 additions & 10 deletions src/services/backup/remote/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const remoteBackupAction = async (taskData?: TaskData) => {
try {
MMKVStorage.set(BACKGROUND_ACTION, BackgoundAction.BACKUP);
if (!taskData) {
throw new Error('No data provided');
throw new Error(getString('backupScreen.noDataProvided'));
}
const { delay, backupFolder, host } = taskData;
await BackgroundService.updateNotification({
taskDesc: 'Preparing Data',
taskDesc: getString('backupScreen.preparingData'),
progressBar: {
indeterminate: true,
value: 0,
Expand All @@ -33,7 +33,7 @@ const remoteBackupAction = async (taskData?: TaskData) => {
.then(() => prepareBackupData(CACHE_DIR_PATH))
.then(() =>
BackgroundService.updateNotification({
taskDesc: 'Uploading Data',
taskDesc: getString('backupScreen.uploadingData'),
progressBar: {
indeterminate: true,
value: 1,
Expand All @@ -47,7 +47,7 @@ const remoteBackupAction = async (taskData?: TaskData) => {
)
.then(() =>
BackgroundService.updateNotification({
taskDesc: 'Uploading Downloaded files',
taskDesc: getString('backupScreen.uploadingDownloadedFiles'),
progressBar: {
indeterminate: true,
value: 2,
Expand Down Expand Up @@ -112,11 +112,11 @@ const remoteRestoreAction = async (taskData?: TaskData) => {
try {
MMKVStorage.set(BACKGROUND_ACTION, BackgoundAction.RESTORE);
if (!taskData) {
throw new Error('No data provided');
throw new Error(getString('backupScreen.noDataProvided'));
}
const { delay, backupFolder, host } = taskData;
await BackgroundService.updateNotification({
taskDesc: 'Downloading Data',
taskDesc: getString('backupScreen.downloadingData'),
progressBar: {
indeterminate: true,
value: 0,
Expand All @@ -128,7 +128,7 @@ const remoteRestoreAction = async (taskData?: TaskData) => {
)
.then(() =>
BackgroundService.updateNotification({
taskDesc: 'Restoring Data',
taskDesc: getString('backupScreen.restoringData'),
progressBar: {
indeterminate: true,
value: 1,
Expand All @@ -140,7 +140,7 @@ const remoteRestoreAction = async (taskData?: TaskData) => {
.then(() => restoreData(CACHE_DIR_PATH))
.then(() =>
BackgroundService.updateNotification({
taskDesc: 'Downloading Downloaded files',
taskDesc: getString('backupScreen.downloadingDownloadedFiles'),
progressBar: {
indeterminate: true,
value: 2,
Expand Down Expand Up @@ -183,8 +183,8 @@ const remoteRestoreAction = async (taskData?: TaskData) => {
export const remoteRestore = async (host: string, backupFolder: string) => {
return BackgroundService.start(remoteRestoreAction, {
taskName: 'Self Host Restore',
taskTitle: 'Self Host Restore',
taskDesc: 'Preparing',
taskTitle: getString('backupScreen.remote.restore'),
taskDesc: getString('common.preparing'),
taskIcon: { name: 'notification_icon', type: 'drawable' },
color: '#00adb5',
parameters: { delay: 200, backupFolder, host },
Expand Down
16 changes: 11 additions & 5 deletions src/services/epub/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const insertLocalNovel = (
});
resolve(resultSet.insertId);
} else {
reject(new Error('novel insert failed'));
reject(
new Error(getString('advancedSettingsScreen.novelInsertFailed')),
);
}
},
(txObj, error) => {
Expand Down Expand Up @@ -112,7 +114,11 @@ const insertLocalChapter = (
);
resolve(staticPaths);
} else {
reject(new Error('chapter insert failed'));
reject(
new Error(
getString('advancedSettingsScreen.chapterInsertFailed'),
),
);
}
},
(txObj, error) => {
Expand Down Expand Up @@ -211,7 +217,7 @@ const parseNovelAndChapters = async (
const importEpubAction = async (taskData?: TaskData) => {
try {
if (!taskData) {
throw new Error('No data provided');
throw new Error(getString('backupScreen.noDataProvided'));
}
const epubFilePath = RNFS.ExternalCachesDirectoryPath + '/novel.epub';
await RNFS.copyFile(taskData.sourceUri, epubFilePath);
Expand Down Expand Up @@ -333,8 +339,8 @@ export const importEpub = async () => {
}
await BackgroundService.start<TaskData>(importEpubAction, {
taskName: 'Import Epub',
taskTitle: 'Parse Epub',
taskDesc: 'Parsing',
taskTitle: getString('advancedSettingsScreen.parseEpub'),
taskDesc: getString('common.parsing'),
taskIcon: { name: 'notification_icon', type: 'drawable' },
color: '#00adb5',
parameters: { delay: 500, sourceUri: epubFile.uri },
Expand Down
2 changes: 1 addition & 1 deletion src/services/updates/LibraryUpdateQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const updateNovel = async (
novel.chapters?.forEach(chapter => {
const { name, url, releaseTime } = chapter;
tx.executeSql(
"INSERT OR REPLACE INTO Chapter (url, name, releaseTime, novelId, updatedTime) values (?, ?, ?, ?, datetime('now','localtime'))",
"INSERT INTO Chapter (url, name, releaseTime, novelId, updatedTime) values (?, ?, ?, ?, datetime('now','localtime')) ON CONFLICT(url) DO UPDATE SET name=excluded.name, releaseTime=excluded.releaseTime, novelId=excluded.novelId, updatedTime=excluded.updatedTime",
[url, name, releaseTime || '', novelId],
(txObj, { insertId }) => {
if (insertId && downloadNewChapters) {
Expand Down
22 changes: 18 additions & 4 deletions strings/languages/en/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"advancedSettings": "Advanced",
"advancedSettingsScreen": {
"cachedNovelsDeletedToast": "Cached novels deleted",
"chapterInsertFailed": "chapter insert failed",
"clearCachedNovels": "Clear cached novels",
"clearCachedNovelsDesc": "Delete cached novels which not in your library",
"clearDatabaseWarning": "Are you sure? Read and Downloaded chapters and progress of non-library novels will be lost.",
Expand All @@ -24,6 +25,8 @@
"importError": "Import Error",
"importNovel": "Import Novel",
"importStaticFiles": "Import Static Files",
"novelInsertFailed": "novel insert failed",
"parseEpub": "Parse Epub",
"useFAB": "Use FAB instead of button",
"userAgent": "User Agent"
},
Expand Down Expand Up @@ -56,6 +59,8 @@
"createBackup": "Create backup",
"createBackupDesc": "Can be used to restore current library",
"createBackupWarning": "Create backup may not work on devices with Android 9 or lower.",
"downloadingData": "Downloading Data",
"downloadingDownloadedFiles": "Downloading Downloaded files",
"drive": {
"backup": "Drive Backup",
"backupInterruped": "Drive Backup Interruped",
Expand All @@ -65,6 +70,7 @@
},
"googeDrive": "Googe Drive",
"googeDriveDesc": "Backup to your Google Drive",
"invalidBackupFolder": "Invalid backup folder",
"legacy": {
"backupCreated": "Backup created %{fileName}",
"libraryRestored": "Library Restored",
Expand All @@ -76,6 +82,8 @@
},
"legacyBackup": "Legacy Backup",
"noBackupFound": "No backup found",
"noDataProvided": "No data provided",
"preparingData": "Preparing Data",
"remote": {
"backup": "Self Host Backup",
"backupInterruped": "Self Host Backup Interruped",
Expand All @@ -91,19 +99,22 @@
"restoreErrorDesc": "Using this to restore the remaining. Save your time.",
"restoreLargeBackupsWarning": "Restoring large backups may freeze the app until restoring is finished",
"restorinBackup": "Restoring backup",
"restoringData": "Restoring Data",
"selfHost": "Self Host",
"selfHostDesc": "Backup to your server"
"selfHostDesc": "Backup to your server",
"uploadingData": "Uploading Data",
"uploadingDownloadedFiles": "Uploading Downloaded files"
},
"browse": "Browse",
"browseScreen": {
"addedToLibrary": "Added to library",
"available": "Available",
"discover": "Discover",
"globalSearch": "Global search",
"installFailed": "Installation failed: %{name}",
"installed": "Installed",
"installedPlugin": "Installed %{name}",
"installedPlugins": "Installed plugins",
"installFailed": "Installation failed: %{name}",
"lastUsed": "Last used",
"latest": "Latest",
"listEmpty": "Enable languages from settings",
Expand All @@ -119,13 +130,14 @@
},
"noSource": "Your library does not have any novels from this source",
"pinned": "Pinned",
"pluginsHostError": "Plugins host error",
"removeFromLibrary": "Removed from Library",
"searchbar": "Search sources",
"selectNovel": "Select Novel",
"tryAgain": "Try again in a moment",
"uninstalledPlugin": "Uninstalled %{name}",
"updatedTo": "Updated to %{version}",
"updateFailed": "Update failed"
"updateFailed": "Update failed",
"updatedTo": "Updated to %{version}"
},
"browseSettings": "Browse Settings",
"browseSettingsScreen": {
Expand Down Expand Up @@ -176,6 +188,7 @@
"name": "Name",
"newUpdateAvailable": "New update available",
"ok": "Ok",
"parsing": "Parsing",
"pause": "Pause",
"preparing": "Preparing",
"remove": "Remove",
Expand Down Expand Up @@ -474,6 +487,7 @@
"newChapters": "new Chapters",
"novelsUpdated": "%{num} novels updated",
"searchbar": "Search updates",
"unableToGetNovel": "Unable to get novel",
"updatesLower": "updates",
"updatingLibrary": "Updating library"
}
Expand Down
Loading

0 comments on commit e0dbf87

Please sign in to comment.