mirror of
https://github.com/JuLi0n21/pwa-player.git
synced 2026-04-19 23:40:05 +00:00
actual changes :3
This commit is contained in:
@@ -669,8 +669,8 @@ const docTemplate = `{
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = &swag.Spec{
|
||||
Version: "1.0",
|
||||
Host: "localhost:8080",
|
||||
BasePath: "/api/v1/",
|
||||
Host: "",
|
||||
BasePath: "api/v1/",
|
||||
Schemes: []string{},
|
||||
Title: "go-osu-music-hoster",
|
||||
Description: "Server Hosting ur own osu files over a simple Api",
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"contact": {},
|
||||
"version": "1.0"
|
||||
},
|
||||
"host": "localhost:8080",
|
||||
"host": "/",
|
||||
"basePath": "/api/v1/",
|
||||
"paths": {
|
||||
"/audio/{filepath}": {
|
||||
|
||||
@@ -69,7 +69,7 @@ definitions:
|
||||
example: 240
|
||||
type: integer
|
||||
type: object
|
||||
host: localhost:8080
|
||||
host: /
|
||||
info:
|
||||
contact: {}
|
||||
description: Server Hosting ur own osu files over a simple Api
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module backend
|
||||
|
||||
go 1.23.5
|
||||
go 1.24.3
|
||||
|
||||
require (
|
||||
github.com/joho/godotenv v1.5.1
|
||||
|
||||
@@ -31,32 +31,58 @@ type Server struct {
|
||||
Env map[string]string
|
||||
}
|
||||
|
||||
func (s *Server) registerRoutes() {
|
||||
http.HandleFunc("/api/v1/ping", s.ping)
|
||||
http.HandleFunc("/api/v1/login", s.login)
|
||||
func (s *Server) registerRoutes() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
http.HandleFunc("/api/v1/song/{hash}/", s.song)
|
||||
http.HandleFunc("/api/v1/songs/recents", s.recents)
|
||||
http.HandleFunc("/api/v1/songs/favorites", s.favorites)
|
||||
http.HandleFunc("/api/v1/songs/artist", s.aristsSongs)
|
||||
mux.HandleFunc("/api/v1/ping", s.ping)
|
||||
mux.HandleFunc("/api/v1/login", s.login)
|
||||
|
||||
http.HandleFunc("/api/v1/collection", s.collection)
|
||||
http.HandleFunc("/api/v1/search/collections", s.collectionSearch)
|
||||
mux.HandleFunc("/api/v1/song/{hash}/", s.song)
|
||||
mux.HandleFunc("/api/v1/songs/recent", s.recents)
|
||||
mux.HandleFunc("/api/v1/songs/favorites", s.favorites)
|
||||
mux.HandleFunc("/api/v1/songs/artist", s.aristsSongs)
|
||||
|
||||
http.HandleFunc("/api/v1/search/active", s.activeSearch)
|
||||
http.HandleFunc("/api/v1/search/artist", s.artistSearch)
|
||||
mux.HandleFunc("/api/v1/collection", s.collection)
|
||||
mux.HandleFunc("/api/v1/search/collections", s.collectionSearch)
|
||||
|
||||
http.HandleFunc("/api/v1/audio/{filepath}", s.songFile)
|
||||
http.HandleFunc("/api/v1/image/{filepath}", s.imageFile)
|
||||
mux.HandleFunc("/api/v1/search/active", s.activeSearch)
|
||||
mux.HandleFunc("/api/v1/search/artist", s.artistSearch)
|
||||
|
||||
http.HandleFunc("/api/v1/callback", s.callback)
|
||||
http.Handle("/swagger/", httpSwagger.WrapHandler)
|
||||
mux.HandleFunc("/api/v1/audio/{filepath}", s.songFile)
|
||||
mux.HandleFunc("/api/v1/image/{filepath}", s.imageFile)
|
||||
|
||||
mux.HandleFunc("/api/v1/callback", s.callback)
|
||||
mux.Handle("/swagger/", httpSwagger.WrapHandler)
|
||||
|
||||
return corsMiddleware(logRequests(mux))
|
||||
}
|
||||
|
||||
func run(s *Server) {
|
||||
s.registerRoutes()
|
||||
mux := s.registerRoutes()
|
||||
fmt.Println("starting server on http://localhost" + s.Port)
|
||||
log.Fatal(http.ListenAndServe(s.Port, nil))
|
||||
log.Fatal(http.ListenAndServe(s.Port, mux))
|
||||
}
|
||||
|
||||
func logRequests(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL.Path)
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func corsMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
// ping godoc
|
||||
|
||||
@@ -21,10 +21,9 @@ import (
|
||||
// @version 1.0
|
||||
// @description Server Hosting ur own osu files over a simple Api
|
||||
|
||||
// @host localhost:8080
|
||||
// @host /
|
||||
// @BasePath /api/v1/
|
||||
func main() {
|
||||
|
||||
envMap, err := godotenv.Read(".env")
|
||||
if err != nil {
|
||||
fmt.Println("Error reading .env file")
|
||||
@@ -125,7 +124,7 @@ func StartCloudflared(port string) (string, error) {
|
||||
}
|
||||
|
||||
func sendUrl(endpoint, cookie string) error {
|
||||
url := "http://proxy.illegalesachen.download/settings"
|
||||
url := GetEnv("PROXY_URL", "https://proxy.illegalesachen.download/settings")
|
||||
|
||||
payload := struct {
|
||||
Sharing *bool `json:"sharing"`
|
||||
@@ -137,22 +136,19 @@ func sendUrl(endpoint, cookie string) error {
|
||||
body, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error marshalling payload: %v", err)
|
||||
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating request: %v", err)
|
||||
return fmt.Errorf("failed to create request: %v", err)
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
req.AddCookie(&http.Cookie{
|
||||
Name: "session_cookie",
|
||||
Value: cookie,
|
||||
})
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
fmt.Println(req)
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
@@ -163,6 +159,5 @@ func sendUrl(endpoint, cookie string) error {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("Error in request: %s", resp.Status)
|
||||
}
|
||||
fmt.Println("Response Status:", resp.Status)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user