summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
Diffstat (limited to 'public')
-rw-r--r--public/index.php30
-rw-r--r--public/site.js28
2 files changed, 54 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">&#9654;&nbsp;Compile &amp; 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>
diff --git a/public/site.js b/public/site.js
index ed7173d..e19d6ef 100644
--- a/public/site.js
+++ b/public/site.js
@@ -21,6 +21,34 @@ $(function() {
a.remove();
});
+ $("#permalink").on("click", function() {
+ $("#loader").show();
+ $.ajax({
+ type: "POST",
+ url: location.href,
+ data: {
+ code: editor.getValue(),
+ csrf: csrf,
+ permalink: "1"
+ },
+ dataType: "json",
+ success: function(data) {
+ $("#loader").hide();
+
+ if (!data.ok) {
+ alert("Error: " + data.message);
+ if (data.csrf)
+ csrf = data.csrf;
+ return;
+ }
+
+ csrf = data.csrf;
+
+ location.href = "?c=" + encodeURIComponent(data.data);
+ }
+ });
+ });
+
$("form").on("submit", function(e) {
e.preventDefault();