MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / getModelsFilteredHandler

Function getModelsFilteredHandler

main.js:3522–3799  ·  view source on GitHub ↗
(event, filters)

Source from the content-addressed store, hash-verified

3520 cancelId: 1,
3521 });
3522
3523 // If user clicked "Skip", return 0 without deleting
3524 if (result.response === 1) {
3525 console.log(`User skipped removal of ${filesToDelete.length} non-existent files from directory ${scanDirectoryPath}`);
3526 return 0;
3527 }
3528 }
3529 }
3530
3531 // Proceed with deletion if user confirmed or if there were no files to delete
3532 let removedCount = 0;
3533 db.transaction(() => {
3534 for (const fileInfo of filesToDelete) {
3535 // First delete from model_tags (child table)
3536 deleteModelJunctionRows(fileInfo.id);
3537
3538 // Then delete from models (parent table)
3539 db.prepare('DELETE FROM models WHERE id = ?').run(fileInfo.id);
3540
3541 removedCount++;
3542 }
3543 })();
3544
3545 if (removedCount > 0) {
3546 console.log(`Removed ${removedCount} non-existent files from directory ${scanDirectoryPath}`);
3547 }
3548
3549 return removedCount;
3550 } catch (error) {
3551 console.error('Error removing non-existent files:', error);
3552 throw error;
3553 }
3554}
3555
3556// Update the scan-directory handler to use a more efficient scanning process
3557ipcMain.handle('scan-directory', async (event, directoryPath, options = {}) => {
3558 try {
3559 // Validate UNC path in server mode
3560 try {
3561 validateUncPath(directoryPath, 'scan-directory');
3562 } catch (validationError) {
3563 throw new Error(validationError.message);
3564 }
3565
3566 debugLog('Starting directory scan:', directoryPath);
3567 const maxFileSize = await getMaxFileSize();
3568
3569 // Read enableZipArchives and scanAdditionalFileTypes from database
3570 const zipSetting = db.prepare('SELECT value FROM settings WHERE key = ?').get('enableZipArchives');
3571 const enableZipArchives = zipSetting && zipSetting.value === '1';
3572 let scanExtensions = ['.stl', '.3mf'];
3573 try {
3574 const scanTypesSetting = db.prepare('SELECT value FROM settings WHERE key = ?').get('scanAdditionalFileTypes');
3575 if (scanTypesSetting && scanTypesSetting.value) {
3576 const selectedIds = JSON.parse(scanTypesSetting.value);
3577 if (Array.isArray(selectedIds)) scanExtensions = getScanExtensions(selectedIds);
3578 }
3579 } catch (e) { /* ignore */ }

Callers

nothing calls this directly

Calls 7

normalizeFilterValueListFunction · 0.85
compileSearchTokensToSQLFunction · 0.85
pushSearchClauseFragmentFunction · 0.85
pushTagListSQLFunction · 0.85
normalizePathFunction · 0.70

Tested by

no test coverage detected