initial commit
This commit is contained in:
32
handler_get_thumbnail.go
Normal file
32
handler_get_thumbnail.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (cfg *apiConfig) handlerThumbnailGet(w http.ResponseWriter, r *http.Request) {
|
||||
videoIDString := r.PathValue("videoID")
|
||||
videoID, err := uuid.Parse(videoIDString)
|
||||
if err != nil {
|
||||
respondWithError(w, http.StatusBadRequest, "Invalid video ID", err)
|
||||
return
|
||||
}
|
||||
|
||||
tn, ok := videoThumbnails[videoID]
|
||||
if !ok {
|
||||
respondWithError(w, http.StatusNotFound, "Thumbnail not found", nil)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", tn.mediaType)
|
||||
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(tn.data)))
|
||||
|
||||
_, err = w.Write(tn.data)
|
||||
if err != nil {
|
||||
respondWithError(w, http.StatusInternalServerError, "Error writing response", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user