mostly formatting, dependency fix
This commit is contained in:
@@ -2,13 +2,13 @@ import type {
|
||||
LoadedWorkspace,
|
||||
StoredWorkspace,
|
||||
WorkspaceSummary,
|
||||
} from "./workspaceTypes";
|
||||
} from './workspaceTypes';
|
||||
|
||||
const DB_NAME = "pdf-tools-workspaces";
|
||||
const DB_NAME = 'pdf-tools-workspaces';
|
||||
const DB_VERSION = 1;
|
||||
|
||||
const WORKSPACE_STORE = "workspaces";
|
||||
const PDF_STORE = "pdfBinaries";
|
||||
const WORKSPACE_STORE = 'workspaces';
|
||||
const PDF_STORE = 'pdfBinaries';
|
||||
|
||||
interface PdfBinaryRecord {
|
||||
pdfId: string;
|
||||
@@ -48,21 +48,21 @@ function openWorkspaceDb(): Promise<IDBDatabase> {
|
||||
|
||||
if (!db.objectStoreNames.contains(WORKSPACE_STORE)) {
|
||||
const workspaceStore = db.createObjectStore(WORKSPACE_STORE, {
|
||||
keyPath: "id",
|
||||
keyPath: 'id',
|
||||
});
|
||||
|
||||
workspaceStore.createIndex("updatedAt", "updatedAt", {
|
||||
workspaceStore.createIndex('updatedAt', 'updatedAt', {
|
||||
unique: false,
|
||||
});
|
||||
|
||||
workspaceStore.createIndex("pdfId", "pdfId", {
|
||||
workspaceStore.createIndex('pdfId', 'pdfId', {
|
||||
unique: false,
|
||||
});
|
||||
}
|
||||
|
||||
if (!db.objectStoreNames.contains(PDF_STORE)) {
|
||||
db.createObjectStore(PDF_STORE, {
|
||||
keyPath: "pdfId",
|
||||
keyPath: 'pdfId',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -76,7 +76,7 @@ export async function listWorkspaces(): Promise<WorkspaceSummary[]> {
|
||||
const db = await openWorkspaceDb();
|
||||
|
||||
try {
|
||||
const tx = db.transaction(WORKSPACE_STORE, "readonly");
|
||||
const tx = db.transaction(WORKSPACE_STORE, 'readonly');
|
||||
const store = tx.objectStore(WORKSPACE_STORE);
|
||||
|
||||
const records = await requestToPromise<StoredWorkspace[]>(store.getAll());
|
||||
@@ -113,13 +113,13 @@ export async function saveWorkspaceToIndexedDb({
|
||||
const pdfRecord: PdfBinaryRecord = {
|
||||
pdfId: workspace.pdfId,
|
||||
name: workspace.pdfName,
|
||||
blob: new Blob([pdfArrayBuffer], { type: "application/pdf" }),
|
||||
blob: new Blob([pdfArrayBuffer], { type: 'application/pdf' }),
|
||||
size: pdfArrayBuffer.byteLength,
|
||||
createdAt: workspace.createdAt,
|
||||
updatedAt: now,
|
||||
};
|
||||
|
||||
const tx = db.transaction([WORKSPACE_STORE, PDF_STORE], "readwrite");
|
||||
const tx = db.transaction([WORKSPACE_STORE, PDF_STORE], 'readwrite');
|
||||
|
||||
tx.objectStore(PDF_STORE).put(pdfRecord);
|
||||
tx.objectStore(WORKSPACE_STORE).put(workspace);
|
||||
@@ -131,15 +131,15 @@ export async function saveWorkspaceToIndexedDb({
|
||||
}
|
||||
|
||||
export async function loadWorkspaceFromIndexedDb(
|
||||
workspaceId: string,
|
||||
workspaceId: string
|
||||
): Promise<LoadedWorkspace | null> {
|
||||
const db = await openWorkspaceDb();
|
||||
|
||||
try {
|
||||
const tx = db.transaction([WORKSPACE_STORE, PDF_STORE], "readonly");
|
||||
const tx = db.transaction([WORKSPACE_STORE, PDF_STORE], 'readonly');
|
||||
|
||||
const workspace = await requestToPromise<StoredWorkspace | undefined>(
|
||||
tx.objectStore(WORKSPACE_STORE).get(workspaceId),
|
||||
tx.objectStore(WORKSPACE_STORE).get(workspaceId)
|
||||
);
|
||||
|
||||
if (!workspace) {
|
||||
@@ -148,7 +148,7 @@ export async function loadWorkspaceFromIndexedDb(
|
||||
}
|
||||
|
||||
const pdfRecord = await requestToPromise<PdfBinaryRecord | undefined>(
|
||||
tx.objectStore(PDF_STORE).get(workspace.pdfId),
|
||||
tx.objectStore(PDF_STORE).get(workspace.pdfId)
|
||||
);
|
||||
|
||||
await transactionDone(tx);
|
||||
@@ -169,20 +169,20 @@ export async function loadWorkspaceFromIndexedDb(
|
||||
}
|
||||
|
||||
export async function deleteWorkspaceFromIndexedDb(
|
||||
workspaceId: string,
|
||||
workspaceId: string
|
||||
): Promise<void> {
|
||||
const db = await openWorkspaceDb();
|
||||
|
||||
try {
|
||||
const lookupTx = db.transaction(WORKSPACE_STORE, "readonly");
|
||||
const lookupTx = db.transaction(WORKSPACE_STORE, 'readonly');
|
||||
const workspace = await requestToPromise<StoredWorkspace | undefined>(
|
||||
lookupTx.objectStore(WORKSPACE_STORE).get(workspaceId),
|
||||
lookupTx.objectStore(WORKSPACE_STORE).get(workspaceId)
|
||||
);
|
||||
await transactionDone(lookupTx);
|
||||
|
||||
if (!workspace) return;
|
||||
|
||||
const deleteTx = db.transaction([WORKSPACE_STORE, PDF_STORE], "readwrite");
|
||||
const deleteTx = db.transaction([WORKSPACE_STORE, PDF_STORE], 'readwrite');
|
||||
deleteTx.objectStore(WORKSPACE_STORE).delete(workspaceId);
|
||||
await transactionDone(deleteTx);
|
||||
|
||||
@@ -190,14 +190,14 @@ export async function deleteWorkspaceFromIndexedDb(
|
||||
const remainingWorkspaces = await listWorkspaces();
|
||||
|
||||
const pdfStillUsed = remainingWorkspaces.some(
|
||||
(summary) => summary.pdfId === workspace.pdfId,
|
||||
(summary) => summary.pdfId === workspace.pdfId
|
||||
);
|
||||
|
||||
if (!pdfStillUsed) {
|
||||
const cleanupDb = await openWorkspaceDb();
|
||||
|
||||
try {
|
||||
const cleanupTx = cleanupDb.transaction(PDF_STORE, "readwrite");
|
||||
const cleanupTx = cleanupDb.transaction(PDF_STORE, 'readwrite');
|
||||
cleanupTx.objectStore(PDF_STORE).delete(workspace.pdfId);
|
||||
await transactionDone(cleanupTx);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user