Files
365devnet/src/pages/api/commits.ts
Richard Bergsma a767dbb115 Enhance security and localization features across the application
- Added rehype-sanitize plugin to the markdown configuration for improved security against XSS attacks.
- Updated environment variables in the codebase to include new configurations for SMTP and monitoring.
- Implemented secure headers in server and Nginx configurations to bolster security.
- Refactored email handling to prevent spoofing by ensuring safe sender addresses.
- Improved localization by updating language persistence and button components for better user experience.
- Enhanced the uptime API and contact form with better error handling and logging practices.
- Updated dependencies in package.json and package-lock.json for better performance and security.
2025-10-19 21:13:15 +02:00

97 lines
2.8 KiB
TypeScript

import type { APIRoute } from 'astro';
export const GET: APIRoute = async ({ request }) => {
try {
const username = 'Richard';
const url = `https://git.365devnet.eu/api/v1/users/${username}/activities/feeds`;
const headers: HeadersInit = {
accept: 'application/json'
};
if (import.meta.env.GITEA_TOKEN) {
headers['Authorization'] = `token ${import.meta.env.GITEA_TOKEN}`;
}
const response = await fetch(url, { headers, redirect: 'follow', cache: 'no-store' });
if (!response.ok) {
throw new Error(`Gitea API responded with status: ${response.status}`);
}
const feeds = await response.json();
// Only keep commit_repo events
const commits: Array<{
sha: string;
message: string;
author: string;
date: string;
repo: string;
repo_url: string;
compare_url: string;
}> = [];
for (const feed of feeds) {
if (feed.op_type === 'commit_repo' && feed.content) {
let content;
try {
content = JSON.parse(feed.content);
} catch {
continue;
}
// Each feed may have multiple commits
if (content.Commits && Array.isArray(content.Commits)) {
for (const commit of content.Commits) {
commits.push({
sha: commit.Sha1,
message: commit.Message,
author: commit.AuthorName,
date: commit.Timestamp,
repo: feed.repo ? feed.repo.full_name : '',
repo_url: feed.repo ? feed.repo.html_url : '',
compare_url: content.CompareURL ? `https://git.365devnet.eu/${content.CompareURL}` : '',
});
}
}
}
}
// Pagination
const { searchParams } = new URL(request.url);
const limit = parseInt(searchParams.get('limit') || '5', 10);
const offset = parseInt(searchParams.get('offset') || '0', 10);
const pagedCommits = commits.slice(offset, offset + limit);
const hasMore = offset + limit < commits.length;
return new Response(JSON.stringify({
success: true,
commits: pagedCommits,
hasMore,
total: commits.length,
timestamp: new Date().toISOString()
}), {
status: 200,
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0'
}
});
} catch (error) {
console.error('Error fetching commits:', error);
return new Response(JSON.stringify({
success: false,
error: 'Failed to fetch commits',
timestamp: new Date().toISOString()
}), {
status: 500,
headers: {
'Content-Type': 'application/json'
}
});
}
};