[feature/backend] overall enhancement of image uploading
All checks were successful
Build Backend / Build Docker Image (push) Successful in 5m3s

This commit is contained in:
CDN 2025-02-23 04:42:48 +08:00
parent 6e1be3d513
commit 3e6181e578
Signed by: CDN
GPG key ID: 0C656827F9F80080
13 changed files with 740 additions and 314 deletions

View file

@ -25,8 +25,9 @@ func NewHandler(cfg *config.Config, service service.Service) *Handler {
}
// RegisterRoutes registers all the routes
func (h *Handler) RegisterRoutes(r *gin.Engine) {
api := r.Group("/api/v1")
func (h *Handler) RegisterRoutes(router *gin.Engine) {
// API routes
api := router.Group("/api/v1")
{
// Auth routes
auth := api.Group("/auth")
@ -93,6 +94,9 @@ func (h *Handler) RegisterRoutes(r *gin.Engine) {
media.DELETE("/:id", h.DeleteMedia)
}
}
// Public media files
router.GET("/media/:year/:month/:filename", h.GetMediaFile)
}
// Category handlers
@ -246,10 +250,10 @@ func (h *Handler) GetPost(c *gin.Context) {
contents := make([]gin.H, 0, len(post.Edges.Contents))
for _, content := range post.Edges.Contents {
contents = append(contents, gin.H{
"language_code": content.LanguageCode,
"title": content.Title,
"language_code": content.LanguageCode,
"title": content.Title,
"content_markdown": content.ContentMarkdown,
"summary": content.Summary,
"summary": content.Summary,
})
}
response["edges"].(gin.H)["contents"] = contents
@ -294,7 +298,7 @@ func (h *Handler) CreatePost(c *gin.Context) {
}
type AddPostContentRequest struct {
LanguageCode string `json:"language_code" binding:"required"`
LanguageCode string `json:"language_code" binding:"required"`
Title string `json:"title" binding:"required"`
ContentMarkdown string `json:"content_markdown" binding:"required"`
Summary string `json:"summary" binding:"required"`
@ -326,10 +330,10 @@ func (h *Handler) AddPostContent(c *gin.Context) {
"title": content.Title,
"content_markdown": content.ContentMarkdown,
"language_code": content.LanguageCode,
"summary": content.Summary,
"summary": content.Summary,
"meta_keywords": content.MetaKeywords,
"meta_description": content.MetaDescription,
"edges": gin.H{},
"edges": gin.H{},
})
}
@ -535,11 +539,3 @@ func (h *Handler) AddDailyContent(c *gin.Context) {
c.JSON(http.StatusCreated, content)
}
// Helper functions
func stringPtr(s *string) string {
if s == nil {
return ""
}
return *s
}