mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 14:46:01 +00:00
electron app starting
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
import localforage from 'localforage';
|
||||
import _ from 'lodash';
|
||||
import { openedTabs } from '../stores';
|
||||
import { getLocalStorage, setLocalStorage } from './storageCache';
|
||||
|
||||
let counter = 0;
|
||||
|
||||
@@ -21,7 +21,7 @@ export async function alterDatabaseDialog(conid, database, updateFunc) {
|
||||
sql,
|
||||
recreates,
|
||||
onConfirm: async () => {
|
||||
const resp = await axiosInstance.request({
|
||||
const resp = await axiosInstance().request({
|
||||
url: 'database-connections/run-script',
|
||||
method: 'post',
|
||||
params: {
|
||||
@@ -30,7 +30,7 @@ export async function alterDatabaseDialog(conid, database, updateFunc) {
|
||||
},
|
||||
data: { sql },
|
||||
});
|
||||
await axiosInstance.post('database-connections/sync-model', { conid, database });
|
||||
await axiosInstance().post('database-connections/sync-model', { conid, database });
|
||||
},
|
||||
engine: driver.engine,
|
||||
});
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import axios from 'axios';
|
||||
import resolveApi, { resolveApiHeaders } from './resolveApi';
|
||||
|
||||
let axiosInstance;
|
||||
let instance;
|
||||
|
||||
function recreateAxiosInstance() {
|
||||
axiosInstance = axios.create({
|
||||
instance = axios.create({
|
||||
baseURL: resolveApi(),
|
||||
});
|
||||
|
||||
axiosInstance.defaults.headers = {
|
||||
instance.defaults.headers = {
|
||||
'Cache-Control': 'no-cache',
|
||||
Pragma: 'no-cache',
|
||||
Expires: '0',
|
||||
@@ -20,4 +20,6 @@ window['dbgate_recreateAxiosInstance'] = recreateAxiosInstance;
|
||||
|
||||
recreateAxiosInstance();
|
||||
|
||||
export default axiosInstance;
|
||||
export default function axiosInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ import { openedConnections, currentDatabase } from '../stores';
|
||||
import axiosInstance from './axiosInstance';
|
||||
|
||||
const doServerPing = value => {
|
||||
axiosInstance.post('server-connections/ping', { connections: value });
|
||||
axiosInstance().post('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 });
|
||||
axiosInstance().post('database-connections/ping', { conid, database });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function exportElectronFile(dataName, reader, format) {
|
||||
script.copyStream(sourceVar, targetVar);
|
||||
script.put();
|
||||
|
||||
const resp = await axiosInstance.post('runners/start', { script: script.getScript() });
|
||||
const resp = await axiosInstance().post('runners/start', { script: script.getScript() });
|
||||
const runid = resp.data.runid;
|
||||
let isCanceled = false;
|
||||
|
||||
@@ -40,7 +40,7 @@ export async function exportElectronFile(dataName, reader, format) {
|
||||
label: 'Cancel',
|
||||
onClick: () => {
|
||||
isCanceled = true;
|
||||
axiosInstance.post('runners/cancel', { runid });
|
||||
axiosInstance().post('runners/cancel', { runid });
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -74,7 +74,7 @@ export async function saveFileToDisk(
|
||||
await filePathFunc(filePath);
|
||||
electron.shell.openExternal('file:///' + filePath);
|
||||
} else {
|
||||
const resp = await axiosInstance.get('files/generate-uploads-file');
|
||||
const resp = await axiosInstance().get('files/generate-uploads-file');
|
||||
await filePathFunc(resp.data.filePath);
|
||||
window.open(`${resolveApi()}/uploads/get?file=${resp.data.fileName}`, '_blank');
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ async function getCore(loader, args) {
|
||||
const key = stableStringify({ url, ...params });
|
||||
|
||||
async function doLoad() {
|
||||
const resp = await axiosInstance.request({
|
||||
const resp = await axiosInstance().request({
|
||||
method: 'get',
|
||||
url,
|
||||
params,
|
||||
@@ -169,7 +169,7 @@ function useCore(loader, args) {
|
||||
subscribe: onChange => {
|
||||
async function handleReload() {
|
||||
async function doLoad() {
|
||||
const resp = await axiosInstance.request({
|
||||
const resp = await axiosInstance().request({
|
||||
method: 'get',
|
||||
params,
|
||||
url,
|
||||
|
||||
@@ -12,7 +12,7 @@ export async function openArchiveFolder() {
|
||||
});
|
||||
const linkedFolder = filePaths && filePaths[0];
|
||||
if (!linkedFolder) return;
|
||||
const resp = await axiosInstance.post('archive/create-link', { linkedFolder });
|
||||
const resp = await axiosInstance().post('archive/create-link', { linkedFolder });
|
||||
|
||||
currentArchive.set(resp.data);
|
||||
selectedWidget.set('archive');
|
||||
|
||||
@@ -21,7 +21,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 axiosInstance().post('connections/save', {
|
||||
_id: undefined,
|
||||
databaseFile: filePath,
|
||||
engine: 'sqlite@dbgate-plugin-sqlite',
|
||||
|
||||
@@ -18,10 +18,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 axiosInstance().post('files/save', { folder: savedFolder || folder, file: savedFile, data, format });
|
||||
}
|
||||
if (savedFilePath) {
|
||||
await axiosInstance.post('files/save-as', { filePath: savedFilePath, data, format });
|
||||
await axiosInstance().post('files/save-as', { filePath: savedFilePath, data, format });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user