feat: export database

This commit is contained in:
Stephen Zhou 2024-11-05 17:29:53 +08:00
parent fc81546bed
commit 85b4502f9c
No known key found for this signature in database
5 changed files with 38 additions and 2 deletions

View File

@ -45,6 +45,7 @@
"cmdk": "1.0.3",
"dayjs": "1.11.13",
"dexie": "4.0.9",
"dexie-export-import": "^4.1.2",
"dnum": "^2.14.0",
"electron-log": "5.2.0",
"firebase": "10.14.1",

View File

@ -1,3 +1,5 @@
import "dexie-export-import"
import type { Transaction } from "dexie"
import Dexie from "dexie"
@ -79,6 +81,15 @@ class BrowserDB extends Dexie {
export const browserDB = new BrowserDB()
export const exportDB = async () => {
const blob = await browserDB.export({ prettyJson: true })
const url = URL.createObjectURL(blob)
const a = document.createElement("a")
a.href = url
a.download = `${LOCAL_DB_NAME}.json`
a.click()
}
// ================================================ //
// ================================================ //
// ================================================ //

View File

@ -25,6 +25,7 @@ import {
useGeneralSettingValue,
} from "~/atoms/settings/general"
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
import { exportDB } from "~/database"
import { useProxyValue, useSetProxy } from "~/hooks/biz/useProxySetting"
import { fallbackLanguage } from "~/i18n"
import { initAnalytics } from "~/initialize/analytics"
@ -160,6 +161,14 @@ export const SettingGeneral = () => {
description: t("general.rebuild_database.description"),
buttonText: t("general.rebuild_database.button"),
},
{
label: t("general.export_database.label"),
description: t("general.export_database.description"),
buttonText: t("general.export_database.button"),
action: () => {
exportDB()
},
},
{
label: t("general.export.label"),
description: t("general.export.description"),

View File

@ -107,6 +107,9 @@
"general.export.button": "Export",
"general.export.description": "Export your feeds to an OPML file.",
"general.export.label": "Export Feeds",
"general.export_database.button": "Export",
"general.export_database.description": "Export your database to a JSON file.",
"general.export_database.label": "Export Database",
"general.group_by_date.description": "Group entries by date.",
"general.group_by_date.label": "Group by date",
"general.language": "Language",

View File

@ -420,6 +420,9 @@ importers:
dexie:
specifier: 4.0.9
version: 4.0.9
dexie-export-import:
specifier: ^4.1.2
version: 4.1.2(dexie@4.0.9)
dnum:
specifier: ^2.14.0
version: 2.14.0
@ -3340,8 +3343,8 @@ packages:
'@radix-ui/react-avatar@1.1.1':
resolution: {integrity: sha512-eoOtThOmxeoizxpX6RiEsQZ2wj5r4+zoeqAwO0cBaFQGjJwIH3dIX0OCxNrCyrrdxG+vBweMETh3VziQG7c1kw==}
peerDependencies:
'@types/react': '*'
'@types/react-dom': '*'
'@types/react': npm:types-react@19.0.0-rc.1
'@types/react-dom': npm:types-react-dom@19.0.0-rc.1
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
@ -5614,6 +5617,11 @@ packages:
devlop@1.1.0:
resolution: {integrity: sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==}
dexie-export-import@4.1.2:
resolution: {integrity: sha512-dWIkkajX+CsEJ19xMnvyqUDlldIl7jW/G49hy3pXZeIgCei9fPeGSjteoh7BeTujexIM3XZ+uAGCEwgCx2HAsQ==}
peerDependencies:
dexie: ^2.0.4 || ^3.0.0 || ^4.0.1-alpha.5
dexie@4.0.9:
resolution: {integrity: sha512-VQG1huEVSAdDZssb9Bb9mFy+d3jAE0PT4d1nIRYlT46ip1fzbs1tXi0SlUayRDgV3tTbJG8ZRqAo2um49gtynA==}
@ -15757,6 +15765,10 @@ snapshots:
dependencies:
dequal: 2.0.3
dexie-export-import@4.1.2(dexie@4.0.9):
dependencies:
dexie: 4.0.9
dexie@4.0.9: {}
didyoumean@1.2.2: {}