Initial commit of YouTube Downloader application, including core functionality for downloading videos, user authentication, and Docker support. Added configuration files, environment setup, and basic UI components using Astro.js and Tailwind CSS.
This commit is contained in:
57
src/pages/api/login.ts
Normal file
57
src/pages/api/login.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { createSessionCookie, isLoginEnabled } from '../../lib/session';
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
// Wenn Login deaktiviert ist, weiterleiten
|
||||
if (!isLoginEnabled()) {
|
||||
return new Response(null, {
|
||||
status: 302,
|
||||
headers: {
|
||||
'Location': new URL('/download', request.url).toString(),
|
||||
},
|
||||
});
|
||||
}
|
||||
const formData = await request.formData();
|
||||
const username = formData.get('username')?.toString();
|
||||
const password = formData.get('password')?.toString();
|
||||
|
||||
// Credentials aus Environment-Variablen
|
||||
const envUsername = import.meta.env.LOGIN_USERNAME;
|
||||
const envPassword = import.meta.env.LOGIN_PASSWORD;
|
||||
|
||||
// Prüfe ob Credentials konfiguriert sind
|
||||
if (!envUsername || !envPassword) {
|
||||
console.error('LOGIN_USERNAME oder LOGIN_PASSWORD nicht in Environment-Variablen gesetzt!');
|
||||
return new Response(null, {
|
||||
status: 302,
|
||||
headers: {
|
||||
'Location': new URL('/', request.url).toString(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Authentifizierung gegen Environment-Variablen
|
||||
if (username === envUsername && password === envPassword) {
|
||||
const session = {
|
||||
username,
|
||||
loggedIn: true,
|
||||
};
|
||||
|
||||
return new Response(null, {
|
||||
status: 302,
|
||||
headers: {
|
||||
'Location': new URL('/download', request.url).toString(),
|
||||
'Set-Cookie': createSessionCookie(session),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Falsche Credentials
|
||||
return new Response(null, {
|
||||
status: 302,
|
||||
headers: {
|
||||
'Location': new URL('/', request.url).toString(),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user