mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-21 16:11:56 +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
|
||||
|
||||
variables:
|
||||
VERSION: 0.0.16
|
||||
VERSION: 0.0.17
|
||||
|
||||
build-go:
|
||||
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
|
||||
- Add registration_enabled to /api/v1/serverinfo
|
||||
- Add config table caching on save
|
||||
|
@ -86,6 +86,21 @@ func HandleRequests(port string) {
|
||||
// API ENDPOINT HANDLING
|
||||
// handleRegister - Does as it says!
|
||||
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{}
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
err := decoder.Decode(®Req)
|
||||
@ -462,7 +477,7 @@ func fetchServerInfo(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
info := ServerInfo{
|
||||
Version: "0.0.16",
|
||||
Version: "0.0.17",
|
||||
RegistrationEnabled: cachedRegistrationEnabled,
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ import (
|
||||
var endTicker chan bool
|
||||
|
||||
func StartBackgroundWorkers() {
|
||||
updateSpotifyData()
|
||||
|
||||
endTicker := make(chan bool)
|
||||
|
||||
hourTicker := time.NewTicker(time.Hour)
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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 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!
|
||||
@ -47,7 +49,7 @@ func insertTrack(name string, legnth int, mbid string, spotifyId string, album s
|
||||
}
|
||||
|
||||
if track.Uuid == "" {
|
||||
track = fetchTrack("name", name, tx)
|
||||
track = fetchTrackWithArtists(name, artists, tx)
|
||||
}
|
||||
|
||||
err = track.linkTrack(album, artists, tx)
|
||||
@ -78,6 +80,25 @@ func fetchTrack(col string, val string, tx *sql.Tx) 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 {
|
||||
_, err := tx.Exec("INSERT INTO `tracks` (`uuid`, `name`, `length`, `mbid`, `spotify_id`) "+
|
||||
"VALUES (UUID_TO_BIN(UUID(), true),?,?,?,?)", name, length, mbid, spotifyId)
|
||||
|
@ -252,12 +252,3 @@ export const getServerInfo = () => {
|
||||
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 = () => {
|
||||
setLoading(true);
|
||||
resetScrobbleToken(user.uuid)
|
||||
patchUser({ token: '' })
|
||||
.then(() => {
|
||||
getUser()
|
||||
.then(data => {
|
||||
|
Loading…
Reference in New Issue
Block a user