axiosInstance replaced with apiCall

This commit is contained in:
Jan Prochazka
2021-12-22 10:16:44 +01:00
parent 148af24b2c
commit f9c54cdce2
55 changed files with 257 additions and 328 deletions

View File

@@ -6,6 +6,7 @@ import { getExtensions } from '../stores';
import { getConnectionInfo, getDatabaseInfo } from './metadataLoaders';
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
import axiosInstance from './axiosInstance';
import { apiCall } from './api';
export async function alterDatabaseDialog(conid, database, updateFunc) {
const conn = await getConnectionInfo({ conid });
@@ -21,16 +22,8 @@ export async function alterDatabaseDialog(conid, database, updateFunc) {
sql,
recreates,
onConfirm: async () => {
const resp = await axiosInstance().request({
url: 'database-connections/run-script',
method: 'post',
params: {
conid,
database,
},
data: { sql },
});
await axiosInstance().post('database-connections/sync-model', { conid, database });
const resp = await apiCall('database-connections/run-script', { conid, database, sql });
await apiCall('database-connections/sync-model', { conid, database });
},
engine: driver.engine,
});

View File

@@ -1,16 +1,17 @@
import _ from 'lodash';
import { openedConnections, currentDatabase } from '../stores';
import { apiCall } from './api';
import axiosInstance from './axiosInstance';
const doServerPing = value => {
axiosInstance().post('server-connections/ping', { connections: value });
apiCall('server-connections/ping', { connections: value });
};
const doDatabasePing = value => {
const database = _.get(value, 'name');
const conid = _.get(value, 'connection._id');
if (conid && database) {
axiosInstance().post('database-connections/ping', { conid, database });
apiCall('database-connections/ping', { conid, database });
}
};

View File

@@ -4,6 +4,7 @@ import axiosInstance from '../utility/axiosInstance';
import socket from '../utility/socket';
import { showSnackbar, showSnackbarInfo, showSnackbarError, closeSnackbar } from '../utility/snackbar';
import resolveApi from './resolveApi';
import { apiCall } from './api';
export async function exportElectronFile(dataName, reader, format) {
const electron = getElectron();
@@ -28,8 +29,8 @@ export async function exportElectronFile(dataName, reader, format) {
script.copyStream(sourceVar, targetVar);
script.put();
const resp = await axiosInstance().post('runners/start', { script: script.getScript() });
const runid = resp.data.runid;
const resp = await apiCall('runners/start', { script: script.getScript() });
const runid = resp.runid;
let isCanceled = false;
const snackId = showSnackbar({
@@ -40,7 +41,7 @@ export async function exportElectronFile(dataName, reader, format) {
label: 'Cancel',
onClick: () => {
isCanceled = true;
axiosInstance().post('runners/cancel', { runid });
apiCall('runners/cancel', { runid });
},
},
],
@@ -74,8 +75,8 @@ export async function saveFileToDisk(
await filePathFunc(filePath);
electron.openExternal('file:///' + filePath);
} else {
const resp = await axiosInstance().get('files/generate-uploads-file');
await filePathFunc(resp.data.filePath);
window.open(`${resolveApi()}/uploads/get?file=${resp.data.fileName}`, '_blank');
const resp = await apiCall('files/generate-uploads-file');
await filePathFunc(resp.filePath);
window.open(`${resolveApi()}/uploads/get?file=${resp.fileName}`, '_blank');
}
}

View File

@@ -3,6 +3,7 @@ import getElectron from './getElectron';
import { currentArchive, extensions, selectedWidget } from '../stores';
import axiosInstance from '../utility/axiosInstance';
import { showSnackbarSuccess } from './snackbar';
import { apiCall } from './api';
export async function openArchiveFolder() {
const electron = getElectron();
@@ -12,9 +13,9 @@ export async function openArchiveFolder() {
});
const linkedFolder = filePaths && filePaths[0];
if (!linkedFolder) return;
const resp = await axiosInstance().post('archive/create-link', { linkedFolder });
const resp = await apiCall('archive/create-link', { linkedFolder });
currentArchive.set(resp.data);
currentArchive.set(resp);
selectedWidget.set('archive');
showSnackbarSuccess(`Created link ${resp.data}`);
showSnackbarSuccess(`Created link ${resp}`);
}

View File

@@ -7,6 +7,7 @@ import { currentDatabase, extensions } from '../stores';
import { getUploadListener } from './uploadFiles';
import axiosInstance from '../utility/axiosInstance';
import { getDatabaseFileLabel } from './getConnectionLabel';
import { apiCall } from './api';
export function canOpenByElectron(file, extensions) {
if (!file) return false;
@@ -21,7 +22,7 @@ export function canOpenByElectron(file, extensions) {
export async function openSqliteFile(filePath) {
const defaultDatabase = getDatabaseFileLabel(filePath);
const resp = await axiosInstance().post('connections/save', {
const resp = await apiCall('connections/save', {
_id: undefined,
databaseFile: filePath,
engine: 'sqlite@dbgate-plugin-sqlite',
@@ -29,7 +30,7 @@ export async function openSqliteFile(filePath) {
defaultDatabase,
});
currentDatabase.set({
connection: resp.data,
connection: resp,
name: getDatabaseFileLabel(filePath),
});
}

View File

@@ -5,6 +5,7 @@ import axiosInstance from '../utility/axiosInstance';
import { changeTab } from './common';
import SaveFileModal from '../modals/SaveFileModal.svelte';
import registerCommand from '../commands/registerCommand';
import { apiCall } from './api';
// export function saveTabEnabledStore(editorStore) {
// return derived(editorStore, editor => editor != null);
@@ -18,10 +19,10 @@ export default function saveTabFile(editor, saveAs, folder, format, fileExtensio
const handleSave = async () => {
if (savedFile) {
await axiosInstance().post('files/save', { folder: savedFolder || folder, file: savedFile, data, format });
await apiCall('files/save', { folder: savedFolder || folder, file: savedFile, data, format });
}
if (savedFilePath) {
await axiosInstance().post('files/save-as', { filePath: savedFilePath, data, format });
await apiCall('files/save-as', { filePath: savedFilePath, data, format });
}
};