1
All checks were successful
Deploy API / deploy (push) Successful in 35s

This commit is contained in:
2026-05-26 09:01:25 +08:00
parent 12b4ee536e
commit f8792f8db8
2 changed files with 17 additions and 3 deletions

View File

@@ -66,6 +66,7 @@ type adminPost struct {
ID string `json:"id"` ID string `json:"id"`
PostType string `json:"postType"` PostType string `json:"postType"`
CategoryID int `json:"categoryId,omitempty"` CategoryID int `json:"categoryId,omitempty"`
CategorySlug string `json:"categorySlug,omitempty"`
Language string `json:"language"` Language string `json:"language"`
Text string `json:"text"` Text string `json:"text"`
Attachments []attachmentInput `json:"attachments"` Attachments []attachmentInput `json:"attachments"`
@@ -223,6 +224,9 @@ func validateAdminPost(ap *adminPost) error {
if ap.Status == "published" && !hasText && !hasAtt { if ap.Status == "published" && !hasText && !hasAtt {
return fmt.Errorf("published post requires text and/or at least one attachment") return fmt.Errorf("published post requires text and/or at least one attachment")
} }
if ap.Status == "published" && ap.CategoryID <= 0 {
return fmt.Errorf("published post requires categoryId")
}
for i, a := range ap.Attachments { for i, a := range ap.Attachments {
if strings.TrimSpace(a.URL) == "" { if strings.TrimSpace(a.URL) == "" {
return fmt.Errorf("attachment %d: url required", i) return fmt.Errorf("attachment %d: url required", i)
@@ -365,6 +369,13 @@ func classifyAttachmentKind(mime, filename string) string {
return "document" return "document"
} }
func postCategoryIDArg(id int) any {
if id <= 0 {
return nil
}
return id
}
func nullIfEmptyStr(s, def string) string { func nullIfEmptyStr(s, def string) string {
if strings.TrimSpace(s) == "" { if strings.TrimSpace(s) == "" {
return def return def

View File

@@ -94,7 +94,7 @@ func UploadFile(d UploadDeps) http.HandlerFunc {
return return
} }
pub := publicObjectURL(d.S3PublicBase, d.S3Bucket, d.AWSRegion, key) pub := publicObjectURL(d.S3PublicBase, d.S3Bucket, d.AWSRegion, key)
writeUploadJSON(w, pub, hdr.Filename, name, ct, int64(len(data)), data, "s3") writeUploadJSON(w, r, pub, hdr.Filename, name, ct, int64(len(data)), data, "s3")
return return
} }
@@ -113,15 +113,18 @@ func UploadFile(d UploadDeps) http.HandlerFunc {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
writeUploadJSON(w, "/uploads/"+name, hdr.Filename, name, ct, int64(len(data)), data, "local") writeUploadJSON(w, r, "/uploads/"+name, hdr.Filename, name, ct, int64(len(data)), data, "local")
} }
} }
func writeUploadJSON(w http.ResponseWriter, url, originalName, storedName, mime string, size int64, data []byte, storage string) { func writeUploadJSON(w http.ResponseWriter, r *http.Request, url, originalName, storedName, mime string, size int64, data []byte, storage string) {
kind := classifyAttachmentKind(mime, originalName) kind := classifyAttachmentKind(mime, originalName)
if kind == "" { if kind == "" {
kind = classifyAttachmentKind(mime, storedName) kind = classifyAttachmentKind(mime, storedName)
} }
if k := strings.TrimSpace(r.FormValue("kind")); k == "image" || k == "document" || k == "video" {
kind = k
}
out := map[string]any{ out := map[string]any{
"url": url, "url": url,
"filename": storedName, "filename": storedName,