fix: import now does something and project folders are managed correctly
This commit is contained in:
@@ -29,9 +29,9 @@ export class ProjectEngine extends EventEmitter {
|
|||||||
.replace(/^-|-$/g, '');
|
.replace(/^-|-$/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async ensureProjectDirectories(slug: string): Promise<void> {
|
private async ensureProjectDirectories(projectId: string): Promise<void> {
|
||||||
const userDataPath = app.getPath('userData');
|
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 postsDir = path.join(projectDir, 'posts');
|
||||||
const mediaDir = path.join(projectDir, 'media');
|
const mediaDir = path.join(projectDir, 'media');
|
||||||
|
|
||||||
@@ -66,8 +66,8 @@ export class ProjectEngine extends EventEmitter {
|
|||||||
isActive: false,
|
isActive: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create directories
|
// Create directories using project ID (not slug)
|
||||||
await this.ensureProjectDirectories(finalSlug);
|
await this.ensureProjectDirectories(id);
|
||||||
|
|
||||||
// Insert into database
|
// Insert into database
|
||||||
const dbProject: NewProject = {
|
const dbProject: NewProject = {
|
||||||
@@ -219,11 +219,11 @@ export class ProjectEngine extends EventEmitter {
|
|||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
getProjectPaths(projectSlug: string): { posts: string; media: string } {
|
getProjectPaths(projectId: string): { posts: string; media: string } {
|
||||||
const userDataPath = app.getPath('userData');
|
const userDataPath = app.getPath('userData');
|
||||||
return {
|
return {
|
||||||
posts: path.join(userDataPath, 'projects', projectSlug, 'posts'),
|
posts: path.join(userDataPath, 'projects', projectId, 'posts'),
|
||||||
media: path.join(userDataPath, 'projects', projectSlug, 'media'),
|
media: path.join(userDataPath, 'projects', projectId, 'media'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,7 +130,13 @@ export function registerIpcHandlers(): void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('posts:rebuildFromFiles', async () => {
|
ipcMain.handle('posts:rebuildFromFiles', async () => {
|
||||||
|
// Ensure project context is current before rebuilding
|
||||||
|
const projectEngine = getProjectEngine();
|
||||||
|
const project = await projectEngine.getActiveProject();
|
||||||
const engine = getPostEngine();
|
const engine = getPostEngine();
|
||||||
|
if (project) {
|
||||||
|
engine.setProjectContext(project.id);
|
||||||
|
}
|
||||||
return engine.rebuildDatabaseFromFiles();
|
return engine.rebuildDatabaseFromFiles();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -231,7 +237,13 @@ export function registerIpcHandlers(): void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('media:rebuildFromFiles', async () => {
|
ipcMain.handle('media:rebuildFromFiles', async () => {
|
||||||
|
// Ensure project context is current before rebuilding
|
||||||
|
const projectEngine = getProjectEngine();
|
||||||
|
const project = await projectEngine.getActiveProject();
|
||||||
const engine = getMediaEngine();
|
const engine = getMediaEngine();
|
||||||
|
if (project) {
|
||||||
|
engine.setProjectContext(project.id);
|
||||||
|
}
|
||||||
return engine.rebuildDatabaseFromFiles();
|
return engine.rebuildDatabaseFromFiles();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -373,7 +385,16 @@ export function registerIpcHandlers(): void {
|
|||||||
// ============ App Handlers ============
|
// ============ App Handlers ============
|
||||||
|
|
||||||
ipcMain.handle('app:getDataPaths', async () => {
|
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) => {
|
ipcMain.handle('app:openFolder', async (_, folderPath: string) => {
|
||||||
|
|||||||
@@ -254,19 +254,21 @@ describe('ProjectEngine', () => {
|
|||||||
|
|
||||||
describe('getProjectPaths', () => {
|
describe('getProjectPaths', () => {
|
||||||
it('should return paths for posts and media directories', () => {
|
it('should return paths for posts and media directories', () => {
|
||||||
const paths = projectEngine.getProjectPaths('my-blog');
|
const projectId = 'test-project-id';
|
||||||
|
const paths = projectEngine.getProjectPaths(projectId);
|
||||||
|
|
||||||
expect(paths.posts).toContain('my-blog');
|
expect(paths.posts).toContain(projectId);
|
||||||
expect(paths.posts).toContain('posts');
|
expect(paths.posts).toContain('posts');
|
||||||
expect(paths.media).toContain('my-blog');
|
expect(paths.media).toContain(projectId);
|
||||||
expect(paths.media).toContain('media');
|
expect(paths.media).toContain('media');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should include project slug in paths', () => {
|
it('should include project ID in paths', () => {
|
||||||
const paths = projectEngine.getProjectPaths('custom-project');
|
const projectId = 'custom-project-uuid';
|
||||||
|
const paths = projectEngine.getProjectPaths(projectId);
|
||||||
|
|
||||||
expect(paths.posts).toContain('custom-project');
|
expect(paths.posts).toContain(projectId);
|
||||||
expect(paths.media).toContain('custom-project');
|
expect(paths.media).toContain(projectId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user