 23a4ebb74a
			
		
	
	23a4ebb74a
	
	
	
		
			
			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
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			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
 | |
| 			}
 | |
| 		};
 | |
| 	}
 | |
| }
 |