Migrate ingest and API paths to string IDs

This commit is contained in:
2026-02-14 20:10:23 +03:00
parent 6df92b7a69
commit 3ffdf9b0e1
42 changed files with 1958 additions and 437 deletions

View File

@@ -4,43 +4,46 @@ import (
"encoding/json"
"io"
"net/http"
"regexp"
"strconv"
"strings"
"time"
)
func parseID(path, prefix string) (int64, bool) {
var entityIDPattern = regexp.MustCompile(`^[A-Z]{2,3}-[0-9]{7}$`)
func parseID(path, prefix string) (string, bool) {
if !strings.HasPrefix(path, prefix) {
return 0, false
return "", false
}
trimmed := strings.TrimPrefix(path, prefix)
if trimmed == "" || strings.Contains(trimmed, "/") {
return 0, false
return "", false
}
id, err := strconv.ParseInt(trimmed, 10, 64)
if err != nil || id <= 0 {
return 0, false
if !entityIDPattern.MatchString(trimmed) {
return "", false
}
return id, true
return trimmed, true
}
func parseSubresourceID(path, prefix, suffix string) (int64, bool) {
func parseSubresourceID(path, prefix, suffix string) (string, bool) {
if !strings.HasPrefix(path, prefix) || !strings.HasSuffix(path, suffix) {
return 0, false
return "", false
}
trimmed := strings.TrimPrefix(path, prefix)
trimmed = strings.TrimSuffix(trimmed, suffix)
if trimmed == "" || strings.Contains(trimmed, "/") {
return 0, false
return "", false
}
id, err := strconv.ParseInt(trimmed, 10, 64)
if err != nil || id <= 0 {
return 0, false
if !entityIDPattern.MatchString(trimmed) {
return "", false
}
return id, true
return trimmed, true
}
func decodeJSON(r *http.Request, dest any) error {