fix(media): 资源访问 - 签名地址有效期跟随后台策略并放开服务器访问地址限制

平台展示与厂商读取的签名地址有效期改为读取「资源与请求策略」,默认均为 4 小时,不再硬编码 5 分钟。服务器访问地址只校验 http/https 格式,允许本机、局域网或 HTTP 地址,模型读取平台资源不再强制 HTTPS 公网地址。
This commit is contained in:
ddcat666 committed 2026-09-30 03:38:31 +08:00
1 parent 4957f8bc22
commit 4272b0e499
9 files changed
+40 -14

No files matched your search

+4 -2
View File
@@ -102,9 +102,11 @@ func ResolveAccess(resource *model.Resource, setting storage.Settings, options A
if resource.Status != model.ResourceStatusReady {
return nil, AccessError(http.StatusConflict, "resource_not_ready", "资源尚未上传完成")
}
ttl := 5 * time.Minute
// 有效期来自后台「资源与请求策略」;未注入运行时策略时回落到存储层默认值(均为 4 小时)。
runtime := storage.NormalizeSettings(storage.Settings{Runtime: setting.Runtime}).Runtime
ttl := runtime.AccessURLTTL
if options.Purpose == PurposeProvider {
ttl = 4 * time.Hour
ttl = runtime.ProviderAccessURLTTL
}
expires := now.Add(ttl)
if !options.ExpiresAt.IsZero() && options.ExpiresAt.Before(expires) {
+16
View File
@@ -185,3 +185,19 @@ func errorReason(err error) string {
}
return err.Error()
}
func TestResolveAccessUsesRuntimePolicyTTL(t *testing.T) {
now := time.Date(2026, time.January, 2, 3, 4, 5, 0, time.UTC)
resource := testReadyResource("local")
setting := storage.Settings{Runtime: storage.RuntimePolicy{AccessURLTTL: 2 * time.Hour, ProviderAccessURLTTL: 6 * time.Hour}}
var variants []ResourceVariant
for purpose, want := range map[AccessPurpose]time.Duration{PurposeDisplay: 2 * time.Hour, PurposeProvider: 6 * time.Hour} {
access, err := ResolveAccess(resource, setting, AccessOptions{Purpose: purpose}, now, testPlatformURL(&variants))
if err != nil {
t.Fatal(err)
}
if access.ExpiresAt == nil || !access.ExpiresAt.Equal(now.Add(want)) {
t.Fatalf("%s access expiry = %v, want %v", purpose, access.ExpiresAt, now.Add(want))
}
}
}