Skip to content

Commit 2266b6e

Browse files
authored
Merge pull request #70 from mbaraa/dev
minor fixes
2 parents 607d500 + 9e41c8f commit 2266b6e

File tree

8 files changed

+57
-6
lines changed

8 files changed

+57
-6
lines changed

app/handlers/apis/email_login.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ func (e *emailLoginApi) HandleEmailLogin(w http.ResponseWriter, r *http.Request)
3333
}
3434

3535
verificationToken, err := e.service.Login(reqBody)
36-
if err != nil {
36+
if err != nil && errors.Is(err, login.ErrDifferentLoginMethod) {
37+
log.Errorf("[EMAIL LOGIN API]: Failed to login user: %+v, error: %s\n", reqBody, err.Error())
38+
// w.WriteHeader(http.StatusInternalServerError)
39+
status.
40+
BugsBunnyError("This account uses Google Auth to login!").
41+
Render(context.Background(), w)
42+
return
43+
} else if err != nil {
3744
log.Errorf("[EMAIL LOGIN API]: Failed to login user: %+v, error: %s\n", reqBody, err.Error())
3845
// w.WriteHeader(http.StatusInternalServerError)
3946
status.

app/handlers/apis/google_login.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"dankmuzikk/log"
88
"dankmuzikk/services/login"
99
"dankmuzikk/views/components/status"
10+
"errors"
1011
"net/http"
1112
"time"
1213
)
@@ -39,7 +40,14 @@ func (g *googleLoginApi) HandleGoogleOAuthLoginCallback(w http.ResponseWriter, r
3940
}
4041

4142
sessionToken, err := g.service.Login(state, code)
42-
if err != nil {
43+
if err != nil && errors.Is(err, login.ErrDifferentLoginMethod) {
44+
log.Errorf("[EMAIL LOGIN API]: Failed to login, error: %s\n", err.Error())
45+
// w.WriteHeader(http.StatusInternalServerError)
46+
status.
47+
BugsBunnyError("This account uses Email to login!").
48+
Render(context.Background(), w)
49+
return
50+
} else if err != nil {
4351
// w.WriteHeader(http.StatusUnauthorized)
4452
status.
4553
GenericError("Account doesn't exist").

app/services/login/email.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ func NewEmailLoginService(
3636
}
3737

3838
func (e *EmailLoginService) Login(user entities.LoginRequest) (string, error) {
39-
account, err := e.accountRepo.GetByConds("email = ? AND is_o_auth = 0", user.Email)
39+
account, err := e.accountRepo.GetByConds("email = ?", user.Email)
4040
if err != nil {
4141
return "", errors.Join(ErrAccountNotFound, err)
4242
}
43+
if account[0].IsOAuth {
44+
return "", ErrDifferentLoginMethod
45+
}
4346

4447
profile, err := e.profileRepo.GetByConds("account_id = ?", account[0].Id)
4548
if err != nil {

app/services/login/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ var (
88
ErrAccountExists = errors.New("an account with the associated email already exists")
99
ErrExpiredVerificationCode = errors.New("expired verification code")
1010
ErrInvalidVerificationCode = errors.New("invalid verification code")
11+
ErrDifferentLoginMethod = errors.New("account uses a different login/signup method")
1112
)

app/services/login/google.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ func (g *GoogleLoginService) Login(state, code string) (string, error) {
6363
return "", err
6464
}
6565

66-
account, err := g.accountRepo.GetByConds("email = ? AND is_o_auth = 1", googleUser.Email)
66+
account, err := g.accountRepo.GetByConds("email = ?", googleUser.Email)
6767
if errors.Is(err, db.ErrRecordNotFound) || len(account) == 0 {
6868
return g.Signup(googleUser)
6969
}
70+
if !account[0].IsOAuth {
71+
return "", ErrDifferentLoginMethod
72+
}
7073
if err != nil {
7174
return "", err
7275
}

app/services/youtube/search/search_scraper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (y *ScraperSearch) Search(query string) (results []entities.Song, err error
144144
}
145145

146146
for _, res := range res {
147-
if res.Id == "" || res.Title == "" || res.ThumbnailUrl == "" || res.Uploader == "" {
147+
if res.Id == "" || res.Title == "" || res.ThumbnailUrl == "" || res.Uploader == "" || res.Duration == "" {
148148
continue
149149
}
150150
duration := strings.Split(res.Duration, ":")

app/static/js/player.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,30 @@ audioPlayerEl.addEventListener("progress", () => {
886886
console.log("downloading...");
887887
});
888888

889+
let playerStartY = 0;
890+
891+
playerEl?.addEventListener(
892+
"touchstart",
893+
(e) => {
894+
playerStartY = e.touches[0].pageY;
895+
},
896+
{ passive: true },
897+
);
898+
899+
playerEl?.addEventListener(
900+
"touchmove",
901+
async (e) => {
902+
const y = e.touches[0].pageY;
903+
if (y > playerStartY + 75) {
904+
collapse();
905+
}
906+
if (y < playerStartY - 25) {
907+
expand();
908+
}
909+
},
910+
{ passive: true },
911+
);
912+
889913
document
890914
.getElementById("collapse-player-button")
891915
?.addEventListener("click", (event) => {

app/static/js/player_shortcuts.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
"use strict";
22

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

0 commit comments

Comments
 (0)