Added libs
This commit is contained in:
126
noSys/vue/api/noSysApi.js
Normal file
126
noSys/vue/api/noSysApi.js
Normal file
@@ -0,0 +1,126 @@
|
||||
import { useNoSysStore } from '../stores/noSysStore'
|
||||
|
||||
const noSysApiUrl = "/api/noSys";
|
||||
const noSysStore = useNoSysStore()
|
||||
|
||||
export const noSysApi = {
|
||||
|
||||
async getUsers(){
|
||||
let users = {}
|
||||
try {
|
||||
const response = await fetch(noSysApiUrl+'/users')
|
||||
if (!response.ok) throw new Error("Error fetching users:")
|
||||
users = await response.json()
|
||||
return users;
|
||||
} catch (error) {
|
||||
console.error("Error fetching users:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
async getUser(userId){
|
||||
let user = {}
|
||||
try {
|
||||
const response = await fetch(noSysApiUrl+'/users/'+userId)
|
||||
if (!response.ok) throw new Error("Error fetching users:")
|
||||
user = await response.json()
|
||||
return user;
|
||||
} catch (error) {
|
||||
console.error("Error fetching users:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
async getConfigs(){
|
||||
try {
|
||||
const response = await fetch(noSysApiUrl+'/configs')
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Error fetching configs: ${response.status} - ${errorText}`);
|
||||
}
|
||||
const result = await response.json()
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("Error fetching configs:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
async connectAddress(user, ip, port){
|
||||
const data = {"user": user, "address": {"ip": ip,"port": port}};
|
||||
const requestOptions = {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json',},
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
try {
|
||||
const response = await fetch(noSysApiUrl+"/peers", requestOptions);
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Error fetching users: ${response.status} - ${errorText}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
return result;
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error fetching users:", error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
async listPeers(){
|
||||
try {
|
||||
const response = await fetch(noSysApiUrl+'/peers')
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Error fetching peers: ${response.status} - ${errorText}`);
|
||||
}
|
||||
const result = await response.json()
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("Error fetching peers:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
async disconnectPeer(connectionId){
|
||||
const data = {};
|
||||
const requestOptions = {
|
||||
method: 'DELETE',
|
||||
headers: {'Content-Type': 'application/json',},
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
try {
|
||||
const response = await fetch(noSysApiUrl+"/peers/"+connectionId, requestOptions);
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Error fetching users: ${response.status} - ${errorText}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
return result;
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error fetching users:", error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
async listNetworks(){
|
||||
try {
|
||||
const response = await fetch(noSysApiUrl+'/networks')
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Error fetching networks: ${response.status} - ${errorText}`);
|
||||
}
|
||||
const result = await response.json()
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("Error fetching networks:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user