Skip to content

Commit

Permalink
Merge pull request #70 from mbaraa/dev
Browse files Browse the repository at this point in the history
minor fixes
  • Loading branch information
mbaraa authored Jun 6, 2024
2 parents 607d500 + 9e41c8f commit 2266b6e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 6 deletions.
9 changes: 8 additions & 1 deletion app/handlers/apis/email_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ func (e *emailLoginApi) HandleEmailLogin(w http.ResponseWriter, r *http.Request)
}

verificationToken, err := e.service.Login(reqBody)
if err != nil {
if err != nil && errors.Is(err, login.ErrDifferentLoginMethod) {
log.Errorf("[EMAIL LOGIN API]: Failed to login user: %+v, error: %s\n", reqBody, err.Error())
// w.WriteHeader(http.StatusInternalServerError)
status.
BugsBunnyError("This account uses Google Auth to login!").
Render(context.Background(), w)
return
} else if err != nil {
log.Errorf("[EMAIL LOGIN API]: Failed to login user: %+v, error: %s\n", reqBody, err.Error())
// w.WriteHeader(http.StatusInternalServerError)
status.
Expand Down
10 changes: 9 additions & 1 deletion app/handlers/apis/google_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"dankmuzikk/log"
"dankmuzikk/services/login"
"dankmuzikk/views/components/status"
"errors"
"net/http"
"time"
)
Expand Down Expand Up @@ -39,7 +40,14 @@ func (g *googleLoginApi) HandleGoogleOAuthLoginCallback(w http.ResponseWriter, r
}

sessionToken, err := g.service.Login(state, code)
if err != nil {
if err != nil && errors.Is(err, login.ErrDifferentLoginMethod) {
log.Errorf("[EMAIL LOGIN API]: Failed to login, error: %s\n", err.Error())
// w.WriteHeader(http.StatusInternalServerError)
status.
BugsBunnyError("This account uses Email to login!").
Render(context.Background(), w)
return
} else if err != nil {
// w.WriteHeader(http.StatusUnauthorized)
status.
GenericError("Account doesn't exist").
Expand Down
5 changes: 4 additions & 1 deletion app/services/login/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ func NewEmailLoginService(
}

func (e *EmailLoginService) Login(user entities.LoginRequest) (string, error) {
account, err := e.accountRepo.GetByConds("email = ? AND is_o_auth = 0", user.Email)
account, err := e.accountRepo.GetByConds("email = ?", user.Email)
if err != nil {
return "", errors.Join(ErrAccountNotFound, err)
}
if account[0].IsOAuth {
return "", ErrDifferentLoginMethod
}

profile, err := e.profileRepo.GetByConds("account_id = ?", account[0].Id)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions app/services/login/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ var (
ErrAccountExists = errors.New("an account with the associated email already exists")
ErrExpiredVerificationCode = errors.New("expired verification code")
ErrInvalidVerificationCode = errors.New("invalid verification code")
ErrDifferentLoginMethod = errors.New("account uses a different login/signup method")
)
5 changes: 4 additions & 1 deletion app/services/login/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ func (g *GoogleLoginService) Login(state, code string) (string, error) {
return "", err
}

account, err := g.accountRepo.GetByConds("email = ? AND is_o_auth = 1", googleUser.Email)
account, err := g.accountRepo.GetByConds("email = ?", googleUser.Email)
if errors.Is(err, db.ErrRecordNotFound) || len(account) == 0 {
return g.Signup(googleUser)
}
if !account[0].IsOAuth {
return "", ErrDifferentLoginMethod
}
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion app/services/youtube/search/search_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (y *ScraperSearch) Search(query string) (results []entities.Song, err error
}

for _, res := range res {
if res.Id == "" || res.Title == "" || res.ThumbnailUrl == "" || res.Uploader == "" {
if res.Id == "" || res.Title == "" || res.ThumbnailUrl == "" || res.Uploader == "" || res.Duration == "" {
continue
}
duration := strings.Split(res.Duration, ":")
Expand Down
24 changes: 24 additions & 0 deletions app/static/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,30 @@ audioPlayerEl.addEventListener("progress", () => {
console.log("downloading...");
});

let playerStartY = 0;

playerEl?.addEventListener(
"touchstart",
(e) => {
playerStartY = e.touches[0].pageY;
},
{ passive: true },
);

playerEl?.addEventListener(
"touchmove",
async (e) => {
const y = e.touches[0].pageY;
if (y > playerStartY + 75) {
collapse();
}
if (y < playerStartY - 25) {
expand();
}
},
{ passive: true },
);

document
.getElementById("collapse-player-button")
?.addEventListener("click", (event) => {
Expand Down
7 changes: 6 additions & 1 deletion app/static/js/player_shortcuts.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
"use strict";

/**
* Using YouTube's applicaple shortcuts: https://support.google.com/youtube/answer/7631406?hl=en
* Using YouTube's applicable shortcuts: https://support.google.com/youtube/answer/7631406?hl=en
*
* set those characters in Vimium's excluded patterns if you still wanna navigate the site using Vimium,
* l r k n N p P s m M 0 1 2 3 4 5 6 7 8 9 $ i I /
*/
const shortcuts = {
" ": togglePP,
l: () => toggleLoop(),
r: () => toggleShuffle(),
k: togglePP,
n: nextMuzikk,
N: nextMuzikk,
Expand Down

0 comments on commit 2266b6e

Please sign in to comment.