diff --git a/api/go.mod b/api/go.mod new file mode 100644 index 0000000..9806ead --- /dev/null +++ b/api/go.mod @@ -0,0 +1,5 @@ +module cs2440.joshashton.dev/api + +go 1.23.5 + +require github.com/joho/godotenv v1.5.1 // indirect diff --git a/api/go.sum b/api/go.sum new file mode 100644 index 0000000..d61b19e --- /dev/null +++ b/api/go.sum @@ -0,0 +1,2 @@ +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= diff --git a/api/main.go b/api/main.go new file mode 100644 index 0000000..34a1f5e --- /dev/null +++ b/api/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "crypto/rand" + "fmt" + "github.com/joho/godotenv" + "log" + "net/http" + "os" + "strings" +) + +func generateRandomString(length int) string { + var b = make([]byte, length) + rand.Read(b) + return fmt.Sprintf("%x", b) +} + +func main() { + err := godotenv.Load("../.env") + if err != nil { + log.Fatalf("Error loading .env file: %s", err) + } + client_id := os.Getenv("SPOTIFY_CLIENT_ID") + + redirect_uri := "http://localhost/music" + + http.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) { + scope := "user-top-read" + + redirectURL := "https://accounts.spotify.com/authorize?" + strings.Join([]string{ + "response_type=code", + "client_id=" + client_id, + "scope=" + scope, + "redirect_uri=" + redirect_uri, + }, "&") + + http.Redirect(w, r, redirectURL, http.StatusFound) + }) + + http.ListenAndServe(":8080", nil) +} diff --git a/music/core.php b/music/core.php index 2e7f596..66c494b 100644 --- a/music/core.php +++ b/music/core.php @@ -1,30 +1,28 @@ 'Abyss', 'artist' => 'Pastel Ghost', 'link' => 'https://open.spotify.com/album/2FQieUp8BxPN7OR8fE76TE'), - array('name' => 'Golden Age - The 4th Album', 'artist' => 'NCT 127', 'link' => 'https://open.spotify.com/album/5mUo2e4QpUA7NJl2t51uFu'), - array('name' => 'To Pimp a Butterfly', 'artist' => 'Kendrick Lamar', 'link' => 'https://open.spotify.com/album/7ycBtnsMtyVbbwTfJwRjSP'), - array('name' => 'Off the Wall', 'artist' => 'Michael Jackson', 'link' => 'https://open.spotify.com/album/2ZytN2cY4Zjrr9ukb2rqTP'), - array('name' => 'Vol. 3: The Subliminal Verses', 'artist' => 'Slipknot', 'link' => 'https://open.spotify.com/album/4ZDBQSIDIZRUBOG2OHcN3T'), - array('name' => 'Этажи', 'artist' => 'Molchat Doma', 'link' => 'https://open.spotify.com/album/1FHREwXgTQvqiG8q5KlRzc'), - array('name' => 'Hot Pink', 'artist' => 'Doja Cat', 'link' => 'https://open.spotify.com/album/1MmVkhiwTH0BkNOU3nw5d3'), - array('name' => 'Currents', 'artist' => 'Tame Impala', 'link' => 'https://open.spotify.com/album/79dL7FLiJFOO0EoehUHQBv'), - array('name' => 'INSIDE', 'artist' => 'Bo Burnham', 'link' => 'https://open.spotify.com/album/35qVMfUfBN6q2xzm9rZn5a'), - array('name' => 'Teenage Dream', 'artist' => 'Katy Perry', 'link' => 'https://open.spotify.com/album/2eQMC9nJE3f3hCNKlYYHL1'), - ]; - shuffle($albums); +$albums = [ + array('name' => 'Abyss', 'artist' => 'Pastel Ghost', 'link' => 'https://open.spotify.com/album/2FQieUp8BxPN7OR8fE76TE'), + array('name' => 'Golden Age - The 4th Album', 'artist' => 'NCT 127', 'link' => 'https://open.spotify.com/album/5mUo2e4QpUA7NJl2t51uFu'), + array('name' => 'To Pimp a Butterfly', 'artist' => 'Kendrick Lamar', 'link' => 'https://open.spotify.com/album/7ycBtnsMtyVbbwTfJwRjSP'), + array('name' => 'Off the Wall', 'artist' => 'Michael Jackson', 'link' => 'https://open.spotify.com/album/2ZytN2cY4Zjrr9ukb2rqTP'), + array('name' => 'Vol. 3: The Subliminal Verses', 'artist' => 'Slipknot', 'link' => 'https://open.spotify.com/album/4ZDBQSIDIZRUBOG2OHcN3T'), + array('name' => 'Этажи', 'artist' => 'Molchat Doma', 'link' => 'https://open.spotify.com/album/1FHREwXgTQvqiG8q5KlRzc'), + array('name' => 'Hot Pink', 'artist' => 'Doja Cat', 'link' => 'https://open.spotify.com/album/1MmVkhiwTH0BkNOU3nw5d3'), + array('name' => 'Currents', 'artist' => 'Tame Impala', 'link' => 'https://open.spotify.com/album/79dL7FLiJFOO0EoehUHQBv'), + array('name' => 'INSIDE', 'artist' => 'Bo Burnham', 'link' => 'https://open.spotify.com/album/35qVMfUfBN6q2xzm9rZn5a'), + array('name' => 'Teenage Dream', 'artist' => 'Katy Perry', 'link' => 'https://open.spotify.com/album/2eQMC9nJE3f3hCNKlYYHL1'), +]; +shuffle($albums); - $content = ''; - foreach ($albums as $album) { - $content = $content . ' +$content = ''; +foreach ($albums as $album) { + $content = $content . '
| Name | @@ -34,6 +32,5 @@ function get_core()
|---|