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