mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Provide force fallback for regeneration
This commit is contained in:
parent
9f42a1a036
commit
16874e1953
4 changed files with 20 additions and 10 deletions
|
@ -69,6 +69,10 @@
|
|||
<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>
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -45,5 +45,5 @@ contextBridge.exposeInMainWorld('hostURLAPI', {
|
|||
})
|
||||
|
||||
contextBridge.exposeInMainWorld('syncDataAPI', {
|
||||
syncData: () => ipcRenderer.invoke('syncData')
|
||||
syncData: (regenerate) => ipcRenderer.invoke('syncData', regenerate)
|
||||
})
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue