diff options
author | Jonas Kohl | 2024-11-08 11:43:34 +0100 |
---|---|---|
committer | Jonas Kohl | 2024-11-08 11:43:34 +0100 |
commit | 8ccf2f9bf55fdf9d707c76aa9074d60d3207fc13 (patch) | |
tree | 711613351e2cbc9c7a5a5b3ee8164bfd2220c7a7 /public/index.php | |
parent | c2a4bd09d7f046f1b2d7e3978d5ee60caded0fc1 (diff) |
Add permalink option
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> |