mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-15 09:48:14 +08:00
✨ 支持 Cookie 数据备份&恢复
This commit is contained in:
20
src/web/utils/backupData.ts
Normal file
20
src/web/utils/backupData.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @file web utils backupData.ts
|
||||
* @description 数据备份
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.2.0
|
||||
*/
|
||||
|
||||
// tauri
|
||||
import { fs, path } from "@tauri-apps/api";
|
||||
|
||||
/**
|
||||
* @description 备份 Cookie 数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {Record<string, string>} cookie cookie
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function backupCookieData (cookie: Record<string, string>): Promise<void> {
|
||||
const savePath = `${await path.appLocalDataDir()}\\userData\\cookie.json`;
|
||||
await fs.writeTextFile(savePath, JSON.stringify(cookie, null, 2));
|
||||
}
|
||||
24
src/web/utils/restoreData.ts
Normal file
24
src/web/utils/restoreData.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* @file web utils restoreData.ts
|
||||
* @description 数据恢复
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.2.0
|
||||
*/
|
||||
|
||||
// tauri
|
||||
import { fs, path } from "@tauri-apps/api";
|
||||
// utils
|
||||
import TGSqlite from "../../utils/TGSqlite";
|
||||
|
||||
/**
|
||||
* @description 恢复 Cookie 数据
|
||||
* @since Alpha v0.2.0
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
export async function restoreCookieData (): Promise<boolean> {
|
||||
const cookiePath = `${await path.appLocalDataDir()}\\userData\\cookie.json`;
|
||||
if (!await fs.exists(cookiePath)) return false;
|
||||
const cookieData = await fs.readTextFile(cookiePath);
|
||||
await TGSqlite.saveAppData("cookie", JSON.stringify(JSON.parse(cookieData)));
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user