Try to unify API responses
This commit is contained in:
@ -1,12 +1,10 @@
|
||||
<?php
|
||||
require "../.php/auth.inc";
|
||||
require "../.php/credentials.inc";
|
||||
global $GITEA_TOKEN;
|
||||
|
||||
if ($_SERVER['PHP_AUTH_USER'] !== 'elwig' || $_SERVER['PHP_AUTH_PW'] !== 'ganzGeheim123!') {
|
||||
header('Status: 401');
|
||||
header('WWW-Authenticate: Basic realm="Elwig"');
|
||||
header('Content-Type: text/plain');
|
||||
exit("401 Unauthorized :(\n");
|
||||
http_401_unauthorized();
|
||||
}
|
||||
|
||||
$repo = "winzer/elwig-misc.git";
|
||||
@ -15,11 +13,18 @@ $schema_version = $_GET['v'];
|
||||
|
||||
shell_exec("cd .repos; git clone $url; cd elwig-misc; git checkout main; git pull -f --rebase");
|
||||
|
||||
if ($schema_version) {
|
||||
if (!$schema_version || !ctype_digit($schema_version)) {
|
||||
header('Status: 400');
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
header('Content-Length: 16');
|
||||
exit("400 Bad Request\n");
|
||||
} else {
|
||||
$commit = shell_exec("cd .repos/elwig-misc; git log -p sql/v01/99.schema_version.sql | grep '+PRAGMA schema_version = ${schema_version}00;' -B 14 | head -n 1 | grep -oE '[^ ]+$'");
|
||||
if (!$commit) {
|
||||
header('Status: 404');
|
||||
exit("404 Specified schema version not found :(\n");
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
header('Content-Length: 39');
|
||||
exit("404 Specified Schema Version Not Found\n");
|
||||
}
|
||||
shell_exec("cd .repos/elwig-misc; git checkout $commit");
|
||||
}
|
||||
|
Reference in New Issue
Block a user