mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Add collection api.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user