forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
93 lines (86 loc) · 3.81 KB
/
server.ts
File metadata and controls
93 lines (86 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// @ts-ignore
import route from '../../../../../vendor/tightenco/ziggy/src/js/route';
import {ActionContext} from "vuex";
import {ServerData} from "@/models/server";
import {ServerApplicationCredentials, ServerState} from "../types";
export default {
namespaced: true,
state: {
server: {},
credentials: {node: '', key: ''},
console: [],
fm: {
currentDirectory: '/',
},
},
getters: {},
actions: {
/**
* Fetches the active server from the API and stores it in vuex.
*/
getServer: ({commit}: ActionContext<ServerState, any>, {server}: { server: string }): Promise<void> => {
return new Promise((resolve, reject) => {
// @ts-ignore
window.axios.get(route('api.client.servers.view', {server}))
// @ts-ignore
.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);
});
},
/**
* Get authentication credentials that the client should use when connecting to the daemon to
* retrieve server information.
*/
getCredentials: ({commit}: ActionContext<ServerState, any>, {server}: { server: string }) => {
return new Promise((resolve, reject) => {
// @ts-ignore
window.axios.get(route('server.credentials', {server}))
// @ts-ignore
.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);
});
},
/**
* 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);
},
},
mutations: {
SET_CURRENT_DIRECTORY: function (state: ServerState, directory: string) {
state.fm.currentDirectory = directory;
},
SERVER_DATA: function (state: ServerState, data: ServerData) {
state.server = data;
},
SERVER_CREDENTIALS: function (state: ServerState, credentials: ServerApplicationCredentials) {
state.credentials = credentials;
},
CONSOLE_DATA: function (state: ServerState, data: string) {
state.console.push(data);
},
},
}