From 9dbcc53fd106277fe9b067d52e1ab0ecf8087878 Mon Sep 17 00:00:00 2001 From: B4D_US3R Date: Fri, 13 Dec 2024 23:30:30 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=20=D0=BF=D1=8B?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=8C=D1=81=D1=8F=20=D1=87=D1=82=D0=BE-?= =?UTF-8?q?=D1=82=D0=BE=20=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BD=D0=B0=20JS.=20=D0=9D=D0=B5=D0=BD=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=B6=D1=83=20JS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ main.html => index.html | 5 +++-- main.go | 14 +++++++++++--- package.json | 15 +++++++++++++++ src/main.js | 7 +++++++ {static => src}/picnic.min.css | 0 6 files changed, 39 insertions(+), 5 deletions(-) rename main.html => index.html (88%) create mode 100644 package.json create mode 100644 src/main.js rename {static => src}/picnic.min.css (100%) diff --git a/.gitignore b/.gitignore index 84159ec..87af672 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ go.work images/ main +node_modules +dist +bun.lockb \ No newline at end of file diff --git a/main.html b/index.html similarity index 88% rename from main.html rename to index.html index abd0840..66ffe97 100644 --- a/main.html +++ b/index.html @@ -2,7 +2,8 @@ CatGirls Town - + + @@ -34,7 +35,7 @@
- +
diff --git a/main.go b/main.go index da5a027..1fc385e 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "math/rand" "net/http" "os" + "strings" "text/template" ) @@ -30,6 +31,11 @@ func GetRandImg() string { return picsArray[rand.Intn(len(picsArray))] } +func ReturnPicFilename(w http.ResponseWriter, req *http.Request) { + var picFilename io.Reader = strings.NewReader(GetRandImg()) + io.Copy(w, picFilename) +} + func ReturnPic(w http.ResponseWriter, req *http.Request) { picture, _ := os.Open(fmt.Sprintf("images/%v", GetRandImg())) var pictureReader io.Reader = picture @@ -38,7 +44,7 @@ func ReturnPic(w http.ResponseWriter, req *http.Request) { } func ReturnHTML(w http.ResponseWriter, req *http.Request) { - htmlOpen, err := template.ParseFiles("main.html") + htmlOpen, err := template.ParseFiles("dist/index.html") if err != nil { log.Println(err.Error()) return @@ -51,9 +57,11 @@ func ReturnHTML(w http.ResponseWriter, req *http.Request) { func main() { log.Println("Server Start") imagesDir := http.FileServer(http.Dir("images")) - staticDir := http.FileServer(http.Dir("static")) + staticDir := http.FileServer(http.Dir("dist/assets")) http.Handle("/images/", http.StripPrefix("/images/", imagesDir)) - http.Handle("/static/", http.StripPrefix("/static/", staticDir)) + http.Handle("/assets/", http.StripPrefix("/assets/", staticDir)) + + http.HandleFunc("/rand", ReturnPicFilename) http.HandleFunc("/", ReturnHTML) http.ListenAndServe(":3666", nil) } diff --git a/package.json b/package.json new file mode 100644 index 0000000..471491f --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "picRan", + "private": "true", + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview" + }, + "devDependencies": { + "vite": "^6.0.1", + "axios": "1.7.9" + } +} \ No newline at end of file diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..192b5da --- /dev/null +++ b/src/main.js @@ -0,0 +1,7 @@ +import axios from "axios"; + +let pictureId = document.getElementById("CatGirlPicture") +pictureId.onclick = function() { + let picFilename = axios.get(location.href + "rand") + console.log(picFilename) +} diff --git a/static/picnic.min.css b/src/picnic.min.css similarity index 100% rename from static/picnic.min.css rename to src/picnic.min.css