mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Fix/auto-backup (#6176)
* disable on change * fix bug and try catch backup * remove delay
This commit is contained in:
parent
bb638b5e94
commit
e000001055
@ -1,4 +1,4 @@
|
||||
import fs, { mkdir } from 'node:fs/promises';
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
import electron from 'electron';
|
||||
@ -11,17 +11,22 @@ import { isGrpcRequest } from '../models/grpc-request';
|
||||
import { isRequest } from '../models/request';
|
||||
import { isWebSocketRequest } from '../models/websocket-request';
|
||||
export async function exportAllWorkspaces() {
|
||||
const projects = await models.project.all();
|
||||
await Promise.all(projects.map(async project => {
|
||||
const dataPath = process.env['INSOMNIA_DATA_PATH'] || electron.app.getPath('userData');
|
||||
const versionPath = path.join(dataPath, 'backups', version);
|
||||
await mkdir(versionPath, { recursive: true });
|
||||
const fileName = path.join(versionPath, `${project.name}.insomnia.json`);
|
||||
const workspaces = await models.workspace.findByParentId(project._id);
|
||||
const docs = await Promise.all(workspaces.map(parentDoc => db.withDescendants(parentDoc)));
|
||||
const requests = docs.flat().filter(doc => isRequest(doc) || isGrpcRequest(doc) || isWebSocketRequest(doc));
|
||||
const stringifiedExport = await exportRequestsData(requests, true, 'json');
|
||||
await fs.writeFile(fileName, stringifiedExport);
|
||||
console.log('Exported project backup to:', fileName);
|
||||
}));
|
||||
try {
|
||||
const projects = await models.project.all();
|
||||
await Promise.all(projects.map(async project => {
|
||||
const dataPath = process.env['INSOMNIA_DATA_PATH'] || electron.app.getPath('userData');
|
||||
const versionPath = path.join(dataPath, 'backups', version);
|
||||
await mkdir(versionPath, { recursive: true });
|
||||
const fileName = path.join(versionPath, `${project.name}.insomnia.json`);
|
||||
const workspaces = await models.workspace.findByParentId(project._id);
|
||||
const docs = await Promise.all(workspaces.map(parentDoc => db.withDescendants(parentDoc)));
|
||||
const requests = docs.flat().filter(doc => isRequest(doc) || isGrpcRequest(doc) || isWebSocketRequest(doc));
|
||||
const stringifiedExport = await exportRequestsData(requests, true, 'json');
|
||||
await writeFile(fileName, stringifiedExport);
|
||||
console.log('Exported project backup to:', fileName);
|
||||
}
|
||||
));
|
||||
} catch (err) {
|
||||
console.log('Error exporting project backup:', err);
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,6 @@ export const init = async () => {
|
||||
console.log(`[updater] Downloaded ${releaseName}`);
|
||||
_sendUpdateStatus('Performing backup...');
|
||||
await exportAllWorkspaces();
|
||||
await delay(1000 * 10); // Workaround early restart issues
|
||||
_sendUpdateStatus('Updated (Restart Required)');
|
||||
|
||||
dialog.showMessageBox({
|
||||
|
@ -19,7 +19,7 @@ export const CheckForUpdatesButton: FC<Props> = ({ children, className }) => {
|
||||
return (
|
||||
<button
|
||||
className={className ?? ''}
|
||||
disabled={disabled}
|
||||
disabled={disabled || status !== 'Check now'}
|
||||
onClick={() => {
|
||||
window.main.manualUpdateCheck();
|
||||
// this is to prevent initiating update multiple times
|
||||
|
Loading…
Reference in New Issue
Block a user