diff options
Diffstat (limited to 'public/index.php')
-rw-r--r-- | public/index.php | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/public/index.php b/public/index.php index eab78af..ad32102 100644 --- a/public/index.php +++ b/public/index.php @@ -40,12 +40,23 @@ public class Program { } java; +const CODE_MAXLENGTH = 16383; + $code = null; -$result = null; -if (isset($_POST["code"]) && strlen($_POST["code"]) <= 16383) { - $id = getid(); +if (!empty($_GET["c"])) { + $compressedCode = @base64_decode($_GET["c"], true); + if ($compressedCode !== false) { + $uncompressedCode = @gzinflate($compressedCode, CODE_MAXLENGTH); + if ($compressedCode !== false) { + $code = &$uncompressedCode; + } + } +} + +$result = null; +if (isset($_POST["code"]) && strlen($_POST["code"]) <= CODE_MAXLENGTH) { header("Content-Type: application/json"); $code = $_POST["code"]; @@ -60,6 +71,16 @@ if (isset($_POST["code"]) && strlen($_POST["code"]) <= 16383) { exit; } + if (($_POST["permalink"] ?? "") === "1") { + echo json_encode([ + "ok" => true, + "data" => base64_encode(gzdeflate($code, 9, ZLIB_ENCODING_RAW)), + ]); + exit; + } + + $id = getid(); + $runnerDir = __DIR__ . "/../_runners/$id"; $srcDir = $runnerDir . "/src"; @@ -150,10 +171,11 @@ $csrf = csrf_token(); <p>Powered by Eclipse Temurin</p> <form method="POST"> <input name="csrf" id="csrf-token" type="hidden" value="<?= htmlentities($csrf) ?>"> - <textarea maxlength="16383" id="editor" name="code" rows="20"><?= htmlentities($code ?? $defaultCode) ?></textarea> + <textarea maxlength="<?= CODE_MAXLENGTH ?>" id="editor" name="code" rows="20"><?= htmlentities($code ?? $defaultCode) ?></textarea> <div id="toolbar"> <button type="submit">▶ Compile & run</button> <button type="button" id="dlCodeButton">Download code as file</button> + <button type="button" id="permalink">Permalink</button> </div> </form> <div id="output" style="display: none;"></div> |