mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-01-19 08:57:55 +00:00
raw content delivery support -- urls are raw.codeberg.eu/{owner}/{repo}/...
This commit is contained in:
parent
f60ce37802
commit
b866134b9c
1 changed files with 16 additions and 7 deletions
|
@ -15,6 +15,7 @@ $request_url = filter_var($request_uri, FILTER_SANITIZE_URL);
|
||||||
$request_url = str_replace("%20", " ", $request_url);
|
$request_url = str_replace("%20", " ", $request_url);
|
||||||
$request_url_parts = explode("/", $request_url);
|
$request_url_parts = explode("/", $request_url);
|
||||||
$request_url_parts = array_diff($request_url_parts, array("")); # Remove empty parts in URL
|
$request_url_parts = array_diff($request_url_parts, array("")); # Remove empty parts in URL
|
||||||
|
$cors = false;
|
||||||
|
|
||||||
if ($tld === "org") {
|
if ($tld === "org") {
|
||||||
$subdomain_repo = array(
|
$subdomain_repo = array(
|
||||||
|
@ -24,6 +25,7 @@ if ($tld === "org") {
|
||||||
);
|
);
|
||||||
if (array_key_exists($subdomain, $subdomain_repo)) {
|
if (array_key_exists($subdomain, $subdomain_repo)) {
|
||||||
$owner = $subdomain_repo[$subdomain];
|
$owner = $subdomain_repo[$subdomain];
|
||||||
|
$cors = true;
|
||||||
} else {
|
} else {
|
||||||
$owner = strtolower(array_shift($request_url_parts));
|
$owner = strtolower(array_shift($request_url_parts));
|
||||||
if (!$owner) {
|
if (!$owner) {
|
||||||
|
@ -42,6 +44,10 @@ if ($tld === "org") {
|
||||||
$owner = strtolower($subdomain);
|
$owner = strtolower($subdomain);
|
||||||
if (strpos($owner, ".") !== false)
|
if (strpos($owner, ".") !== false)
|
||||||
send_response(200, "Pages not supported for user names with dots. Please rename your username to use Codeberg pages.");
|
send_response(200, "Pages not supported for user names with dots. Please rename your username to use Codeberg pages.");
|
||||||
|
if ($owner === "raw") {
|
||||||
|
$owner = strtolower(array_shift($request_url_parts));
|
||||||
|
$cors = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$reservedUsernames = array(
|
$reservedUsernames = array(
|
||||||
|
@ -72,9 +78,6 @@ $reservedUsernames = array(
|
||||||
if (in_array($owner, $reservedUsernames))
|
if (in_array($owner, $reservedUsernames))
|
||||||
send_response(404, "Reserved user name '" . $owner . "' cannot have pages");
|
send_response(404, "Reserved user name '" . $owner . "' cannot have pages");
|
||||||
|
|
||||||
if ($owner == "codeberg-fonts" || $owner == "get-it-on")
|
|
||||||
header("Access-Control-Allow-Origin: *");
|
|
||||||
|
|
||||||
if (!$owner) {
|
if (!$owner) {
|
||||||
send_response(200, file_get_contents("./default-page.html"));
|
send_response(200, file_get_contents("./default-page.html"));
|
||||||
}
|
}
|
||||||
|
@ -131,12 +134,18 @@ $mime_types = array(
|
||||||
"xml" => "text/xml"
|
"xml" => "text/xml"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (array_key_exists($ext, $mime_types)) {
|
$mime_type = "application/octet-stream";
|
||||||
header("Content-Type: " . $mime_types[$ext]);
|
if (array_key_exists($ext, $mime_types))
|
||||||
} else {
|
$mime_type = $mime_types[$ext];
|
||||||
header("Content-Type: application/octet-stream");
|
|
||||||
|
if ($cors === true) {
|
||||||
|
header("Access-Control-Allow-Origin: *");
|
||||||
|
if ($ext === "html" || $ext === "js" || $ext === "css")
|
||||||
|
$mime_type = "text/plain";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
header("Content-Type: " . $mime_type);
|
||||||
|
|
||||||
#header("Cache-Control: public, max-age=10, immutable");
|
#header("Cache-Control: public, max-age=10, immutable");
|
||||||
|
|
||||||
$command = "sh -c \"cd '$git_root' && /usr/bin/git log --format='%H' -1\"";
|
$command = "sh -c \"cd '$git_root' && /usr/bin/git log --format='%H' -1\"";
|
||||||
|
|
Loading…
Reference in a new issue