2018-12-16 23:29:44 +00:00
|
|
|
// @ts-ignore
|
2018-06-03 22:45:01 +00:00
|
|
|
import route from '../../../../../vendor/tightenco/ziggy/src/js/route';
|
2018-12-16 23:29:44 +00:00
|
|
|
import {ActionContext} from "vuex";
|
2019-02-17 01:54:15 +00:00
|
|
|
import {ServerData} from "@/models/server";
|
2019-02-17 21:29:11 +00:00
|
|
|
import {ServerApplicationCredentials, ServerState} from "../types";
|
2018-06-03 22:45:01 +00:00
|
|
|
|
2018-07-15 23:57:00 +00:00
|
|
|
export default {
|
2018-07-19 05:48:19 +00:00
|
|
|
namespaced: true,
|
2018-06-03 22:45:01 +00:00
|
|
|
state: {
|
2018-07-19 05:48:19 +00:00
|
|
|
server: {},
|
2018-07-21 06:45:07 +00:00
|
|
|
credentials: {node: '', key: ''},
|
|
|
|
console: [],
|
2019-02-17 01:54:15 +00:00
|
|
|
fm: {
|
|
|
|
currentDirectory: '/',
|
|
|
|
},
|
2018-06-03 22:45:01 +00:00
|
|
|
},
|
2019-02-10 05:15:45 +00:00
|
|
|
getters: {},
|
2018-06-03 22:45:01 +00:00
|
|
|
actions: {
|
2018-07-19 05:48:19 +00:00
|
|
|
/**
|
2018-12-16 23:29:44 +00:00
|
|
|
* Fetches the active server from the API and stores it in vuex.
|
2018-07-19 05:48:19 +00:00
|
|
|
*/
|
2018-12-16 23:29:44 +00:00
|
|
|
getServer: ({commit}: ActionContext<ServerState, any>, {server}: { server: string }): Promise<void> => {
|
2018-07-19 05:48:19 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2018-12-16 23:29:44 +00:00
|
|
|
// @ts-ignore
|
2019-02-10 05:15:45 +00:00
|
|
|
window.axios.get(route('api.client.servers.view', {server}))
|
|
|
|
// @ts-ignore
|
2018-07-19 05:48:19 +00:00
|
|
|
.then(response => {
|
|
|
|
// If there is a 302 redirect or some other odd behavior (basically, response that isnt
|
|
|
|
// in JSON format) throw an error and don't try to continue with the login.
|
|
|
|
if (!(response.data instanceof Object)) {
|
|
|
|
return reject(new Error('An error was encountered while processing this request.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.data.object === 'server' && response.data.attributes) {
|
|
|
|
commit('SERVER_DATA', response.data.attributes)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve();
|
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
2018-06-03 22:45:01 +00:00
|
|
|
},
|
2018-07-21 06:45:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get authentication credentials that the client should use when connecting to the daemon to
|
|
|
|
* retrieve server information.
|
|
|
|
*/
|
2018-12-16 23:29:44 +00:00
|
|
|
getCredentials: ({commit}: ActionContext<ServerState, any>, {server}: { server: string }) => {
|
2018-07-21 06:45:07 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2018-12-16 23:29:44 +00:00
|
|
|
// @ts-ignore
|
2018-07-21 06:45:07 +00:00
|
|
|
window.axios.get(route('server.credentials', {server}))
|
2019-02-10 05:15:45 +00:00
|
|
|
// @ts-ignore
|
2018-07-21 06:45:07 +00:00
|
|
|
.then(response => {
|
|
|
|
// If there is a 302 redirect or some other odd behavior (basically, response that isnt
|
|
|
|
// in JSON format) throw an error and don't try to continue with the login.
|
|
|
|
if (!(response.data instanceof Object)) {
|
|
|
|
return reject(new Error('An error was encountered while processing this request.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.data.key) {
|
|
|
|
commit('SERVER_CREDENTIALS', response.data)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve();
|
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
2019-02-17 01:54:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the last viewed directory for the server the user is currently viewing. This allows
|
|
|
|
* us to quickly navigate back to that directory, as well as ensure that actions taken are
|
|
|
|
* performed aganist the correct directory without having to pass that mess everywhere.
|
|
|
|
*/
|
|
|
|
updateCurrentDirectory: ({commit}: ActionContext<ServerState, any>, directory: string) => {
|
|
|
|
commit('SET_CURRENT_DIRECTORY', directory);
|
|
|
|
},
|
2018-06-03 22:45:01 +00:00
|
|
|
},
|
2018-07-19 05:48:19 +00:00
|
|
|
mutations: {
|
2019-02-17 01:54:15 +00:00
|
|
|
SET_CURRENT_DIRECTORY: function (state: ServerState, directory: string) {
|
|
|
|
state.fm.currentDirectory = directory;
|
|
|
|
},
|
2018-12-16 23:29:44 +00:00
|
|
|
SERVER_DATA: function (state: ServerState, data: ServerData) {
|
2018-07-19 05:48:19 +00:00
|
|
|
state.server = data;
|
2018-07-21 06:45:07 +00:00
|
|
|
},
|
2018-12-16 23:29:44 +00:00
|
|
|
SERVER_CREDENTIALS: function (state: ServerState, credentials: ServerApplicationCredentials) {
|
2018-07-21 06:45:07 +00:00
|
|
|
state.credentials = credentials;
|
|
|
|
},
|
2018-12-16 23:29:44 +00:00
|
|
|
CONSOLE_DATA: function (state: ServerState, data: string) {
|
2018-07-21 06:45:07 +00:00
|
|
|
state.console.push(data);
|
|
|
|
},
|
2018-07-19 05:48:19 +00:00
|
|
|
},
|
|
|
|
}
|