mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-22 08:25:14 +00:00
0.0.17
- Add check for registration_enabled on /register endpoint - Made songlookup check artist name as well
This commit is contained in:
parent
9cbb94fc56
commit
8324894b0f
@ -3,7 +3,7 @@ stages:
|
|||||||
- bundle
|
- bundle
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
VERSION: 0.0.16
|
VERSION: 0.0.17
|
||||||
|
|
||||||
build-go:
|
build-go:
|
||||||
image: golang:1.16.2
|
image: golang:1.16.2
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# 0.0.17
|
||||||
|
- Add check for registration_enabled on /register endpoint
|
||||||
|
- Made songlookup check artist name as well
|
||||||
|
|
||||||
# 0.0.16
|
# 0.0.16
|
||||||
- Add registration_enabled to /api/v1/serverinfo
|
- Add registration_enabled to /api/v1/serverinfo
|
||||||
- Add config table caching on save
|
- Add config table caching on save
|
||||||
|
@ -86,6 +86,21 @@ func HandleRequests(port string) {
|
|||||||
// API ENDPOINT HANDLING
|
// API ENDPOINT HANDLING
|
||||||
// handleRegister - Does as it says!
|
// handleRegister - Does as it says!
|
||||||
func handleRegister(w http.ResponseWriter, r *http.Request) {
|
func handleRegister(w http.ResponseWriter, r *http.Request) {
|
||||||
|
cachedRegistrationEnabled := getRedisVal("REGISTRATION_ENABLED")
|
||||||
|
if cachedRegistrationEnabled == "" {
|
||||||
|
registrationEnabled, err := getConfigValue("REGISTRATION_ENABLED")
|
||||||
|
if err != nil {
|
||||||
|
throwOkError(w, "Error checking if registration is enabled")
|
||||||
|
}
|
||||||
|
setRedisVal("REGISTRATION_ENABLED", registrationEnabled)
|
||||||
|
cachedRegistrationEnabled = registrationEnabled
|
||||||
|
}
|
||||||
|
|
||||||
|
if cachedRegistrationEnabled == "0" {
|
||||||
|
throwOkError(w, "Registration is currently disabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
regReq := RegisterRequest{}
|
regReq := RegisterRequest{}
|
||||||
decoder := json.NewDecoder(r.Body)
|
decoder := json.NewDecoder(r.Body)
|
||||||
err := decoder.Decode(®Req)
|
err := decoder.Decode(®Req)
|
||||||
@ -462,7 +477,7 @@ func fetchServerInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info := ServerInfo{
|
info := ServerInfo{
|
||||||
Version: "0.0.16",
|
Version: "0.0.17",
|
||||||
RegistrationEnabled: cachedRegistrationEnabled,
|
RegistrationEnabled: cachedRegistrationEnabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ import (
|
|||||||
var endTicker chan bool
|
var endTicker chan bool
|
||||||
|
|
||||||
func StartBackgroundWorkers() {
|
func StartBackgroundWorkers() {
|
||||||
|
updateSpotifyData()
|
||||||
|
|
||||||
endTicker := make(chan bool)
|
endTicker := make(chan bool)
|
||||||
|
|
||||||
hourTicker := time.NewTicker(time.Hour)
|
hourTicker := time.NewTicker(time.Hour)
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Track struct {
|
type Track struct {
|
||||||
@ -29,7 +30,8 @@ func insertTrack(name string, legnth int, mbid string, spotifyId string, album s
|
|||||||
|
|
||||||
// If it didn't match above, lookup by name
|
// If it didn't match above, lookup by name
|
||||||
if track.Uuid == "" {
|
if track.Uuid == "" {
|
||||||
track = fetchTrack("name", name, tx)
|
// TODO: add artist check here too
|
||||||
|
track = fetchTrackWithArtists(name, artists, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we can't find it. Lets add it!
|
// If we can't find it. Lets add it!
|
||||||
@ -47,7 +49,7 @@ func insertTrack(name string, legnth int, mbid string, spotifyId string, album s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if track.Uuid == "" {
|
if track.Uuid == "" {
|
||||||
track = fetchTrack("name", name, tx)
|
track = fetchTrackWithArtists(name, artists, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = track.linkTrack(album, artists, tx)
|
err = track.linkTrack(album, artists, tx)
|
||||||
@ -78,6 +80,25 @@ func fetchTrack(col string, val string, tx *sql.Tx) Track {
|
|||||||
return track
|
return track
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchTrackWithArtists(name string, artists []string, tx *sql.Tx) Track {
|
||||||
|
var track Track
|
||||||
|
artistString := strings.Join(artists, "','")
|
||||||
|
|
||||||
|
err := tx.QueryRow(
|
||||||
|
"SELECT BIN_TO_UUID(`uuid`, true), `name`, `desc`, `img`, `mbid` FROM `tracks` "+
|
||||||
|
"LEFT JOIN `track_artist` ON `tracks`.`uuid` = `track_artist`.`track` "+
|
||||||
|
"WHERE `name` = ? AND BIN_TO_UUID(`track_artist`.`artist`, true) IN ('`"+artistString+"`')",
|
||||||
|
name).Scan(&track.Uuid, &track.Name, &track.Desc, &track.Img, &track.MusicBrainzID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if err != sql.ErrNoRows {
|
||||||
|
log.Printf("Error fetching tracks: %+v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return track
|
||||||
|
}
|
||||||
|
|
||||||
func insertNewTrack(name string, length int, mbid string, spotifyId string, tx *sql.Tx) error {
|
func insertNewTrack(name string, length int, mbid string, spotifyId string, tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("INSERT INTO `tracks` (`uuid`, `name`, `length`, `mbid`, `spotify_id`) "+
|
_, err := tx.Exec("INSERT INTO `tracks` (`uuid`, `name`, `length`, `mbid`, `spotify_id`) "+
|
||||||
"VALUES (UUID_TO_BIN(UUID(), true),?,?,?,?)", name, length, mbid, spotifyId)
|
"VALUES (UUID_TO_BIN(UUID(), true),?,?,?,?)", name, length, mbid, spotifyId)
|
||||||
|
@ -252,12 +252,3 @@ export const getServerInfo = () => {
|
|||||||
return handleErrorResp(error)
|
return handleErrorResp(error)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const resetScrobbleToken = () => {
|
|
||||||
return axios.patch(process.env.REACT_APP_API_URL + "user", { token: "" }, { headers: getHeaders() })
|
|
||||||
.then((data) => {
|
|
||||||
return data.data
|
|
||||||
}).catch((error) => {
|
|
||||||
return handleErrorResp(error)
|
|
||||||
});
|
|
||||||
}
|
|
@ -56,7 +56,7 @@ const User = () => {
|
|||||||
|
|
||||||
const resetToken = () => {
|
const resetToken = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
resetScrobbleToken(user.uuid)
|
patchUser({ token: '' })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
getUser()
|
getUser()
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
Loading…
Reference in New Issue
Block a user