diff --git a/src/interface/desktop/config.html b/src/interface/desktop/config.html index 096102965..66c091703 100644 --- a/src/interface/desktop/config.html +++ b/src/interface/desktop/config.html @@ -69,6 +69,10 @@

+
+ + +
diff --git a/src/interface/desktop/main.js b/src/interface/desktop/main.js index 097b799cd..060eb84b4 100644 --- a/src/interface/desktop/main.js +++ b/src/interface/desktop/main.js @@ -86,7 +86,7 @@ function handleSetTitle (event, title) { }); } -function pushDataToKhoj () { +function pushDataToKhoj (regenerate = false) { let filesToPush = []; const files = store.get('files'); const folders = store.get('folders'); @@ -118,9 +118,12 @@ function pushDataToKhoj () { for (file of filesToPush) { const stats = fs.statSync(file); - if (stats.mtime.toISOString() < lastSync.find((syncedFile) => syncedFile.path === file)?.datetime) { - continue; + if (!regenerate) { + if (stats.mtime.toISOString() < lastSync.find((syncedFile) => syncedFile.path === file)?.datetime) { + continue; + } } + try { let rawData; // If the file is a PDF or IMG file, read it as a binary file @@ -166,7 +169,7 @@ function pushDataToKhoj () { const hostURL = store.get('hostURL') || KHOJ_URL; - axios.post(`${hostURL}/v1/indexer/batch`, stream, { headers }) + axios.post(`${hostURL}/v1/indexer/batch?regenerate=${regenerate}`, stream, { headers }) .then(response => { console.log(response.data); const win = BrowserWindow.getAllWindows()[0]; @@ -186,7 +189,6 @@ function pushDataToKhoj () { const win = BrowserWindow.getAllWindows()[0]; win.webContents.send('update-state', state); }); - } pushDataToKhoj(); @@ -263,9 +265,9 @@ async function removeFolder (event, folderPath) { return newFolders; } -async function syncData () { +async function syncData (regenerate = false) { try { - pushDataToKhoj(); + pushDataToKhoj(regenerate); const date = new Date(); console.log('Pushing data to Khoj at: ', date); } catch (err) { @@ -324,7 +326,9 @@ app.whenReady().then(() => { ipcMain.handle('setURL', setURL); ipcMain.handle('getURL', getURL); - ipcMain.handle('syncData', syncData); + ipcMain.handle('syncData', (event, regenerate) => { + syncData(regenerate); + }); createWindow() diff --git a/src/interface/desktop/preload.js b/src/interface/desktop/preload.js index 8b4ec59e3..a7ec09673 100644 --- a/src/interface/desktop/preload.js +++ b/src/interface/desktop/preload.js @@ -45,5 +45,5 @@ contextBridge.exposeInMainWorld('hostURLAPI', { }) contextBridge.exposeInMainWorld('syncDataAPI', { - syncData: () => ipcRenderer.invoke('syncData') + syncData: (regenerate) => ipcRenderer.invoke('syncData', regenerate) }) diff --git a/src/interface/desktop/renderer.js b/src/interface/desktop/renderer.js index a60805cbf..ad1aa573c 100644 --- a/src/interface/desktop/renderer.js +++ b/src/interface/desktop/renderer.js @@ -172,6 +172,8 @@ urlInput.addEventListener('blur', async () => { }); const syncButton = document.getElementById('sync-data'); +const syncForceToggle = document.getElementById('sync-force'); syncButton.addEventListener('click', async () => { - await window.syncDataAPI.syncData(); + const regenerate = syncForceToggle.checked; + await window.syncDataAPI.syncData(regenerate); });