initial commit

This commit is contained in:
Daniel Hjartland
2024-11-26 18:08:49 +01:00
commit 75be79c6cf
26 changed files with 1885 additions and 0 deletions

32
handler_get_thumbnail.go Normal file
View 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
}
}