Normalize / and /{id} responses.
This commit is contained in:
parent
4f0fb236bd
commit
ecc21cb935
@ -104,17 +104,30 @@ export class RegHelper {
|
||||
return [...records];
|
||||
}
|
||||
|
||||
async deploymentRequestStatus() {
|
||||
const requests = await this.queryRecords({
|
||||
type: 'ApplicationDeploymentRequest',
|
||||
});
|
||||
const deployments = await this.queryRecords({
|
||||
type: 'ApplicationDeploymentRecord',
|
||||
});
|
||||
async deploymentRequestStatus(requestId?: string) {
|
||||
const requests: any[] = [];
|
||||
const deployments: any[] = [];
|
||||
const removalRequests = await this.queryRecords({
|
||||
type: 'ApplicationDeploymentRemovalRequest',
|
||||
});
|
||||
|
||||
if (requestId) {
|
||||
const request = await this.getRecordById(requestId);
|
||||
if (request) {
|
||||
requests.push(request);
|
||||
}
|
||||
deployments.push(...await this.queryRecords({
|
||||
type: 'ApplicationDeploymentRecord', request: requestId
|
||||
}));
|
||||
} else {
|
||||
requests.push(...await this.queryRecords({
|
||||
type: 'ApplicationDeploymentRequest',
|
||||
}));
|
||||
deployments.push(...await this.queryRecords({
|
||||
type: 'ApplicationDeploymentRecord',
|
||||
}));
|
||||
}
|
||||
|
||||
requests.sort((a, b) => a.createTime === b.createTime ? 0 : a.createTime > b.createTime ? 1 : -1,);
|
||||
requests.reverse();
|
||||
|
||||
|
24
src/main.ts
24
src/main.ts
@ -1,7 +1,7 @@
|
||||
import express from 'express';
|
||||
import {existsSync, readdirSync, readFileSync} from 'fs';
|
||||
|
||||
import {Config, getRegistry} from './config.js';
|
||||
import {Config} from './config.js';
|
||||
|
||||
import {RegHelper} from './deployments.js';
|
||||
|
||||
@ -26,9 +26,7 @@ const logForRequest = (req_id) => {
|
||||
return ret;
|
||||
};
|
||||
|
||||
app.get('/', async (_req, res) => {
|
||||
const reg = new RegHelper();
|
||||
const regStatus = await reg.deploymentRequestStatus();
|
||||
const adjustFromState = (regStatus: any[]) => {
|
||||
let deployerState = {};
|
||||
if (Config.DEPLOYER_STATE && existsSync(Config.DEPLOYER_STATE)) {
|
||||
deployerState = JSON.parse(readFileSync(Config.DEPLOYER_STATE).toString());
|
||||
@ -53,19 +51,29 @@ app.get('/', async (_req, res) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
return regStatus;
|
||||
}
|
||||
|
||||
app.get('/', async (_req, res) => {
|
||||
const reg = new RegHelper();
|
||||
const regStatus = adjustFromState(await reg.deploymentRequestStatus());
|
||||
res.send(regStatus);
|
||||
});
|
||||
|
||||
app.get('/:id', async (req, res) => {
|
||||
const registry = getRegistry();
|
||||
const records = await registry.getRecordsByIds([req.params.id]);
|
||||
res.send(records);
|
||||
const reg = new RegHelper();
|
||||
const records = adjustFromState(await reg.deploymentRequestStatus(req.params.id));
|
||||
if (records.length) {
|
||||
res.send(records[0]);
|
||||
} else {
|
||||
res.sendStatus(410);
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/log/:id', async (req, res) => {
|
||||
const logFile = logForRequest(req.params.id);
|
||||
if (!logFile) {
|
||||
res.sendStatus(404);
|
||||
res.sendStatus(410);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user