feat: 删除不再使用的数据库和环境相关的工具函数
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
import Dexie from "dexie";
|
||||
|
||||
export const db = new Dexie("testImagesDb");
|
||||
|
||||
db.version(1).stores({
|
||||
images: '++id, created, source'
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
/**
|
||||
* 判断当前是否处于 Chrome 插件环境
|
||||
* @returns {false|chrome.storage.LocalStorageArea}
|
||||
*/
|
||||
export const isExtension = () => {
|
||||
return typeof chrome !== 'undefined' && chrome.storage && chrome.storage.local;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
// 判断当前是否处于 Chrome 插件环境
|
||||
const isExtension = typeof chrome !== 'undefined' && chrome.storage && chrome.storage.local;
|
||||
|
||||
const storageAdapter = {
|
||||
// 获取数据
|
||||
get: async (key) => {
|
||||
if (isExtension) {
|
||||
const result = await chrome.storage.local.get([key]);
|
||||
return result[key];
|
||||
} else {
|
||||
const item = localStorage.getItem(key);
|
||||
try {
|
||||
return JSON.parse(item); // 保持与插件版一致的对象处理
|
||||
} catch {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 设置数据
|
||||
set: async (key, value) => {
|
||||
if (isExtension) {
|
||||
await chrome.storage.local.set({[key]: value});
|
||||
} else {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default storageAdapter;
|
||||
Reference in New Issue
Block a user