fix: import now does something and project folders are managed correctly

This commit is contained in:
2026-02-10 22:09:26 +01:00
parent 429e70ced5
commit e4cf0d333f
3 changed files with 38 additions and 15 deletions

View File

@@ -29,9 +29,9 @@ export class ProjectEngine extends EventEmitter {
.replace(/^-|-$/g, '');
}
private async ensureProjectDirectories(slug: string): Promise<void> {
private async ensureProjectDirectories(projectId: string): Promise<void> {
const userDataPath = app.getPath('userData');
const projectDir = path.join(userDataPath, 'projects', slug);
const projectDir = path.join(userDataPath, 'projects', projectId);
const postsDir = path.join(projectDir, 'posts');
const mediaDir = path.join(projectDir, 'media');
@@ -66,8 +66,8 @@ export class ProjectEngine extends EventEmitter {
isActive: false,
};
// Create directories
await this.ensureProjectDirectories(finalSlug);
// Create directories using project ID (not slug)
await this.ensureProjectDirectories(id);
// Insert into database
const dbProject: NewProject = {
@@ -219,11 +219,11 @@ export class ProjectEngine extends EventEmitter {
return project;
}
getProjectPaths(projectSlug: string): { posts: string; media: string } {
getProjectPaths(projectId: string): { posts: string; media: string } {
const userDataPath = app.getPath('userData');
return {
posts: path.join(userDataPath, 'projects', projectSlug, 'posts'),
media: path.join(userDataPath, 'projects', projectSlug, 'media'),
posts: path.join(userDataPath, 'projects', projectId, 'posts'),
media: path.join(userDataPath, 'projects', projectId, 'media'),
};
}
}

View File

@@ -130,7 +130,13 @@ export function registerIpcHandlers(): void {
});
ipcMain.handle('posts:rebuildFromFiles', async () => {
// Ensure project context is current before rebuilding
const projectEngine = getProjectEngine();
const project = await projectEngine.getActiveProject();
const engine = getPostEngine();
if (project) {
engine.setProjectContext(project.id);
}
return engine.rebuildDatabaseFromFiles();
});
@@ -231,7 +237,13 @@ export function registerIpcHandlers(): void {
});
ipcMain.handle('media:rebuildFromFiles', async () => {
// Ensure project context is current before rebuilding
const projectEngine = getProjectEngine();
const project = await projectEngine.getActiveProject();
const engine = getMediaEngine();
if (project) {
engine.setProjectContext(project.id);
}
return engine.rebuildDatabaseFromFiles();
});
@@ -373,7 +385,16 @@ export function registerIpcHandlers(): void {
// ============ App Handlers ============
ipcMain.handle('app:getDataPaths', async () => {
return getDatabase().getDataPaths();
// Get paths for the active project
const projectEngine = getProjectEngine();
const activeProject = await projectEngine.getActiveProject();
const projectId = activeProject?.id || 'default';
const paths = projectEngine.getProjectPaths(projectId);
return {
database: getDatabase().getDataPaths().database,
posts: paths.posts,
media: paths.media,
};
});
ipcMain.handle('app:openFolder', async (_, folderPath: string) => {