(path, size)
| 7297 | |
| 7298 | // Update these handlers to remove Promise wrappers and use synchronous API |
| 7299 | |
| 7300 | ipcMain.handle('get-duplicate-files', async () => { |
| 7301 | try { |
| 7302 | const models = db.prepare(` |
| 7303 | SELECT filePath, hash, size, |
| 7304 | CASE WHEN thumbnail IS NOT NULL AND thumbnail != '' AND thumbnail != '3d.png' THEN 1 ELSE 0 END AS hasThumbnail |
| 7305 | FROM models WHERE hash IS NOT NULL |
| 7306 | `).all(); |
| 7307 | |
| 7308 | // Group files by hash |
| 7309 | const duplicates = {}; |
| 7310 | for (const model of models) { |
| 7311 | if (!model.hash) continue; |
| 7312 | |
| 7313 | if (!duplicates[model.hash]) { |
| 7314 | duplicates[model.hash] = []; |
| 7315 | } |
| 7316 | duplicates[model.hash].push({ |
| 7317 | filePath: model.filePath, |
| 7318 | size: model.size, |
| 7319 | hasThumbnail: model.hasThumbnail === 1 |
| 7320 | }); |
| 7321 | } |
| 7322 | |
| 7323 | // Filter out unique files |
| 7324 | return Object.fromEntries( |
| 7325 | Object.entries(duplicates).filter(([_, files]) => files.length > 1) |
| 7326 | ); |
| 7327 | } catch (error) { |
| 7328 | console.error('Error getting duplicate files:', error); |
| 7329 | throw error; |
| 7330 | } |
| 7331 | }); |
| 7332 | |
| 7333 | // Add this new handler |
| 7334 | ipcMain.handle('check-files-exist', async (_, filePaths) => { |
| 7335 | const results = await Promise.all(filePaths.map(async (path) => { |
| 7336 | if (isUrlModel(path)) { |
| 7337 | return { path, exists: true }; |
| 7338 | } |
| 7339 | try { |
| 7340 | await fs.promises.access(path, fs.constants.F_OK); |
| 7341 | return { |
| 7342 | path, |
| 7343 | exists: true |
| 7344 | }; |
| 7345 | } catch { |
| 7346 | return { |
| 7347 | path, |
| 7348 | exists: false |
| 7349 | }; |
| 7350 | } |
no test coverage detected