Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update logo (fr this time) #98

Merged
merged 11 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PORT=3000
GO_ENV="dev" # "beta" "prod"
HOSTNAME="http://localhost:3000"
JWT_SECRET="spoikoninochi"

Expand Down
20 changes: 0 additions & 20 deletions app/Dockerfile.beta

This file was deleted.

7 changes: 2 additions & 5 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ init:
go generate && \
go run main.go migrate

seed:
go run main.go seed

dev:
go run github.com/cosmtrek/[email protected]

beta:
./${BINARY_NAME} serve
GO_ENV="beta" ./${BINARY_NAME} serve

prod:
./${BINARY_NAME} migrate
./${BINARY_NAME} serve
GO_ENV="prod" ./${BINARY_NAME} serve

clean:
go clean
Expand Down
65 changes: 36 additions & 29 deletions app/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package server
import (
"dankmuzikk/config"
"dankmuzikk/db"
"dankmuzikk/handlers"
"dankmuzikk/handlers/apis"
"dankmuzikk/handlers/middlewares/auth"
"dankmuzikk/handlers/middlewares/contenttype"
"dankmuzikk/handlers/middlewares/ismobile"
"dankmuzikk/handlers/middlewares/logger"
"dankmuzikk/handlers/middlewares/theme"
"dankmuzikk/handlers/pages"
"dankmuzikk/log"
"dankmuzikk/models"
Expand Down Expand Up @@ -53,7 +57,7 @@ func StartServer(staticFS embed.FS) error {

jwtUtil := jwt.NewJWTImpl()

gHandler := handlers.NewHandler(profileRepo, jwtUtil)
authMw := auth.New(profileRepo, jwtUtil)

///////////// Pages and files /////////////
pagesHandler := http.NewServeMux()
Expand All @@ -74,16 +78,16 @@ func StartServer(staticFS embed.FS) error {
pagesHandler.Handle("/muzikkx/", http.StripPrefix("/muzikkx", http.FileServer(http.Dir(config.Env().YouTube.MusicDir))))

pagesRouter := pages.NewPagesHandler(profileRepo, playlistsService, jwtUtil, &search.ScraperSearch{}, downloadService, historyService, songsService)
pagesHandler.HandleFunc("/", gHandler.OptionalAuthPage(pagesRouter.HandleHomePage))
pagesHandler.HandleFunc("GET /signup", gHandler.AuthPage(pagesRouter.HandleSignupPage))
pagesHandler.HandleFunc("GET /login", gHandler.AuthPage(pagesRouter.HandleLoginPage))
pagesHandler.HandleFunc("GET /profile", gHandler.AuthPage(pagesRouter.HandleProfilePage))
pagesHandler.HandleFunc("GET /about", gHandler.NoAuthPage(pagesRouter.HandleAboutPage))
pagesHandler.HandleFunc("GET /playlists", gHandler.AuthPage(pagesRouter.HandlePlaylistsPage))
pagesHandler.HandleFunc("GET /playlist/{playlist_id}", gHandler.AuthPage(pagesRouter.HandleSinglePlaylistPage))
pagesHandler.HandleFunc("GET /song/{song_id}", gHandler.OptionalAuthPage(pagesRouter.HandleSingleSongPage))
pagesHandler.HandleFunc("GET /privacy", gHandler.NoAuthPage(pagesRouter.HandlePrivacyPage))
pagesHandler.HandleFunc("GET /search", gHandler.OptionalAuthPage(pagesRouter.HandleSearchResultsPage))
pagesHandler.HandleFunc("/", contenttype.Html(authMw.OptionalAuthPage(pagesRouter.HandleHomePage)))
pagesHandler.HandleFunc("GET /signup", contenttype.Html(authMw.AuthPage(pagesRouter.HandleSignupPage)))
pagesHandler.HandleFunc("GET /login", contenttype.Html(authMw.AuthPage(pagesRouter.HandleLoginPage)))
pagesHandler.HandleFunc("GET /profile", contenttype.Html(authMw.AuthPage(pagesRouter.HandleProfilePage)))
pagesHandler.HandleFunc("GET /about", contenttype.Html(pagesRouter.HandleAboutPage))
pagesHandler.HandleFunc("GET /playlists", contenttype.Html(authMw.AuthPage(pagesRouter.HandlePlaylistsPage)))
pagesHandler.HandleFunc("GET /playlist/{playlist_id}", contenttype.Html(authMw.AuthPage(pagesRouter.HandleSinglePlaylistPage)))
pagesHandler.HandleFunc("GET /song/{song_id}", contenttype.Html(authMw.OptionalAuthPage(pagesRouter.HandleSingleSongPage)))
pagesHandler.HandleFunc("GET /privacy", contenttype.Html(pagesRouter.HandlePrivacyPage))
pagesHandler.HandleFunc("GET /search", contenttype.Html(authMw.OptionalAuthPage(pagesRouter.HandleSearchResultsPage)))

///////////// APIs /////////////

Expand All @@ -102,25 +106,28 @@ func StartServer(staticFS embed.FS) error {
apisHandler.HandleFunc("/login/google/callback", googleLoginApi.HandleGoogleOAuthLoginCallback)
apisHandler.HandleFunc("GET /logout", apis.HandleLogout)
apisHandler.HandleFunc("GET /search-suggestion", apis.HandleSearchSuggestions)
apisHandler.HandleFunc("GET /song", gHandler.OptionalAuthApi(songApi.HandlePlaySong))
apisHandler.HandleFunc("GET /song/single", gHandler.OptionalAuthApi(songApi.HandleGetSong))
apisHandler.HandleFunc("PUT /song/playlist", gHandler.AuthApi(playlistsApi.HandleToggleSongInPlaylist))
apisHandler.HandleFunc("PUT /song/playlist/plays", gHandler.AuthApi(songApi.HandleIncrementSongPlaysInPlaylist))
apisHandler.HandleFunc("PUT /song/playlist/upvote", gHandler.AuthApi(songApi.HandleUpvoteSongPlaysInPlaylist))
apisHandler.HandleFunc("PUT /song/playlist/downvote", gHandler.AuthApi(songApi.HandleDownvoteSongPlaysInPlaylist))
apisHandler.HandleFunc("GET /playlist/all", gHandler.AuthApi(playlistsApi.HandleGetPlaylistsForPopover))
apisHandler.HandleFunc("GET /playlist", gHandler.AuthApi(playlistsApi.HandleGetPlaylist))
apisHandler.HandleFunc("POST /playlist", gHandler.AuthApi(playlistsApi.HandleCreatePlaylist))
apisHandler.HandleFunc("PUT /playlist/public", gHandler.AuthApi(playlistsApi.HandleTogglePublicPlaylist))
apisHandler.HandleFunc("PUT /playlist/join", gHandler.AuthApi(playlistsApi.HandleToggleJoinPlaylist))
apisHandler.HandleFunc("DELETE /playlist", gHandler.AuthApi(playlistsApi.HandleDeletePlaylist))
apisHandler.HandleFunc("GET /playlist/zip", gHandler.AuthApi(playlistsApi.HandleDonwnloadPlaylist))
apisHandler.HandleFunc("GET /history/{page}", gHandler.AuthApi(historyApi.HandleGetMoreHistoryItems))
apisHandler.HandleFunc("GET /song", authMw.OptionalAuthApi(songApi.HandlePlaySong))
apisHandler.HandleFunc("GET /song/single", authMw.OptionalAuthApi(songApi.HandleGetSong))
apisHandler.HandleFunc("PUT /song/playlist", authMw.AuthApi(playlistsApi.HandleToggleSongInPlaylist))
apisHandler.HandleFunc("PUT /song/playlist/plays", authMw.AuthApi(songApi.HandleIncrementSongPlaysInPlaylist))
apisHandler.HandleFunc("PUT /song/playlist/upvote", authMw.AuthApi(songApi.HandleUpvoteSongPlaysInPlaylist))
apisHandler.HandleFunc("PUT /song/playlist/downvote", authMw.AuthApi(songApi.HandleDownvoteSongPlaysInPlaylist))
apisHandler.HandleFunc("GET /playlist/all", authMw.AuthApi(playlistsApi.HandleGetPlaylistsForPopover))
apisHandler.HandleFunc("GET /playlist", authMw.AuthApi(playlistsApi.HandleGetPlaylist))
apisHandler.HandleFunc("POST /playlist", authMw.AuthApi(playlistsApi.HandleCreatePlaylist))
apisHandler.HandleFunc("PUT /playlist/public", authMw.AuthApi(playlistsApi.HandleTogglePublicPlaylist))
apisHandler.HandleFunc("PUT /playlist/join", authMw.AuthApi(playlistsApi.HandleToggleJoinPlaylist))
apisHandler.HandleFunc("DELETE /playlist", authMw.AuthApi(playlistsApi.HandleDeletePlaylist))
apisHandler.HandleFunc("GET /playlist/zip", authMw.AuthApi(playlistsApi.HandleDonwnloadPlaylist))
apisHandler.HandleFunc("GET /history/{page}", authMw.AuthApi(historyApi.HandleGetMoreHistoryItems))

applicationHandler := http.NewServeMux()
applicationHandler.Handle("/", pagesHandler)
applicationHandler.Handle("/api/", http.StripPrefix("/api", apisHandler))
applicationHandler.Handle("/", ismobile.Handler(theme.Handler(pagesHandler)))
applicationHandler.Handle("/api/", ismobile.Handler(theme.Handler(http.StripPrefix("/api", apisHandler))))

log.Info("Starting http server at port " + config.Env().Port)
return http.ListenAndServe(":"+config.Env().Port, m.Middleware(applicationHandler))
if config.Env().GoEnv == "dev" || config.Env().GoEnv == "beta" {
return http.ListenAndServe(":"+config.Env().Port, logger.Handler(ismobile.Handler(theme.Handler(m.Middleware(applicationHandler)))))
}
return http.ListenAndServe(":"+config.Env().Port, ismobile.Handler(theme.Handler(m.Middleware(applicationHandler))))
}
2 changes: 2 additions & 0 deletions app/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
func initEnvVars() {
_config = config{
Port: getEnv("PORT"),
GoEnv: getEnv("GO_ENV"),
Hostname: getEnv("HOSTNAME"),
JwtSecret: getEnv("JWT_SECRET"),
YouTube: struct {
Expand Down Expand Up @@ -57,6 +58,7 @@ func initEnvVars() {

type config struct {
Port string
GoEnv string
Hostname string
JwtSecret string
YouTube struct {
Expand Down
10 changes: 5 additions & 5 deletions app/handlers/apis/email_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"dankmuzikk/config"
"dankmuzikk/entities"
"dankmuzikk/handlers"
"dankmuzikk/handlers/middlewares/auth"
"dankmuzikk/log"
"dankmuzikk/services/login"
"dankmuzikk/views/components/otp"
Expand Down Expand Up @@ -50,7 +50,7 @@ func (e *emailLoginApi) HandleEmailLogin(w http.ResponseWriter, r *http.Request)
}

http.SetCookie(w, &http.Cookie{
Name: handlers.VerificationTokenKey,
Name: auth.VerificationTokenKey,
Value: verificationToken,
HttpOnly: true,
Path: "/api/verify-otp",
Expand Down Expand Up @@ -87,7 +87,7 @@ func (e *emailLoginApi) HandleEmailSignup(w http.ResponseWriter, r *http.Request
}

http.SetCookie(w, &http.Cookie{
Name: handlers.VerificationTokenKey,
Name: auth.VerificationTokenKey,
Value: verificationToken,
HttpOnly: true,
Path: "/api/verify-otp",
Expand All @@ -98,7 +98,7 @@ func (e *emailLoginApi) HandleEmailSignup(w http.ResponseWriter, r *http.Request
}

func (e *emailLoginApi) HandleEmailOTPVerification(w http.ResponseWriter, r *http.Request) {
verificationToken, err := r.Cookie(handlers.VerificationTokenKey)
verificationToken, err := r.Cookie(auth.VerificationTokenKey)
if err != nil {
// w.Write([]byte("Invalid verification token"))
status.
Expand Down Expand Up @@ -148,7 +148,7 @@ func (e *emailLoginApi) HandleEmailOTPVerification(w http.ResponseWriter, r *htt
}

http.SetCookie(w, &http.Cookie{
Name: handlers.SessionTokenKey,
Name: auth.SessionTokenKey,
Value: sessionToken,
HttpOnly: true,
Path: "/",
Expand Down
4 changes: 2 additions & 2 deletions app/handlers/apis/google_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package apis
import (
"context"
"dankmuzikk/config"
"dankmuzikk/handlers"
"dankmuzikk/handlers/middlewares/auth"
"dankmuzikk/log"
"dankmuzikk/services/login"
"dankmuzikk/views/components/status"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (g *googleLoginApi) HandleGoogleOAuthLoginCallback(w http.ResponseWriter, r
}

http.SetCookie(w, &http.Cookie{
Name: handlers.SessionTokenKey,
Name: auth.SessionTokenKey,
Value: sessionToken,
HttpOnly: true,
Path: "/",
Expand Down
4 changes: 2 additions & 2 deletions app/handlers/apis/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package apis
import (
"bytes"
"dankmuzikk/entities"
"dankmuzikk/handlers"
"dankmuzikk/handlers/middlewares/auth"
"dankmuzikk/log"
"dankmuzikk/services/history"
"dankmuzikk/views/components/playlist"
Expand All @@ -24,7 +24,7 @@ func NewHistoryApi(service *history.Service) *historyApi {
}

func (h *historyApi) HandleGetMoreHistoryItems(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.WriteHeader(http.StatusUnauthorized)
return
Expand Down
4 changes: 2 additions & 2 deletions app/handlers/apis/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package apis

import (
"dankmuzikk/config"
"dankmuzikk/handlers"
"dankmuzikk/handlers/middlewares/auth"
"net/http"
)

func HandleLogout(w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, &http.Cookie{
Name: handlers.SessionTokenKey,
Name: auth.SessionTokenKey,
Value: "",
Path: "/",
Domain: config.Env().Hostname,
Expand Down
18 changes: 9 additions & 9 deletions app/handlers/apis/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package apis
import (
"context"
"dankmuzikk/entities"
"dankmuzikk/handlers"
"dankmuzikk/handlers/middlewares/auth"
"dankmuzikk/log"
"dankmuzikk/services/playlists"
"dankmuzikk/services/playlists/songs"
Expand All @@ -26,7 +26,7 @@ func NewPlaylistApi(service *playlists.Service, songService *songs.Service) *pla
}

func (p *playlistApi) HandleCreatePlaylist(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.Write([]byte("🤷‍♂️"))
return
Expand Down Expand Up @@ -57,7 +57,7 @@ func (p *playlistApi) HandleCreatePlaylist(w http.ResponseWriter, r *http.Reques
}

func (p *playlistApi) HandleToggleSongInPlaylist(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.Write([]byte("🤷‍♂️"))
return
Expand Down Expand Up @@ -89,7 +89,7 @@ func (p *playlistApi) HandleToggleSongInPlaylist(w http.ResponseWriter, r *http.
}

func (p *playlistApi) HandleTogglePublicPlaylist(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.Write([]byte("🤷‍♂️"))
return
Expand All @@ -116,7 +116,7 @@ func (p *playlistApi) HandleTogglePublicPlaylist(w http.ResponseWriter, r *http.
}

func (p *playlistApi) HandleToggleJoinPlaylist(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.Write([]byte("🤷‍♂️"))
return
Expand Down Expand Up @@ -145,7 +145,7 @@ func (p *playlistApi) HandleToggleJoinPlaylist(w http.ResponseWriter, r *http.Re
}

func (p *playlistApi) HandleGetPlaylist(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.Write([]byte("🤷‍♂️"))
return
Expand All @@ -167,7 +167,7 @@ func (p *playlistApi) HandleGetPlaylist(w http.ResponseWriter, r *http.Request)
}

func (p *playlistApi) HandleDeletePlaylist(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.Write([]byte("🤷‍♂️"))
return
Expand All @@ -190,7 +190,7 @@ func (p *playlistApi) HandleDeletePlaylist(w http.ResponseWriter, r *http.Reques
}

func (p *playlistApi) HandleGetPlaylistsForPopover(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.Write([]byte("🤷‍♂️"))
return
Expand All @@ -214,7 +214,7 @@ func (p *playlistApi) HandleGetPlaylistsForPopover(w http.ResponseWriter, r *htt
}

func (p *playlistApi) HandleDonwnloadPlaylist(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte("🤷‍♂️"))
Expand Down
10 changes: 5 additions & 5 deletions app/handlers/apis/songs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package apis

import (
"dankmuzikk/handlers"
"dankmuzikk/handlers/middlewares/auth"
"dankmuzikk/log"
"dankmuzikk/services/history"
"dankmuzikk/services/playlists/songs"
Expand Down Expand Up @@ -30,7 +30,7 @@ func NewDownloadHandler(
}

func (s *songDownloadHandler) HandleIncrementSongPlaysInPlaylist(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.Write([]byte("🤷‍♂️"))
return
Expand All @@ -55,7 +55,7 @@ func (s *songDownloadHandler) HandleIncrementSongPlaysInPlaylist(w http.Response
}

func (s *songDownloadHandler) HandleUpvoteSongPlaysInPlaylist(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.Write([]byte("🤷‍♂️"))
return
Expand All @@ -82,7 +82,7 @@ func (s *songDownloadHandler) HandleUpvoteSongPlaysInPlaylist(w http.ResponseWri
}

func (s *songDownloadHandler) HandleDownvoteSongPlaysInPlaylist(w http.ResponseWriter, r *http.Request) {
profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if !profileIdCorrect {
w.Write([]byte("🤷‍♂️"))
return
Expand Down Expand Up @@ -116,7 +116,7 @@ func (s *songDownloadHandler) HandlePlaySong(w http.ResponseWriter, r *http.Requ
return
}

profileId, profileIdCorrect := r.Context().Value(handlers.ProfileIdKey).(uint)
profileId, profileIdCorrect := r.Context().Value(auth.ProfileIdKey).(uint)
if profileIdCorrect {
err := s.historyService.AddSongToHistory(id, profileId)
if err != nil {
Expand Down
Loading