Files
coolify/src/routes/api/v1/application/deploy/logs/index.ts
Andras Bacsai 23a4ebb74a v1.0.12 - Sveltekit migration (#44)
Changed the whole tech stack to SvelteKit which means:
- Typescript 
- SSR
- No fastify :(
- Beta, but it's fine!

Other changes:
- Tailwind -> Tailwind JIT
- A lot more
2021-05-14 21:51:14 +02:00

48 lines
1.1 KiB
TypeScript

import type { Request } from '@sveltejs/kit';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js';
import relativeTime from 'dayjs/plugin/relativeTime.js';
import Deployment from '$models/Logs/Deployment';
dayjs.extend(utc);
dayjs.extend(relativeTime);
export async function get(request: Request) {
try {
const repoId = request.query.get('repoId');
const branch = request.query.get('branch');
const page = request.query.get('page');
const onePage = 5;
const show = Number(page) * onePage || 5;
const deploy: any = await Deployment.find({ repoId, branch })
.select('-_id -__v -repoId')
.sort({ createdAt: 'desc' })
.limit(show);
const finalLogs = deploy.map((d) => {
const finalLogs = { ...d._doc };
const updatedAt = dayjs(d.updatedAt).utc();
finalLogs.took = updatedAt.diff(dayjs(d.createdAt)) / 1000;
finalLogs.since = updatedAt.fromNow();
return finalLogs;
});
return {
status: 200,
body: {
success: true,
logs: finalLogs
}
};
} catch (error) {
console.log(error);
return {
status: 500,
body: {
error
}
};
}
}