You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
4.0 KiB
136 lines
4.0 KiB
3 years ago
|
import { mapState, mapActions, commit } from 'vuex'
|
||
|
import store from '@/store/index'
|
||
|
import axios from 'axios'
|
||
|
|
||
|
export default {
|
||
|
namespaced: true,
|
||
|
state: {
|
||
|
token: ''
|
||
|
},
|
||
|
getters: {
|
||
|
gettoken (state, container) {
|
||
|
return state.token
|
||
|
},
|
||
|
getlog (state, container) {
|
||
|
return state.log
|
||
|
}
|
||
|
},
|
||
|
mutations: {
|
||
|
set_token (state, data) {
|
||
|
state.token=data;
|
||
|
},
|
||
|
add_log (state, data) {
|
||
|
//console.log("js1 set "+JSON.stringify(data))
|
||
|
state.log.push(data);
|
||
|
}
|
||
|
},
|
||
|
actions: {
|
||
|
addlog({commit}, value) {
|
||
|
//console.log("container "+value)
|
||
|
var tt = {}
|
||
|
tt.message = value.log.log.message
|
||
|
tt.tailed_path = value.log.log.tailed_path
|
||
|
tt.date = value.log.date
|
||
|
commit('add_log', tt)
|
||
|
},
|
||
|
settoken({commit}, value) {
|
||
|
//console.log("container "+value)
|
||
|
commit('set_token', value.token)
|
||
|
},
|
||
|
async swarmlabstart({commit,rootGetters}, value) {
|
||
|
console.log('from '+JSON.stringify(value))
|
||
|
try {
|
||
|
var token = value.token
|
||
|
var params = {
|
||
|
action: value.action,
|
||
|
}
|
||
|
var options = {
|
||
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
|
||
|
};
|
||
|
var p = await axios.post('http://localhost:8084/run',params,options);
|
||
|
//console.log(value.token)
|
||
|
//console.log(value.swarmlabname)
|
||
|
console.log(JSON.stringify(p))
|
||
|
} catch (e) {
|
||
|
if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){
|
||
|
//console.log('error '+JSON.stringify(e))
|
||
|
window.location.href = 'https://api-login.swarmlab.io:8089';
|
||
|
}else{
|
||
|
var R = {
|
||
|
ERROR_str: e,
|
||
|
ERROR: 'yes'
|
||
|
}
|
||
|
return R;
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
async swarmlabhybridrm({commit,rootGetters}, value) {
|
||
|
try {
|
||
|
var token = value.token
|
||
|
var params = {
|
||
|
action: value.action,
|
||
|
nodename: value.nodename,
|
||
|
nodeip: value.nodeip,
|
||
|
nodeid: value.nodeid,
|
||
|
noderole: value.noderole,
|
||
|
nodezones: value.nodezones,
|
||
|
nodedesc: value.nodedesc
|
||
|
}
|
||
|
var options = {
|
||
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
|
||
|
};
|
||
|
var p = await axios.post('https://api.swarmlab.io/swarmlabhybridrm',params,options);
|
||
|
if(p.error == "invalid_token"){
|
||
|
console.log(p)
|
||
|
console.log(JSON.stringify(p))
|
||
|
}else{
|
||
|
}
|
||
|
//console.log(value.token)
|
||
|
//console.log(value.swarmlabname)
|
||
|
console.log(JSON.stringify(p))
|
||
|
} catch (e) {
|
||
|
if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){
|
||
|
//console.log('error '+JSON.stringify(e))
|
||
|
window.location.href = 'https://api-login.swarmlab.io:8089';
|
||
|
}else{
|
||
|
var R = {
|
||
|
ERROR_str: e,
|
||
|
ERROR: 'yes'
|
||
|
}
|
||
|
return R;
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
async swarmlabstartget({commit,rootGetters}, value) {
|
||
|
console.log('value '+JSON.stringify(value))
|
||
|
try {
|
||
|
var token = value.token
|
||
|
var params = {
|
||
|
action: value.action
|
||
|
}
|
||
|
var options = {
|
||
|
params: params,
|
||
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
|
||
|
};
|
||
|
var p = await axios.get('http://localhost:8084/run',options);
|
||
|
return p
|
||
|
//console.log(JSON.stringify(p))
|
||
|
//console.log(value.token)
|
||
|
//console.log(value.swarmlabname)
|
||
|
} catch (e) {
|
||
|
if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){
|
||
|
//console.log('error '+JSON.stringify(e))
|
||
|
window.location.href = 'https://api-login.swarmlab.io:8089';
|
||
|
}else{
|
||
|
var R = {
|
||
|
ERROR_str: e,
|
||
|
ERROR: 'yes'
|
||
|
}
|
||
|
return R;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|