Replaced tabs with spaces

master
WolverinDEV 2021-02-19 23:04:02 +01:00
parent c4575b21b5
commit 1a78bf8d57
6 changed files with 244 additions and 202 deletions

3
.gitmodules vendored
View File

@ -4,3 +4,6 @@
[submodule "web/native-codec/libraries/opus"]
path = web/native-codec/libraries/opus
url = https://github.com/xiph/opus.git
[submodule "vendor/TeaEventBus"]
path = vendor/TeaEventBus
url = https://github.com/WolverinDEV/TeaEventBus.git

View File

@ -1,23 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: WolverinDEV
* Date: 04.10.18
* Time: 16:42
*/
/**
* Created by PhpStorm.
* User: WolverinDEV
* Date: 04.10.18
* Time: 16:42
*/
$UI_BASE_PATH = "ui-files/";
$CLIENT_BASE_PATH = "files/";
function errorExit($message) {
http_response_code(400);
die(json_encode([
"success" => false,
"msg" => $message
]));
}
function errorExit($message) {
http_response_code(400);
die(json_encode([
"success" => false,
"msg" => $message
]));
}
function verifyPostSecret() {
function verifyPostSecret() {
if(!isset($_POST["secret"])) {
errorExit("Missing required information!");
}
@ -36,159 +36,159 @@
}
}
function handleRequest() {
if(isset($_GET) && isset($_GET["type"])) {
if ($_GET["type"] == "update-info") {
global $CLIENT_BASE_PATH;
$raw_versions = file_get_contents($CLIENT_BASE_PATH . "/version.json");
if($raw_versions === false) {
function handleRequest() {
if(isset($_GET) && isset($_GET["type"])) {
if ($_GET["type"] == "update-info") {
global $CLIENT_BASE_PATH;
$raw_versions = file_get_contents($CLIENT_BASE_PATH . "/version.json");
if($raw_versions === false) {
errorExit("Missing file!");
}
$versions = json_decode($raw_versions, true);
$versions["success"] = true;
$versions = json_decode($raw_versions, true);
$versions["success"] = true;
die(json_encode($versions));
}
else if ($_GET["type"] == "update-download") {
global $CLIENT_BASE_PATH;
die(json_encode($versions));
}
else if ($_GET["type"] == "update-download") {
global $CLIENT_BASE_PATH;
$path = $CLIENT_BASE_PATH . $_GET["channel"] . DIRECTORY_SEPARATOR . $_GET["version"] . DIRECTORY_SEPARATOR;
$raw_release_info = file_get_contents($path . "info.json");
if($raw_release_info === false) {
$path = $CLIENT_BASE_PATH . $_GET["channel"] . DIRECTORY_SEPARATOR . $_GET["version"] . DIRECTORY_SEPARATOR;
$raw_release_info = file_get_contents($path . "info.json");
if($raw_release_info === false) {
errorExit("missing info file (version and/or channel missing. Path was " . $path . ")");
}
$release_info = json_decode($raw_release_info);
$release_info = json_decode($raw_release_info);
foreach($release_info as $platform) {
if($platform->platform != $_GET["platform"]) continue;
if($platform->arch != $_GET["arch"]) continue;
foreach($release_info as $platform) {
if($platform->platform != $_GET["platform"]) continue;
if($platform->arch != $_GET["arch"]) continue;
http_response_code(200);
header("Cache-Control: public"); // needed for internet explorer
header("Content-Type: application/binary");
header("Content-Transfer-Encoding: Binary");
header("Content-Length:".filesize($path . $platform->update));
header("Content-Disposition: attachment; filename=update.tar.gz");
header("info-version: 1");
readfile($path . $platform->update);
die();
}
errorExit("Missing platform, arch or file");
}
else if ($_GET["type"] == "ui-info") {
global $UI_BASE_PATH;
http_response_code(200);
header("Cache-Control: public"); // needed for internet explorer
header("Content-Type: application/binary");
header("Content-Transfer-Encoding: Binary");
header("Content-Length:".filesize($path . $platform->update));
header("Content-Disposition: attachment; filename=update.tar.gz");
header("info-version: 1");
readfile($path . $platform->update);
die();
}
errorExit("Missing platform, arch or file");
}
else if ($_GET["type"] == "ui-info") {
global $UI_BASE_PATH;
$version_info = file_get_contents($UI_BASE_PATH . "info.json");
if($version_info === false) $version_info = array();
else $version_info = json_decode($version_info, true);
$version_info = file_get_contents($UI_BASE_PATH . "info.json");
if($version_info === false) $version_info = array();
else $version_info = json_decode($version_info, true);
$info = array();
$info["success"] = true;
$info["versions"] = array();
$info = array();
$info["success"] = true;
$info["versions"] = array();
foreach($version_info as $channel => $data) {
if(!isset($data["latest"])) continue;
foreach($version_info as $channel => $data) {
if(!isset($data["latest"])) continue;
$channel_info = [
"timestamp" => $data["latest"]["timestamp"],
"version" => $data["latest"]["version"],
"git-ref" => $data["latest"]["git-ref"],
"channel" => $channel,
"required_client" => $data["latest"]["required_client"]
];
array_push($info["versions"], $channel_info);
}
die(json_encode($info));
} else if ($_GET["type"] == "ui-download") {
global $UI_BASE_PATH;
$channel_info = [
"timestamp" => $data["latest"]["timestamp"],
"version" => $data["latest"]["version"],
"git-ref" => $data["latest"]["git-ref"],
"channel" => $channel,
"required_client" => $data["latest"]["required_client"]
];
array_push($info["versions"], $channel_info);
}
die(json_encode($info));
} else if ($_GET["type"] == "ui-download") {
global $UI_BASE_PATH;
if(!isset($_GET["channel"]) || !isset($_GET["version"]))
errorExit("missing required parameters");
if(!isset($_GET["channel"]) || !isset($_GET["version"]))
errorExit("missing required parameters");
if($_GET["version"] !== "latest" && !isset($_GET["git-ref"]))
errorExit("missing required parameters");
if($_GET["version"] !== "latest" && !isset($_GET["git-ref"]))
errorExit("missing required parameters");
$version_info = file_get_contents($UI_BASE_PATH . "info.json");
if($version_info === false) $version_info = array();
else $version_info = json_decode($version_info, true);
$version_info = file_get_contents($UI_BASE_PATH . "info.json");
if($version_info === false) $version_info = array();
else $version_info = json_decode($version_info, true);
$channel_data = $version_info[$_GET["channel"]];
if(!isset($channel_data))
errorExit("channel unknown");
$channel_data = $version_info[$_GET["channel"]];
if(!isset($channel_data))
errorExit("channel unknown");
$ui_pack = false;
if($_GET["version"] === "latest") {
$ui_pack = $channel_data["latest"];
} else {
foreach ($channel_data["history"] as $entry) {
if($entry["version"] == $_GET["version"] && $entry["git-ref"] == $_GET["git-ref"]) {
$ui_pack = $entry;
break;
}
}
}
if($ui_pack === false)
errorExit("missing version");
$ui_pack = false;
if($_GET["version"] === "latest") {
$ui_pack = $channel_data["latest"];
} else {
foreach ($channel_data["history"] as $entry) {
if($entry["version"] == $_GET["version"] && $entry["git-ref"] == $_GET["git-ref"]) {
$ui_pack = $entry;
break;
}
}
}
if($ui_pack === false)
errorExit("missing version");
header("Cache-Control: public"); // needed for internet explorer
header("Content-Type: application/binary");
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment; filename=ui.tar.gz");
header("info-version: 1");
header("Cache-Control: public"); // needed for internet explorer
header("Content-Type: application/binary");
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment; filename=ui.tar.gz");
header("info-version: 1");
header("x-ui-timestamp: " . $ui_pack["timestamp"]);
header("x-ui-version: " . $ui_pack["version"]);
header("x-ui-git-ref: " . $ui_pack["git-ref"]);
header("x-ui-required_client: " . $ui_pack["required_client"]);
header("x-ui-timestamp: " . $ui_pack["timestamp"]);
header("x-ui-version: " . $ui_pack["version"]);
header("x-ui-git-ref: " . $ui_pack["git-ref"]);
header("x-ui-required_client: " . $ui_pack["required_client"]);
$read = readfile($ui_pack["file"]);
header("Content-Length:" . $read);
$read = readfile($ui_pack["file"]);
header("Content-Length:" . $read);
if($read === false) errorExit("internal error: Failed to read file!");
die();
}
}
else if($_POST["type"] == "deploy-build") {
global $CLIENT_BASE_PATH;
if($read === false) errorExit("internal error: Failed to read file!");
die();
}
}
else if($_POST["type"] == "deploy-build") {
global $CLIENT_BASE_PATH;
if(!isset($_POST["version"]) || !isset($_POST["platform"]) || !isset($_POST["arch"]) || !isset($_POST["update_suffix"]) || !isset($_POST["installer_suffix"])) {
if(!isset($_POST["version"]) || !isset($_POST["platform"]) || !isset($_POST["arch"]) || !isset($_POST["update_suffix"]) || !isset($_POST["installer_suffix"])) {
errorExit("Missing required information!");
}
}
verifyPostSecret();
if(!isset($_FILES["update"])) {
if(!isset($_FILES["update"])) {
errorExit("Missing update file");
}
if($_FILES["update"]["error"] !== UPLOAD_ERR_OK) {
if($_FILES["update"]["error"] !== UPLOAD_ERR_OK) {
errorExit("Upload for update failed!");
}
if(!isset($_FILES["installer"])) {
if(!isset($_FILES["installer"])) {
errorExit("Missing installer file");
}
if($_FILES["installer"]["error"] !== UPLOAD_ERR_OK) {
if($_FILES["installer"]["error"] !== UPLOAD_ERR_OK) {
errorExit("Upload for installer failed!");
}
$json_version = json_decode($_POST["version"], true);
$version = $json_version["major"] . "." . $json_version["minor"] . "." . $json_version["patch"] . ($json_version["build"] > 0 ? "-" . $json_version["build"] : "");
$path = $CLIENT_BASE_PATH . DIRECTORY_SEPARATOR . $_POST["channel"] . DIRECTORY_SEPARATOR . $version . DIRECTORY_SEPARATOR;
exec("mkdir -p " . $path);
//mkdir($path, 777, true);
$json_version = json_decode($_POST["version"], true);
$version = $json_version["major"] . "." . $json_version["minor"] . "." . $json_version["patch"] . ($json_version["build"] > 0 ? "-" . $json_version["build"] : "");
$path = $CLIENT_BASE_PATH . DIRECTORY_SEPARATOR . $_POST["channel"] . DIRECTORY_SEPARATOR . $version . DIRECTORY_SEPARATOR;
exec("mkdir -p " . $path);
//mkdir($path, 777, true);
$filename_update = "TeaClient-" . $_POST["platform"] . "_" . $_POST["arch"] . "." . $_POST["update_suffix"];
$filename_install = "TeaClient-" . $_POST["platform"] . "_" . $_POST["arch"] . "." . $_POST["installer_suffix"];
$filename_update = "TeaClient-" . $_POST["platform"] . "_" . $_POST["arch"] . "." . $_POST["update_suffix"];
$filename_install = "TeaClient-" . $_POST["platform"] . "_" . $_POST["arch"] . "." . $_POST["installer_suffix"];
{
$version_info = file_get_contents($path . "info.json");
if($version_info === false) {
{
$version_info = file_get_contents($path . "info.json");
if($version_info === false) {
$version_info = array();
} else {
$version_info = json_decode($version_info, true);
@ -197,26 +197,26 @@
}
}
for($index = 0; $index < count($version_info); $index++) {
if($version_info[$index]["platform"] == $_POST["platform"] && $version_info[$index]["arch"] == $_POST["arch"]) {
array_splice($version_info, $index, 1);
break;
}
}
for($index = 0; $index < count($version_info); $index++) {
if($version_info[$index]["platform"] == $_POST["platform"] && $version_info[$index]["arch"] == $_POST["arch"]) {
array_splice($version_info, $index, 1);
break;
}
}
$info = array();
$info["platform"] = $_POST["platform"];
$info["arch"] = $_POST["arch"];
$info["update"] = $filename_update;
$info["install"] = $filename_install;
array_push($version_info, $info);
file_put_contents($path . "info.json", json_encode($version_info));
}
$info = array();
$info["platform"] = $_POST["platform"];
$info["arch"] = $_POST["arch"];
$info["update"] = $filename_update;
$info["install"] = $filename_install;
array_push($version_info, $info);
file_put_contents($path . "info.json", json_encode($version_info));
}
{
$filename = $CLIENT_BASE_PATH . DIRECTORY_SEPARATOR . "version.json";
$indexes = file_get_contents($filename);
if($indexes === false) {
{
$filename = $CLIENT_BASE_PATH . DIRECTORY_SEPARATOR . "version.json";
$indexes = file_get_contents($filename);
if($indexes === false) {
$indexes = array();
} else {
$indexes = json_decode($indexes, true);
@ -225,52 +225,52 @@
}
}
$index = &$indexes[$_POST["channel"]];
if(!isset($index)) {
$index = &$indexes[$_POST["channel"]];
if(!isset($index)) {
$index = array();
}
}
for($idx = 0; $idx < count($index); $idx++) {
if($index[$idx]["platform"] == $_POST["platform"] && $index[$idx]["arch"] == $_POST["arch"]) {
array_splice($index, $idx, 1);
break;
}
}
for($idx = 0; $idx < count($index); $idx++) {
if($index[$idx]["platform"] == $_POST["platform"] && $index[$idx]["arch"] == $_POST["arch"]) {
array_splice($index, $idx, 1);
break;
}
}
$info = array();
$info["platform"] = $_POST["platform"];
$info["arch"] = $_POST["arch"];
$info["version"] = $json_version;
array_push($index, $info);
$info = array();
$info["platform"] = $_POST["platform"];
$info["arch"] = $_POST["arch"];
$info["version"] = $json_version;
array_push($index, $info);
file_put_contents($filename, json_encode($indexes));
}
file_put_contents($filename, json_encode($indexes));
}
move_uploaded_file($_FILES["installer"]["tmp_name"],$path . $filename_install);
move_uploaded_file($_FILES["update"]["tmp_name"],$path . $filename_update);
move_uploaded_file($_FILES["installer"]["tmp_name"],$path . $filename_install);
move_uploaded_file($_FILES["update"]["tmp_name"],$path . $filename_update);
die(json_encode([
"success" => true
]));
}
else if($_POST["type"] == "deploy-ui-build") {
global $UI_BASE_PATH;
die(json_encode([
"success" => true
]));
}
else if($_POST["type"] == "deploy-ui-build") {
global $UI_BASE_PATH;
if(!isset($_POST["channel"]) || !isset($_POST["version"]) || !isset($_POST["git_ref"]) || !isset($_POST["required_client"])) {
if(!isset($_POST["channel"]) || !isset($_POST["version"]) || !isset($_POST["git_ref"]) || !isset($_POST["required_client"])) {
errorExit("Missing required information!");
}
}
verifyPostSecret();
$path = $UI_BASE_PATH . DIRECTORY_SEPARATOR;
$channeled_path = $UI_BASE_PATH . DIRECTORY_SEPARATOR . $_POST["channel"];
$filename = "TeaClientUI-" . $_POST["version"] . "_" . $_POST["git_ref"] . ".tar.gz";
exec("mkdir -p " . $path);
exec("mkdir -p " . $channeled_path);
$path = $UI_BASE_PATH . DIRECTORY_SEPARATOR;
$channeled_path = $UI_BASE_PATH . DIRECTORY_SEPARATOR . $_POST["channel"];
$filename = "TeaClientUI-" . $_POST["version"] . "_" . $_POST["git_ref"] . ".tar.gz";
exec("mkdir -p " . $path);
exec("mkdir -p " . $channeled_path);
{
$info = file_get_contents($path . "info.json");
if($info === false) {
{
$info = file_get_contents($path . "info.json");
if($info === false) {
$info = array();
} else {
$info = json_decode($info, true);
@ -279,36 +279,36 @@
}
}
$channel_info = &$info[$_POST["channel"]];
if(!$channel_info) {
$channel_info = &$info[$_POST["channel"]];
if(!$channel_info) {
$channel_info = array();
}
$entry = [
"timestamp" => time(),
"file" => $channeled_path . DIRECTORY_SEPARATOR . $filename,
"version" => $_POST["version"],
"git-ref" => $_POST["git_ref"],
"required_client" => $_POST["required_client"]
];
$entry = [
"timestamp" => time(),
"file" => $channeled_path . DIRECTORY_SEPARATOR . $filename,
"version" => $_POST["version"],
"git-ref" => $_POST["git_ref"],
"required_client" => $_POST["required_client"]
];
$channel_info["latest"] = $entry;
if(!$channel_info["history"]) $channel_info["history"] = array();
array_push($channel_info["history"], $entry);
$channel_info["latest"] = $entry;
if(!$channel_info["history"]) $channel_info["history"] = array();
array_push($channel_info["history"], $entry);
file_put_contents($path . "info.json", json_encode($info));
}
file_put_contents($path . "info.json", json_encode($info));
}
move_uploaded_file($_FILES["file"]["tmp_name"],$channeled_path . DIRECTORY_SEPARATOR . $filename);
die(json_encode([
"success" => true
]));
}
else die(json_encode([
"success" => false,
"error" => "invalid action!"
]));
}
move_uploaded_file($_FILES["file"]["tmp_name"],$channeled_path . DIRECTORY_SEPARATOR . $filename);
die(json_encode([
"success" => true
]));
}
else die(json_encode([
"success" => false,
"error" => "invalid action!"
]));
}
handleRequest();
handleRequest();

View File

@ -15,6 +15,8 @@
"tc-backend/web/*": ["web/app/*"], /* specific web part */
"tc-backend/*": ["shared/backend.d/*"],
"tc-loader": ["loader/exports/loader.d.ts"],
"tc-events": ["vendor/TeaEventBus/src/index.ts"],
"tc-services": ["vendor/TeaClientServices/src/index.ts"],
"svg-sprites/*": ["shared/svg-sprites/*"],
"vendor/xbbcode/*": ["vendor/xbbcode/src/*"]

34
vendor/TeaClientServices/src/Action.ts vendored Normal file
View File

@ -0,0 +1,34 @@
import {MessageCommandErrorResult} from "./Messages";
import {clientServiceLogger} from "./Logging";
export type ActionResult<T> = {
unwrap() : T;
} & ({
status: "success",
result: T
} | {
status: "error",
result: MessageCommandErrorResult
});
export function createErrorResult<T>(result: MessageCommandErrorResult) : ActionResult<T> {
return {
status: "error",
result: result,
unwrap(): T {
clientServiceLogger.logError("Tried to unwrap an action which failed: %o", result);
throw "action failed with " + result.type;
}
}
}
export function createResult<T>(result: T) : ActionResult<T> {
return {
status: "success",
result: result,
unwrap(): T {
return result;
}
}
}

1
vendor/TeaEventBus vendored Submodule

@ -0,0 +1 @@
Subproject commit 9caad3399af830606e25e66f51ee40239bc3b457

View File

@ -230,7 +230,9 @@ export const config = async (target: "web" | "client"): Promise<Configuration> =
resolve: {
extensions: ['.tsx', '.ts', '.js', ".scss", ".css", ".wasm"],
alias: {
"vendor/xbbcode": path.resolve(__dirname, "vendor/xbbcode/src")
"vendor/xbbcode": path.resolve(__dirname, "vendor/xbbcode/src"),
"tc-events": path.resolve(__dirname, "vendor/TeaEventBus/src/index.ts"),
"tc-services": path.resolve(__dirname, "vendor/TeaClientServices/src/index.ts"),
},
},
externals: [