Initial commit

This commit is contained in:
Gabriel Simmer 2024-07-28 15:28:32 +01:00
parent 2d3df21177
commit ced27eb60a
Signed by: arch
SSH key fingerprint: SHA256:m3OEcdtrnBpMX+2BDGh/byv3hrCekCLzDYMdvGEKPPQ
5 changed files with 228 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.wrangler/
node_modules/

171
index.html Normal file
View file

@ -0,0 +1,171 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="What is the secret third rule today?">
<title>third rule</title>
<style>
/* General Styles */
body {
margin: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #36393f;
color: #dcddde;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
}
a {
color: #7289da;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* Main Content */
main {
width: 80%;
max-width: 800px;
background-color: #2f3136;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
display: flex;
flex-direction: column;
}
main header {
font-size: 32px;
font-weight: bold;
margin-bottom: 10px;
}
header h1 {
margin: 0;
text-align: center;
}
main .content {
flex: 1;
padding: 20px;
background-color: #202225;
border-radius: 8px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
display: flex;
align-items: center;
}
.content p {
font-size: 120%;
}
/* Footer */
footer {
background-color: #2f3136;
color: #dcddde;
text-align: center;
padding: 10px 0;
border-top: 1px solid #202225;
}
/* From https://loading.io/css/ */
.lds-ellipsis,
.lds-ellipsis div {
box-sizing: border-box;
}
.lds-ellipsis {
display: inline-block;
position: relative;
width: 80px;
height: 80px;
}
.lds-ellipsis div {
position: absolute;
top: 33.33333px;
width: 13.33333px;
height: 13.33333px;
border-radius: 50%;
background: currentColor;
animation-timing-function: cubic-bezier(0, 1, 1, 0);
}
.lds-ellipsis div:nth-child(1) {
left: 8px;
animation: lds-ellipsis1 0.6s infinite;
}
.lds-ellipsis div:nth-child(2) {
left: 8px;
animation: lds-ellipsis2 0.6s infinite;
}
.lds-ellipsis div:nth-child(3) {
left: 32px;
animation: lds-ellipsis2 0.6s infinite;
}
.lds-ellipsis div:nth-child(4) {
left: 56px;
animation: lds-ellipsis3 0.6s infinite;
}
@keyframes lds-ellipsis1 {
0% {
transform: scale(0);
}
100% {
transform: scale(1);
}
}
@keyframes lds-ellipsis3 {
0% {
transform: scale(1);
}
100% {
transform: scale(0);
}
}
@keyframes lds-ellipsis2 {
0% {
transform: translate(0, 0);
}
100% {
transform: translate(24px, 0);
}
}
</style>
</head>
<body>
<main><div id="error"></div>
<header>
<h1>The Secret Third Rule</h1>
</header>
<div class="content" id="rule">
<p>Generating</p><div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>
</div>
<footer>
made by <a href="https://arch.dog" target="_blank">arch</a>
</footer>
</main>
<script>
const getrule = () => {
// Fetch the content of the dynamic page
fetch("/rule.json")
.then(response => response.json())
.then(data => {
if (data) {
// Inject the dynamic content into the static page
document.getElementById("rule").innerHTML = `<p>${data.response}</p>`;
}
})
.catch(error => console.error('Error fetching rule!:', error));
}
getrule();
</script>
</body>
</html>

43
index.js Normal file
View file

@ -0,0 +1,43 @@
import index from "./index.html";
export default {
async fetch(request, env, ctx) {
const cacheUrl = new URL(request.url);
// Construct the cache key from the cache URL
const cacheKey = new Request(cacheUrl.toString(), request);
const cache = caches.default;
let response = await cache.match(cacheKey);
if (response) {
return response;
}
const url = new URL(request.url);
const { pathname } = url;
switch (pathname) {
case "/":
return new Response(index, {
headers: { "Content-Type": "text/html" }
});
case "/rule.json":
const simple = {
prompt: 'Give me a rule for a Discord server that is surreal, bizzare, and outlandish while still being somewhat realistic on first glance. Keep it short and succinct. Do not add any additional information, greetings, or quotation marks.'
};
const reply = await env.AI.run('@cf/meta/llama-3.1-8b-instruct', simple);
let response = new Response(JSON.stringify(reply), {
headers: { "Content-Type": "application/json",
"Cache-Control": "s-maxage=43200" }
});
ctx.waitUntil(cache.put(cacheKey, response.clone()));
return response;
default:
return new Response("not found", {status: 404});
}
}
};

5
package.json Normal file
View file

@ -0,0 +1,5 @@
{
"name": "thirdrule",
"version": "1.0.0",
"license": "ISC"
}

7
wrangler.toml Normal file
View file

@ -0,0 +1,7 @@
name = "thirdrule"
main = "index.js"
compatibility_date = "2023-08-23"
account_id = "7dc420732ea679a530aee304ea49a63c"
[ai]
binding = "AI"