Add collection api.

This commit is contained in:
2025-07-30 16:28:33 +08:00
parent f8c4509633
commit 17b40f2214
10 changed files with 740 additions and 37 deletions

View File

@@ -6,6 +6,8 @@ import (
"net/http"
"nysoure/server/config"
"nysoure/server/dao"
"regexp"
"strconv"
)
func checkUserCanUpload(uid uint) (bool, error) {
@@ -58,3 +60,36 @@ func verifyCfToken(cfToken string) (bool, error) {
return false, nil
}
}
func findImagesInContent(content string, host string) []uint {
// Handle both absolute and relative URLs
absolutePattern := `!\[.*?\]\((?:https?://` + host + `)?/api/image/(\d+)(?:\s+["'].*?["'])?\)`
relativePattern := `!\[.*?\]\(/api/image/(\d+)(?:\s+["'].*?["'])?\)`
// Combine patterns and compile regex
patterns := []string{absolutePattern, relativePattern}
// Store unique image IDs to avoid duplicates
imageIDs := make(map[uint]struct{})
for _, pattern := range patterns {
re := regexp.MustCompile(pattern)
matches := re.FindAllStringSubmatch(content, -1)
for _, match := range matches {
if len(match) >= 2 {
if id, err := strconv.ParseUint(match[1], 10, 32); err == nil {
imageIDs[uint(id)] = struct{}{}
}
}
}
}
// Convert map keys to slice
result := make([]uint, 0, len(imageIDs))
for id := range imageIDs {
result = append(result, id)
}
return result
}