Integrate CCN 2025-2026 files
This commit is contained in:
@ -1,13 +1,13 @@
|
||||
import type { CsoundProject } from './types';
|
||||
import type { File } from './types';
|
||||
|
||||
const DB_NAME = 'csound-projects-db';
|
||||
const DB_VERSION = 1;
|
||||
const STORE_NAME = 'projects';
|
||||
const DB_NAME = 'csound-files-db';
|
||||
const DB_VERSION = 3;
|
||||
const STORE_NAME = 'files';
|
||||
|
||||
/**
|
||||
* Database wrapper for IndexedDB operations
|
||||
*/
|
||||
class ProjectDatabase {
|
||||
class FileDatabase {
|
||||
private db: IDBDatabase | null = null;
|
||||
private initPromise: Promise<void> | null = null;
|
||||
|
||||
@ -38,18 +38,19 @@ class ProjectDatabase {
|
||||
request.onupgradeneeded = (event) => {
|
||||
const db = (event.target as IDBOpenDBRequest).result;
|
||||
|
||||
// Create object store if it doesn't exist
|
||||
// Delete old stores if they exist
|
||||
if (db.objectStoreNames.contains('projects')) {
|
||||
db.deleteObjectStore('projects');
|
||||
}
|
||||
if (db.objectStoreNames.contains('workspaces')) {
|
||||
db.deleteObjectStore('workspaces');
|
||||
}
|
||||
|
||||
// Create files store if it doesn't exist
|
||||
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
||||
const objectStore = db.createObjectStore(STORE_NAME, {
|
||||
db.createObjectStore(STORE_NAME, {
|
||||
keyPath: 'id',
|
||||
});
|
||||
|
||||
// Create indexes for efficient querying
|
||||
objectStore.createIndex('title', 'title', { unique: false });
|
||||
objectStore.createIndex('author', 'author', { unique: false });
|
||||
objectStore.createIndex('dateCreated', 'dateCreated', { unique: false });
|
||||
objectStore.createIndex('dateModified', 'dateModified', { unique: false });
|
||||
objectStore.createIndex('tags', 'tags', { unique: false, multiEntry: true });
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -69,9 +70,9 @@ class ProjectDatabase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a project by ID
|
||||
* Get a file by ID
|
||||
*/
|
||||
async get(id: string): Promise<CsoundProject | null> {
|
||||
async get(id: string): Promise<File | null> {
|
||||
const db = await this.ensureDb();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -84,15 +85,15 @@ class ProjectDatabase {
|
||||
};
|
||||
|
||||
request.onerror = () => {
|
||||
reject(new Error(`Failed to get project: ${request.error?.message}`));
|
||||
reject(new Error(`Failed to get file: ${request.error?.message}`));
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* Get all files
|
||||
*/
|
||||
async getAll(): Promise<CsoundProject[]> {
|
||||
async getAll(): Promise<File[]> {
|
||||
const db = await this.ensureDb();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -105,34 +106,34 @@ class ProjectDatabase {
|
||||
};
|
||||
|
||||
request.onerror = () => {
|
||||
reject(new Error(`Failed to get all projects: ${request.error?.message}`));
|
||||
reject(new Error(`Failed to get all files: ${request.error?.message}`));
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Save or update a project
|
||||
* Save or update a file
|
||||
*/
|
||||
async put(project: CsoundProject): Promise<void> {
|
||||
async put(file: File): Promise<void> {
|
||||
const db = await this.ensureDb();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction([STORE_NAME], 'readwrite');
|
||||
const store = transaction.objectStore(STORE_NAME);
|
||||
const request = store.put(project);
|
||||
const request = store.put(file);
|
||||
|
||||
request.onsuccess = () => {
|
||||
resolve();
|
||||
};
|
||||
|
||||
request.onerror = () => {
|
||||
reject(new Error(`Failed to save project: ${request.error?.message}`));
|
||||
reject(new Error(`Failed to save file: ${request.error?.message}`));
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a project by ID
|
||||
* Delete a file by ID
|
||||
*/
|
||||
async delete(id: string): Promise<void> {
|
||||
const db = await this.ensureDb();
|
||||
@ -147,57 +148,13 @@ class ProjectDatabase {
|
||||
};
|
||||
|
||||
request.onerror = () => {
|
||||
reject(new Error(`Failed to delete project: ${request.error?.message}`));
|
||||
reject(new Error(`Failed to delete file: ${request.error?.message}`));
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Search projects by tag
|
||||
*/
|
||||
async getByTag(tag: string): Promise<CsoundProject[]> {
|
||||
const db = await this.ensureDb();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction([STORE_NAME], 'readonly');
|
||||
const store = transaction.objectStore(STORE_NAME);
|
||||
const index = store.index('tags');
|
||||
const request = index.getAll(tag);
|
||||
|
||||
request.onsuccess = () => {
|
||||
resolve(request.result || []);
|
||||
};
|
||||
|
||||
request.onerror = () => {
|
||||
reject(new Error(`Failed to get projects by tag: ${request.error?.message}`));
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Search projects by author
|
||||
*/
|
||||
async getByAuthor(author: string): Promise<CsoundProject[]> {
|
||||
const db = await this.ensureDb();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction([STORE_NAME], 'readonly');
|
||||
const store = transaction.objectStore(STORE_NAME);
|
||||
const index = store.index('author');
|
||||
const request = index.getAll(author);
|
||||
|
||||
request.onsuccess = () => {
|
||||
resolve(request.result || []);
|
||||
};
|
||||
|
||||
request.onerror = () => {
|
||||
reject(new Error(`Failed to get projects by author: ${request.error?.message}`));
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all projects (use with caution!)
|
||||
* Clear all files (use with caution!)
|
||||
*/
|
||||
async clear(): Promise<void> {
|
||||
const db = await this.ensureDb();
|
||||
@ -212,7 +169,7 @@ class ProjectDatabase {
|
||||
};
|
||||
|
||||
request.onerror = () => {
|
||||
reject(new Error(`Failed to clear projects: ${request.error?.message}`));
|
||||
reject(new Error(`Failed to clear files: ${request.error?.message}`));
|
||||
};
|
||||
});
|
||||
}
|
||||
@ -229,4 +186,4 @@ class ProjectDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
export { ProjectDatabase };
|
||||
export { FileDatabase };
|
||||
|
||||
Reference in New Issue
Block a user