Skip to content

Commit

Permalink
Provide force fallback for regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
sabaimran committed Sep 12, 2023
1 parent 9f42a1a commit 16874e1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/interface/desktop/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ <h3 class="card-title">
<div class="card-description-row">
<button id="sync-data">Sync</button>
</div>
<div class="card-description-row sync-force-toggle">
<input id="sync-force" type="checkbox" name="sync-force" value="force">
<label for="sync-force">Force Sync</label>
</div>
<div class="card-description-row">
<div id="sync-status"></div>
</div>
Expand Down
20 changes: 12 additions & 8 deletions src/interface/desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand All @@ -186,7 +189,6 @@ function pushDataToKhoj () {
const win = BrowserWindow.getAllWindows()[0];
win.webContents.send('update-state', state);
});

}

pushDataToKhoj();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/interface/desktop/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ contextBridge.exposeInMainWorld('hostURLAPI', {
})

contextBridge.exposeInMainWorld('syncDataAPI', {
syncData: () => ipcRenderer.invoke('syncData')
syncData: (regenerate) => ipcRenderer.invoke('syncData', regenerate)
})
4 changes: 3 additions & 1 deletion src/interface/desktop/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 16874e1

Please sign in to comment.