url signing

This commit is contained in:
2025-03-16 11:24:00 +02:00
parent 34d50fde30
commit 07d574acd9
3 changed files with 64 additions and 4 deletions

View File

@@ -95,7 +95,12 @@ func (cfg *apiConfig) handlerVideoGet(w http.ResponseWriter, r *http.Request) {
return
}
respondWithJSON(w, http.StatusOK, video)
vid, err := cfg.dbVideoToSignedVideo(video)
if err != nil {
respondWithError(w, http.StatusInternalServerError, "Couldn't convert video to signed video", err)
return
}
respondWithJSON(w, http.StatusOK, vid)
}
func (cfg *apiConfig) handlerVideosRetrieve(w http.ResponseWriter, r *http.Request) {
@@ -116,5 +121,19 @@ func (cfg *apiConfig) handlerVideosRetrieve(w http.ResponseWriter, r *http.Reque
return
}
respondWithJSON(w, http.StatusOK, videos)
var vids []database.Video
if len(videos) > 0 {
for _, video := range videos {
vid, err := cfg.dbVideoToSignedVideo(video)
if err != nil {
respondWithError(w, http.StatusInternalServerError, "Couldn't convert video to signed video", err)
return
}
vids = append(vids, vid)
}
} else {
vids = make([]database.Video, 0)
}
respondWithJSON(w, http.StatusOK, vids)
}