Address code review feedback - extract shared constants

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-17 23:28:35 +00:00
parent 35e69c36c3
commit 34f76d6ee4
4 changed files with 13 additions and 8 deletions

8
src/lib/db-constants.ts Normal file
View File

@@ -0,0 +1,8 @@
/**
* Database constants shared across modules
*/
export const DB_KEY = 'codesnippet-db'
export const IDB_NAME = 'CodeSnippetDB'
export const IDB_STORE = 'database'
export const IDB_VERSION = 1

View File

@@ -7,6 +7,7 @@ import { loadFromIndexedDB, saveToIndexedDB, openIndexedDB, deleteFromIndexedDB
import { loadFromLocalStorage, saveToLocalStorage, deleteFromLocalStorage } from './db-localstorage'
import { validateSchema, createTables } from './db-schema'
import { getStorageConfig, FlaskStorageAdapter, loadStorageConfig } from './storage'
import { DB_KEY } from './db-constants'
let dbInstance: Database | null = null
let sqlInstance: any = null
@@ -151,7 +152,8 @@ export async function getDatabaseStats(): Promise<{
const databaseSize = data.length
const hasIDB = await openIndexedDB()
const storageType = hasIDB ? 'indexeddb' : (loadFromLocalStorage() ? 'localstorage' : 'none')
const hasLocalStorage = typeof localStorage !== 'undefined' && localStorage.getItem(DB_KEY) !== null
const storageType = hasIDB ? 'indexeddb' : (hasLocalStorage ? 'localstorage' : 'none')
return {
snippetCount,

View File

@@ -2,10 +2,7 @@
* IndexedDB operations for database persistence
*/
const DB_KEY = 'codesnippet-db'
const IDB_NAME = 'CodeSnippetDB'
const IDB_STORE = 'database'
const IDB_VERSION = 1
import { DB_KEY, IDB_NAME, IDB_STORE, IDB_VERSION } from './db-constants'
export async function openIndexedDB(): Promise<IDBDatabase | null> {
if (typeof indexedDB === 'undefined') return null
@@ -101,5 +98,3 @@ export async function deleteFromIndexedDB(): Promise<void> {
}
})
}
export { DB_KEY }

View File

@@ -2,7 +2,7 @@
* LocalStorage operations for database persistence
*/
import { DB_KEY } from './db-indexeddb'
import { DB_KEY } from './db-constants'
export function loadFromLocalStorage(): Uint8Array | null {
try {