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">
|
<div class="card-description-row">
|
||||||
<button id="sync-data">Sync</button>
|
<button id="sync-data">Sync</button>
|
||||||
</div>
|
</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 class="card-description-row">
|
||||||
<div id="sync-status"></div>
|
<div id="sync-status"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -86,7 +86,7 @@ function handleSetTitle (event, title) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function pushDataToKhoj () {
|
function pushDataToKhoj (regenerate = false) {
|
||||||
let filesToPush = [];
|
let filesToPush = [];
|
||||||
const files = store.get('files');
|
const files = store.get('files');
|
||||||
const folders = store.get('folders');
|
const folders = store.get('folders');
|
||||||
|
@ -118,9 +118,12 @@ function pushDataToKhoj () {
|
||||||
|
|
||||||
for (file of filesToPush) {
|
for (file of filesToPush) {
|
||||||
const stats = fs.statSync(file);
|
const stats = fs.statSync(file);
|
||||||
if (stats.mtime.toISOString() < lastSync.find((syncedFile) => syncedFile.path === file)?.datetime) {
|
if (!regenerate) {
|
||||||
continue;
|
if (stats.mtime.toISOString() < lastSync.find((syncedFile) => syncedFile.path === file)?.datetime) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let rawData;
|
let rawData;
|
||||||
// If the file is a PDF or IMG file, read it as a binary file
|
// 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;
|
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 => {
|
.then(response => {
|
||||||
console.log(response.data);
|
console.log(response.data);
|
||||||
const win = BrowserWindow.getAllWindows()[0];
|
const win = BrowserWindow.getAllWindows()[0];
|
||||||
|
@ -186,7 +189,6 @@ function pushDataToKhoj () {
|
||||||
const win = BrowserWindow.getAllWindows()[0];
|
const win = BrowserWindow.getAllWindows()[0];
|
||||||
win.webContents.send('update-state', state);
|
win.webContents.send('update-state', state);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pushDataToKhoj();
|
pushDataToKhoj();
|
||||||
|
@ -263,9 +265,9 @@ async function removeFolder (event, folderPath) {
|
||||||
return newFolders;
|
return newFolders;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function syncData () {
|
async function syncData (regenerate = false) {
|
||||||
try {
|
try {
|
||||||
pushDataToKhoj();
|
pushDataToKhoj(regenerate);
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
console.log('Pushing data to Khoj at: ', date);
|
console.log('Pushing data to Khoj at: ', date);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -324,7 +326,9 @@ app.whenReady().then(() => {
|
||||||
ipcMain.handle('setURL', setURL);
|
ipcMain.handle('setURL', setURL);
|
||||||
ipcMain.handle('getURL', getURL);
|
ipcMain.handle('getURL', getURL);
|
||||||
|
|
||||||
ipcMain.handle('syncData', syncData);
|
ipcMain.handle('syncData', (event, regenerate) => {
|
||||||
|
syncData(regenerate);
|
||||||
|
});
|
||||||
|
|
||||||
createWindow()
|
createWindow()
|
||||||
|
|
||||||
|
|
|
@ -45,5 +45,5 @@ contextBridge.exposeInMainWorld('hostURLAPI', {
|
||||||
})
|
})
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld('syncDataAPI', {
|
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 syncButton = document.getElementById('sync-data');
|
||||||
|
const syncForceToggle = document.getElementById('sync-force');
|
||||||
syncButton.addEventListener('click', async () => {
|
syncButton.addEventListener('click', async () => {
|
||||||
await window.syncDataAPI.syncData();
|
const regenerate = syncForceToggle.checked;
|
||||||
|
await window.syncDataAPI.syncData(regenerate);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue