Add job namespace and remove old json_routes logic

This commit is contained in:
Patrick Jentsch
2024-12-06 11:41:36 +01:00
parent 1372c86609
commit 93344c9573
10 changed files with 82 additions and 110 deletions

View File

@@ -0,0 +1,37 @@
nopaque.app.endpoints.Jobs = class Jobs {
constructor(app) {
this.app = app;
this.socket = io('/jobs', {transports: ['websocket'], upgrade: false});
}
async delete(id) {
const response = await this.socket.emitWithAck('delete', id);
if (response.status != 202) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
return response.body;
}
async log(id) {
const response = await this.socket.emitWithAck('log', id);
if (response.status != 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
return response.body;
}
async restart(id) {
const response = await this.socket.emitWithAck('restart', id);
if (response.status != 202) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
return response.body;
}
}

View File

@@ -5,8 +5,8 @@ nopaque.app.endpoints.Users = class Users {
this.socket = io('/users', {transports: ['websocket'], upgrade: false});
}
async get(userId) {
const response = await this.socket.emitWithAck('get', userId);
async get(id) {
const response = await this.socket.emitWithAck('get', id);
if (response.status !== 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
@@ -15,27 +15,29 @@ nopaque.app.endpoints.Users = class Users {
return response.body;
}
async subscribe(userId) {
const response = await this.socket.emitWithAck('subscribe', userId);
async subscribe(id) {
const response = await this.socket.emitWithAck('subscribe', id);
if (response.status != 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
}
async unsubscribe(userId) {
const response = await this.socket.emitWithAck('unsubscribe', userId);
async unsubscribe(id) {
const response = await this.socket.emitWithAck('unsubscribe', id);
if (response.status != 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
}
async delete(userId) {
const response = await this.socket.emitWithAck('delete', userId);
async delete(id) {
const response = await this.socket.emitWithAck('delete', id);
if (response.status != 202) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
return response.body;
}
}