feat: added dataPath for projects
This commit is contained in:
@@ -5,6 +5,7 @@ import { getDatabase } from './database';
|
||||
import { registerIpcHandlers, registerChatHandlers, initializeChatHandlers, cleanupChatHandlers } from './ipc';
|
||||
import { media } from './database/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { getMediaEngine } from './engine/MediaEngine';
|
||||
|
||||
let mainWindow: BrowserWindow | null = null;
|
||||
|
||||
@@ -22,6 +23,15 @@ protocol.registerSchemesAsPrivileged([
|
||||
corsEnabled: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
scheme: 'bds-thumb',
|
||||
privileges: {
|
||||
standard: true,
|
||||
secure: true,
|
||||
supportFetchAPI: true,
|
||||
corsEnabled: true,
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
function createWindow(): void {
|
||||
@@ -383,6 +393,39 @@ async function initialize(): Promise<void> {
|
||||
}
|
||||
});
|
||||
|
||||
// Register custom protocol for serving thumbnail images
|
||||
// URLs like bds-thumb://media-id will serve the small thumbnail webp
|
||||
protocol.handle('bds-thumb', async (request) => {
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const mediaId = url.hostname;
|
||||
|
||||
const engine = getMediaEngine();
|
||||
const thumbnails = await engine.getThumbnailPaths(mediaId);
|
||||
|
||||
if (thumbnails.small) {
|
||||
return net.fetch(`file://${thumbnails.small}`);
|
||||
}
|
||||
|
||||
// Fallback to full image if thumbnail doesn't exist
|
||||
const database = getDatabase().getLocal();
|
||||
const mediaItem = await database
|
||||
.select()
|
||||
.from(media)
|
||||
.where(eq(media.id, mediaId))
|
||||
.get();
|
||||
|
||||
if (mediaItem && mediaItem.filePath) {
|
||||
return net.fetch(`file://${mediaItem.filePath}`);
|
||||
}
|
||||
|
||||
return new Response('Thumbnail not found', { status: 404 });
|
||||
} catch (error) {
|
||||
console.error('Error serving thumbnail:', error);
|
||||
return new Response('Internal server error', { status: 500 });
|
||||
}
|
||||
});
|
||||
|
||||
// Register IPC handlers
|
||||
registerIpcHandlers();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user