Compute stable URL in types.NewFile, wire baseURL into console v1 Resolver

Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
Ludovic Vielle
2026-06-10 09:25:20 +02:00
parent 6693ee4bf4
commit 3f484ac330
7 changed files with 27 additions and 11 deletions

View File

@@ -90,7 +90,7 @@ func (r *auditResolver) ReportFile(ctx context.Context, obj *types.Audit) (*type
return nil, gqlutils.Internal(ctx) return nil, gqlutils.Internal(ctx)
} }
return types.NewFile(file), nil return types.NewFile(file, r.baseURL), nil
} }
// Controls is the resolver for the controls field. // Controls is the resolver for the controls field.

View File

@@ -43,7 +43,7 @@ func (r *evidenceResolver) File(ctx context.Context, obj *types.Evidence) (*type
return nil, gqlutils.Internal(ctx) return nil, gqlutils.Internal(ctx)
} }
return types.NewFile(file), nil return types.NewFile(file, r.baseURL), nil
} }
// Task is the resolver for the task field. // Task is the resolver for the task field.

View File

@@ -20,6 +20,7 @@ import (
"go.gearno.de/kit/log" "go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/accessreview" "go.probo.inc/probo/pkg/accessreview"
"go.probo.inc/probo/pkg/agentrun" "go.probo.inc/probo/pkg/agentrun"
"go.probo.inc/probo/pkg/baseurl"
"go.probo.inc/probo/pkg/connector" "go.probo.inc/probo/pkg/connector"
"go.probo.inc/probo/pkg/connector/provider" "go.probo.inc/probo/pkg/connector/provider"
"go.probo.inc/probo/pkg/cookiebanner" "go.probo.inc/probo/pkg/cookiebanner"
@@ -49,6 +50,7 @@ func NewGraphQLHandler(
logger *log.Logger, logger *log.Logger,
thirdPartySvc *thirdparty.Service, thirdPartySvc *thirdparty.Service,
riskManagementSvc *riskmanagement.Service, riskManagementSvc *riskmanagement.Service,
baseURL *baseurl.BaseURL,
) http.Handler { ) http.Handler {
config := schema.Config{ config := schema.Config{
Resolvers: &Resolver{ Resolvers: &Resolver{
@@ -66,6 +68,7 @@ func NewGraphQLHandler(
riskManagement: riskManagementSvc, riskManagement: riskManagementSvc,
thirdParty: thirdPartySvc, thirdParty: thirdPartySvc,
customDomainCname: customDomainCname, customDomainCname: customDomainCname,
baseURL: baseURL,
logger: logger, logger: logger,
}, },
} }

View File

@@ -64,6 +64,7 @@ type (
riskManagement *riskmanagement.Service riskManagement *riskmanagement.Service
thirdParty *thirdparty.Service thirdParty *thirdparty.Service
logger *log.Logger logger *log.Logger
baseURL *baseurl.BaseURL
customDomainCname string customDomainCname string
} }
) )
@@ -104,6 +105,7 @@ func NewMux(
logger, logger,
thirdPartySvc, thirdPartySvc,
riskManagementSvc, riskManagementSvc,
baseURL,
) )
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {

View File

@@ -1064,7 +1064,7 @@ func (r *thirdPartyComplianceReportResolver) File(ctx context.Context, obj *type
return nil, gqlutils.Internal(ctx) return nil, gqlutils.Internal(ctx)
} }
return types.NewFile(file), nil return types.NewFile(file, r.baseURL), nil
} }
// Permission is the resolver for the permission field. // Permission is the resolver for the permission field.

View File

@@ -1079,7 +1079,7 @@ func (r *trustCenterDocumentAccessResolver) ReportFile(ctx context.Context, obj
return nil, gqlutils.Internal(ctx) return nil, gqlutils.Internal(ctx)
} }
return types.NewFile(file), nil return types.NewFile(file, r.baseURL), nil
} }
// Audit is the resolver for the audit field. // Audit is the resolver for the audit field.

View File

@@ -15,16 +15,27 @@
package types package types
import ( import (
"go.probo.inc/probo/pkg/baseurl"
"go.probo.inc/probo/pkg/coredata" "go.probo.inc/probo/pkg/coredata"
) )
func NewFile(r *coredata.File) *File { func NewFile(r *coredata.File, base *baseurl.BaseURL) *File {
var path string
if r.Visibility == coredata.FileVisibilityPublic {
path = "/api/files/v1/public/" + r.ID.String()
} else {
path = "/api/files/v1/" + r.ID.String()
}
url := base.WithPath(path).MustString()
return &File{ return &File{
ID: r.ID, ID: r.ID,
MimeType: r.MimeType, MimeType: r.MimeType,
FileName: r.FileName, FileName: r.FileName,
Size: r.FileSize, Size: r.FileSize,
CreatedAt: r.CreatedAt, DownloadURL: url,
UpdatedAt: r.UpdatedAt, CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
} }
} }