First version of vuejs terminal

This commit is contained in:
Johannes Zellner
2023-07-14 14:48:43 +02:00
parent 6bf7a1a2d8
commit d162ffe508
10 changed files with 347 additions and 9 deletions
+56
View File
@@ -0,0 +1,56 @@
import superagent from 'superagent';
import { ISTATES } from '../constants.js';
import { sleep } from 'pankow/utils';
export function create(origin, accessToken, id) {
return {
name: 'AppModel',
async get() {
let error, result;
try {
result = await superagent.get(`${origin}/api/v1/apps/${id}`).query({ access_token: accessToken });
} catch (e) {
error = e;
}
if (error || result.statusCode !== 200) {
console.error(`Invalid app ${id}`, error || result.statusCode);
this.fatalError = `Invalid app ${id}`;
return;
}
return result.body;
},
async restart() {
let error, result;
try {
result = await superagent.post(`${origin}/api/v1/apps/${id}/restart`).query({ access_token: accessToken });
} catch (e) {
error = e;
}
if (error || result.statusCode !== 202) {
console.error(`Failed to restart app ${this.id}`, error || result.statusCode);
return;
}
while(true) {
let result;
try {
result = await superagent.get(`${origin}/api/v1/apps/${id}`).query({ access_token: accessToken });
} catch (e) {
console.error(e);
}
if (result && result.statusCode === 200 && result.body.installationState === ISTATES.INSTALLED) break;
await sleep(2000);
}
}
};
}
export default {
create
};