refactor: rewrite in Go

NOTE: docker not working anymore
This commit is contained in:
Pihkaal
2024-11-12 16:02:02 +01:00
parent 55c43df2a7
commit 85eac55045
99 changed files with 256 additions and 11762 deletions

View File

@@ -1,3 +0,0 @@
node_modules
.nuxt
.output

28
.gitignore vendored
View File

@@ -1,27 +1 @@
# Nuxt dev/build outputs lilou
.output
.data
.nuxt
.nitro
.cache
dist
# Node dependencies
node_modules
# Logs
logs
*.log
# Misc
.DS_Store
.fleet
.idea
# Local env files
.env
.env.*
!.env.example
# ESLint
.eslintcache

20
app.vue
View File

@@ -1,20 +0,0 @@
<script setup lang="ts">
useSeoMeta({
title: "Lilou Chat",
description: "Just ✨ Lilou ✨",
themeColor: "#fa86c4",
});
</script>
<template>
<div class="h-[100svh]">
<AppBody />
<StarshineGlitter />
</div>
</template>
<style>
body {
color: #fa86c4;
}
</style>

View File

@@ -1,26 +0,0 @@
<template>
<main
class="h-full items-center relative p-5 justify-center flex flex-col space-y-4 bg-[#fa86c4] z-10"
>
<NuxtRouteAnnouncer />
<h1
class="text-4xl md:text-5xl lg:text-6xl font-serif text-white dark:text-white"
>
Lilou
</h1>
<img
class="w-full max-w-[50vh] rotate-90"
src="https://lilou.cat/api"
alt="Lilou"
/>
<h1
class="text-4xl md:text-5xl lg:text-6xl font-serif text-white dark:text-white"
>
Lilou
</h1>
<div class="absolute inset-0">
<StarshineGlitter />
</div>
</main>
</template>

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +0,0 @@
// @ts-check
import withNuxt from "./.nuxt/eslint.config.mjs";
export default withNuxt();

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module lilou
go 1.23.2

93
main.go Normal file
View File

@@ -0,0 +1,93 @@
package main
import (
_ "embed"
"encoding/json"
"errors"
"fmt"
"io"
"math/rand"
"net/http"
"os"
"strings"
"time"
)
//go:embed public/index.html
var indexSrc string
const PORT = 3000
const CACHE_TTL = 5 * time.Minute
const STORAGE_URL = "https://storage.bunnycdn.com/lilou-cat/"
const CDN_URL = "https://lilou-cat.b-cdn.net/"
type Image struct {
ObjectName string
}
var (
cachedImages []string
cacheExpiration time.Time
)
func list_images() []string {
if time.Now().Before(cacheExpiration) {
return cachedImages
}
req, _ := http.NewRequest("GET", STORAGE_URL, nil)
req.Header.Add("Accept", "application/json")
req.Header.Add("AccessKey", os.Getenv("API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Printf("error: %s\n", err)
return []string{}
}
var images = []Image{}
err = json.NewDecoder(res.Body).Decode(&images)
defer res.Body.Close()
if err != nil {
fmt.Printf("error: %s\n", err)
return []string{}
}
var imageUrls = []string{}
for _, image := range images {
imageUrls = append(imageUrls, fmt.Sprintf("%s/%s", CDN_URL, image.ObjectName))
}
cachedImages = imageUrls
cacheExpiration = time.Now().Add(CACHE_TTL)
return imageUrls
}
func getPage(w http.ResponseWriter, r *http.Request) {
var images = list_images()
var image = images[rand.Intn(len(images))]
src := strings.Replace(indexSrc, "{{ IMAGE_URL }}", image, 1)
io.WriteString(w, src)
}
func getFavicon(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "public/favicon.ico")
}
func main() {
http.HandleFunc("/", getPage)
http.HandleFunc("/favicon.ico", getFavicon)
err := http.ListenAndServe(fmt.Sprintf(":%d", PORT), nil)
fmt.Printf("listening on port %d\n", PORT)
if errors.Is(err, http.ErrServerClosed) {
fmt.Printf("server closed\n")
} else if err != nil {
fmt.Printf("error starting server: %s\n", err)
os.Exit(1)
}
}

View File

@@ -6,8 +6,9 @@
IMG_SZ=1024 IMG_SZ=1024
for file in public/lilou/*.jpg; do for file in public/lilou/*.jpg; do
hash=$(md5sum "$file" | awk '{print $1}') hash=$(md5sum "$file" | awk '{print $1}')
cwebp "$file" -resize $IMG_SZ $IMG_SZ -o "./public/lilou/${hash}.webp" out="./public/lilou/${hash}.webp"
rm "$file" cwebp "$file" -resize $IMG_SZ $IMG_SZ -o "$out"
magick "$out" -rotate 90 "$out"
rm "$file"
done done

View File

@@ -1,6 +0,0 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: "2024-04-03",
devtools: { enabled: true },
modules: ["@nuxt/eslint", "@nuxtjs/tailwindcss"],
});

View File

@@ -1,25 +0,0 @@
{
"name": "nuxt-app",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"lint": "eslint . --cache --fix",
"format": "pnpx prettier --cache --write ."
},
"dependencies": {
"@nuxt/eslint": "^0.6.0",
"@nuxtjs/tailwindcss": "^6.12.2",
"nuxt": "^3.13.0",
"vue": "latest",
"vue-router": "latest"
},
"packageManager": "pnpm@9.11.0",
"devDependencies": {
"typescript": "5.5.4"
}
}

11550
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 KiB

After

Width:  |  Height:  |  Size: 221 KiB

154
public/index.html Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

View File

@@ -1 +0,0 @@

View File

@@ -1,10 +0,0 @@
import { resolve } from "path";
import { readdir, readFile } from "fs/promises";
export default defineEventHandler(async () => {
const images = await readdir(resolve("public", "lilou"));
const imageName = images[Math.floor(Math.random() * images.length)];
const image = await readFile(resolve("public", "lilou", imageName));
return image;
});

View File

@@ -1,3 +0,0 @@
{
"extends": "../.nuxt/tsconfig.server.json"
}

View File

@@ -1,4 +0,0 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}