Add resampled image retrieval functionality and update image URLs

This commit is contained in:
2025-06-23 21:19:42 +08:00
parent dcd23054b2
commit be067cc21a
6 changed files with 117 additions and 5 deletions

View File

@@ -71,10 +71,30 @@ func handleDeleteImage(c fiber.Ctx) error {
})
}
func handleGetResampledImage(c fiber.Ctx) error {
idStr := c.Params("id")
if idStr == "" {
return model.NewRequestError("Image ID is required")
}
id, err := strconv.Atoi(idStr)
if err != nil {
return model.NewRequestError("Invalid image ID")
}
image, err := service.GetResampledImage(uint(id))
if err != nil {
return err
}
contentType := http.DetectContentType(image)
c.Set("Content-Type", contentType)
c.Set("Cache-Control", "public, max-age=31536000")
return c.Send(image)
}
func AddImageRoutes(api fiber.Router) {
image := api.Group("/image")
{
image.Put("/", handleUploadImage)
image.Get("/resampled/:id", handleGetResampledImage)
image.Get("/:id", handleGetImage)
image.Delete("/:id", handleDeleteImage)
}