refactor: rewrite in Go
NOTE: docker not working anymore
@@ -1,3 +0,0 @@
|
|||||||
node_modules
|
|
||||||
.nuxt
|
|
||||||
.output
|
|
||||||
28
.gitignore
vendored
@@ -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
@@ -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>
|
|
||||||
@@ -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>
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// @ts-check
|
|
||||||
import withNuxt from "./.nuxt/eslint.config.mjs";
|
|
||||||
|
|
||||||
export default withNuxt();
|
|
||||||
93
main.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,8 @@ 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"
|
||||||
|
cwebp "$file" -resize $IMG_SZ $IMG_SZ -o "$out"
|
||||||
|
magick "$out" -rotate 90 "$out"
|
||||||
rm "$file"
|
rm "$file"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -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"],
|
|
||||||
});
|
|
||||||
25
package.json
@@ -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
|
Before Width: | Height: | Size: 221 KiB After Width: | Height: | Size: 221 KiB |
154
public/index.html
Normal file
|
Before Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 74 KiB |
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 185 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 26 KiB |
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
@@ -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;
|
|
||||||
});
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../.nuxt/tsconfig.server.json"
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
// https://nuxt.com/docs/guide/concepts/typescript
|
|
||||||
"extends": "./.nuxt/tsconfig.json"
|
|
||||||
}
|
|
||||||