feat: export additional is type-checking utility functions from lodash

This commit is contained in:
Haitao Pan 2026-02-07 02:24:19 +08:00
parent b5ee9723c8
commit 6117e6f769

View File

@ -0,0 +1,53 @@
package api
import (
"net/http"
"strings"
"time"
"github.com/gin-gonic/gin"
"account/internal/store"
)
// internalSandboxGuest returns the sandbox user's rotating proxy UUID metadata for the
// Console Guest/Demo experience.
//
// Protected by InternalAuthMiddleware via /api/internal.
func (h *handler) internalSandboxGuest(c *gin.Context) {
if h == nil || h.store == nil {
c.JSON(http.StatusServiceUnavailable, gin.H{"error": "store_not_configured"})
return
}
user, err := h.store.GetUserByEmail(c.Request.Context(), sandboxUserEmail)
if err != nil {
if err == store.ErrUserNotFound {
c.JSON(http.StatusNotFound, gin.H{"error": "sandbox_missing"})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": "sandbox_lookup_failed"})
return
}
if err := h.ensureSandboxProxyUUID(c.Request.Context(), user); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "sandbox_uuid_rotation_failed"})
return
}
proxyUUID := strings.TrimSpace(user.ProxyUUID)
expiresAt := ""
if user.ProxyUUIDExpiresAt != nil {
expiresAt = user.ProxyUUIDExpiresAt.UTC().Format(time.RFC3339)
}
if proxyUUID == "" {
proxyUUID = strings.TrimSpace(user.ID)
}
c.JSON(http.StatusOK, gin.H{
"email": sandboxUserEmail,
"proxyUuid": proxyUUID,
"proxyUuidExpiresAt": expiresAt,
})
}