update: api tests
This commit is contained in:
1 parent
2511b94616
commit
0846dea367
2 files changed
+152
No files matched your search
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
include_once '../controller/DatabaseController.php';
|
||||
include_once '../controller/DataController.php';
|
||||
|
||||
header("Content-Type: application/json");
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Headers: Authorization, Function, Content-Type");
|
||||
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
$validTokens = [
|
||||
"15a437d128c918633e57dc7d18118a073b807644f21731ed5a7ebcf3eca9e242",
|
||||
];
|
||||
|
||||
$headers = getallheaders();
|
||||
$token = $headers['Authorization'] ?? '';
|
||||
$function = $headers['Function'] ?? '';
|
||||
|
||||
if (!in_array($token, $validTokens)) {
|
||||
http_response_code(401);
|
||||
echo json_encode(["error" => "Unauthorized"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (in_array($token, $validTokens)) {
|
||||
DatabaseInsert(
|
||||
"API",
|
||||
"CLIENT_IP, TOKEN, API, FUNKTION",
|
||||
(new getSpecificData())->getClientIP(),
|
||||
$token,
|
||||
(new getSpecificData())->getRequestURL(),
|
||||
$function
|
||||
);
|
||||
|
||||
if ($function === "IPs") {
|
||||
$data = DatabaseShow(
|
||||
"logs",
|
||||
"CLIENT_IP"
|
||||
);
|
||||
}
|
||||
|
||||
if ($function === "Ueberstunden") {
|
||||
$data = DatabaseShow(
|
||||
"Ueberstunden",
|
||||
"MINUTEN"
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode(
|
||||
[
|
||||
"success" => true,
|
||||
"data" => $data,
|
||||
]
|
||||
);
|
||||
exit;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
$validTokens = [
|
||||
"TEST_TOKEN",
|
||||
"15a437d128c918633e57dc7d18118a073b807644f21731ed5a7ebcf3eca9e242",
|
||||
];
|
||||
$baseUploadDir = __DIR__ . "/../services/uploads/";
|
||||
|
||||
$headers = getallheaders();
|
||||
$token = $headers['Authorization'] ?? '';
|
||||
|
||||
if (!in_array($token, $validTokens)) {
|
||||
http_response_code(401);
|
||||
echo json_encode(["error" => "Unauthorized"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($_FILES['files'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(["error" => "No files uploaded"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$folderName = null;
|
||||
$readmeContent = null;
|
||||
|
||||
// Prüfen ob readme.md hochgeladen wurde
|
||||
foreach ($_FILES['files']['name'] as $key => $name) {
|
||||
if (strtolower($name) === "readme.md") {
|
||||
$tmpName = $_FILES['files']['tmp_name'][$key];
|
||||
$readmeContent = file_get_contents($tmpName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($readmeContent) {
|
||||
// Erste Markdown-Überschrift extrahieren (# Titel)
|
||||
if (preg_match('/^#\s*(.+)$/m', $readmeContent, $matches)) {
|
||||
$rawName = $matches[1];
|
||||
|
||||
// Slug erzeugen (ordner-tauglich machen)
|
||||
$folderName = strtolower($rawName);
|
||||
$folderName = preg_replace("/[^a-z0-9]+/", "-", $folderName);
|
||||
$folderName = trim($folderName, "-");
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback falls keine readme oder kein Titel
|
||||
if (!$folderName) {
|
||||
$folderName = uniqid("upload_", true);
|
||||
}
|
||||
$uploadDir = $baseUploadDir . $folderName . "/";
|
||||
|
||||
if (!mkdir($uploadDir, 0755, true)) {
|
||||
http_response_code(500);
|
||||
echo json_encode(["error" => "Failed to create directory"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$uploadedFiles = [];
|
||||
|
||||
foreach ($_FILES['files']['tmp_name'] as $key => $tmpName) {
|
||||
|
||||
if ($_FILES['files']['error'][$key] !== UPLOAD_ERR_OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$originalName = basename($_FILES['files']['name'][$key]);
|
||||
|
||||
$safeName = preg_replace("/[^a-zA-Z0-9._-]/", "", $originalName);
|
||||
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
$mime = $finfo->file($tmpName);
|
||||
|
||||
if ($_FILES['files']['size'][$key] > 25 * 1024 * 1024) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$targetPath = $uploadDir . $safeName;
|
||||
|
||||
if (move_uploaded_file($tmpName, $targetPath)) {
|
||||
$uploadedFiles[] = $safeName;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"folder" => $folderName,
|
||||
"uploaded_files" => $uploadedFiles
|
||||
]);
|
||||
Reference in new issue
Block a user