29 lines
683 B
Go
29 lines
683 B
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"music-server/pkg/helpers"
|
|
"music-server/pkg/server"
|
|
"net/http"
|
|
)
|
|
|
|
func SyncHandler(w http.ResponseWriter, r *http.Request) {
|
|
helpers.SetCorsAndNoCacheHeaders(&w, r)
|
|
if r.URL.Path == "/sync" {
|
|
w.Header().Add("Content-Type", "application/json")
|
|
server.SyncGames()
|
|
_, err := fmt.Fprint(w, "Games are synced")
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
}
|
|
|
|
} else if r.URL.Path == "/sync/reset" {
|
|
w.Header().Add("Content-Type", "application/json")
|
|
server.ResetDB()
|
|
_, err := fmt.Fprint(w, "Games and songs are deleted from the database")
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
}
|
|
}
|
|
}
|