🗝
summary refs log tree commit diff
diff options
context:
space:
mode:
authormia <mia@mia.jetzt>2024-06-29 04:14:48 -0700
committermia <mia@mia.jetzt>2024-06-29 04:14:48 -0700
commit43b8b07f1e67e8c49cb4988192320266063debe6 (patch)
treeb6a309af15aa63c515cda692312155d054fc4e23
parent7e729cc2ea889173a89d79737a957cd3dff6e52f (diff)
downloadasylum-43b8b07f1e67e8c49cb4988192320266063debe6.tar.gz
asylum-43b8b07f1e67e8c49cb4988192320266063debe6.zip
add cat.mia.jetzt code
-rw-r--r--nginx/nginx.conf13
-rw-r--r--nginx/nginx.js23
2 files changed, 35 insertions, 1 deletions
diff --git a/nginx/nginx.conf b/nginx/nginx.conf
index 83b440c..ae6369e 100644
--- a/nginx/nginx.conf
+++ b/nginx/nginx.conf
@@ -42,7 +42,7 @@ http {
         listen [::]:80 default_server;
 
         default_type text/plain;
-        root /srv/html;
+        root /srv/web/$host;
         index index.html;
     }
 
@@ -112,4 +112,15 @@ http {
 
         %AUTH_LOCATIONS%
     }
+
+    # cat
+    server {
+        listen 80;
+        listen [::]:80;
+        server_name cat.mia.jetzt;
+
+        location / {
+            js_content nginx.cat;
+        }
+    }
 }
diff --git a/nginx/nginx.js b/nginx/nginx.js
index 03b2dae..4557167 100644
--- a/nginx/nginx.js
+++ b/nginx/nginx.js
@@ -44,6 +44,29 @@ async function validate(request) {
     return request.return(200);
 }
 
+const cat_sounds = ["meow", "mrow", "mew", "nya", "purr", "miau"];
+/** @param {NginxHTTPRequest} request */
+async function cat(request) {
+    let buffer = "";
+    buffer += "\x1b]0;meow\x07"; // set title
+    buffer += "\x1b[s"; // save cursor position
+    let verbosity = 50;
+    if (request.uri.length > 1) {
+        const supplied = parseInt(request.uri.slice(1));
+        if (supplied !== NaN) verbosity = supplied;
+        if (supplied > 1000) verbosity = 1000;
+    }
+    for (let i = 0; i < verbosity; i++) {
+        const sound = cat_sounds[Math.floor(Math.random() * cat_sounds.length)];
+        const col = Math.floor(Math.random() * (120 - sound.length + 2)) + 1;
+        const row = Math.floor(Math.random() * 40) + 1;
+        buffer += `\x1b[${row};${col}H ${sound} `; // write sound at position
+    }
+    buffer += '\x1b[u' // restore cursor position
+    request.return(200, buffer);
+}
+
 export default {
     validate,
+    cat,
 }