feat: add image management functionality

- Implemented image folder repository with CRUD operations.
- Added image reference repository for managing image references to articles.
- Created image repository for handling image assets, including listing, inserting, updating, and deleting images.
- Introduced image usage repository to track storage usage and quotas for tenants.
- Added SQL queries for image assets, folders, references, and usage.
- Developed image handler for HTTP endpoints to manage images and folders.
- Created database migration scripts for image-related tables and structures.
This commit is contained in:
2026-04-16 20:40:41 +08:00
parent 0a3558fc51
commit 27389164b0
57 changed files with 8063 additions and 153 deletions
@@ -2,6 +2,7 @@ package app
import (
"encoding/json"
"strconv"
"strings"
)
@@ -86,6 +87,14 @@ func resolveArticleCoverAssetURL(wizardStateJSON []byte) *string {
return &value
}
func resolveArticleCoverImageAssetID(wizardStateJSON []byte) *int64 {
value, ok := extractInt64FromJSONPayload(wizardStateJSON, "cover_image_asset_id")
if !ok || value <= 0 {
return nil
}
return &value
}
func extractStringFromJSONPayload(raw []byte, key string) string {
if len(raw) == 0 {
return ""
@@ -103,6 +112,40 @@ func extractStringFromJSONPayload(raw []byte, key string) string {
return strings.TrimSpace(value)
}
func extractInt64FromJSONPayload(raw []byte, key string) (int64, bool) {
if len(raw) == 0 {
return 0, false
}
var payload map[string]interface{}
if err := json.Unmarshal(raw, &payload); err != nil {
return 0, false
}
switch value := payload[key].(type) {
case nil:
return 0, false
case float64:
return int64(value), true
case int64:
return value, true
case int:
return int64(value), true
case string:
value = strings.TrimSpace(value)
if value == "" {
return 0, false
}
parsed, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return 0, false
}
return parsed, true
default:
return 0, false
}
}
func normalizePlatformsFromValue(raw interface{}) []string {
switch typed := raw.(type) {
case nil:
@@ -126,7 +169,7 @@ func normalizePlatformsFromValue(raw interface{}) []string {
}
}
func mergeArticleWizardState(raw []byte, title string, platforms []string, coverAssetURL *string) ([]byte, error) {
func mergeArticleWizardState(raw []byte, title string, platforms []string, coverAssetURL *string, coverImageAssetID NullableInt64Input) ([]byte, error) {
state := make(map[string]interface{})
if len(raw) > 0 {
_ = json.Unmarshal(raw, &state)
@@ -157,5 +200,13 @@ func mergeArticleWizardState(raw []byte, title string, platforms []string, cover
}
}
if coverImageAssetID.Set {
if coverImageAssetID.Value == nil {
delete(state, "cover_image_asset_id")
} else {
state["cover_image_asset_id"] = *coverImageAssetID.Value
}
}
return json.Marshal(state)
}