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 types.NewFile(file), nil
return types.NewFile(file, r.baseURL), nil
}
// 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 types.NewFile(file), nil
return types.NewFile(file, r.baseURL), nil
}
// Task is the resolver for the task field.

View File

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

View File

@@ -64,6 +64,7 @@ type (
riskManagement *riskmanagement.Service
thirdParty *thirdparty.Service
logger *log.Logger
baseURL *baseurl.BaseURL
customDomainCname string
}
)
@@ -104,6 +105,7 @@ func NewMux(
logger,
thirdPartySvc,
riskManagementSvc,
baseURL,
)
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 types.NewFile(file), nil
return types.NewFile(file, r.baseURL), nil
}
// 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 types.NewFile(file), nil
return types.NewFile(file, r.baseURL), nil
}
// Audit is the resolver for the audit field.

View File

@@ -15,16 +15,27 @@
package types
import (
"go.probo.inc/probo/pkg/baseurl"
"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{
ID: r.ID,
MimeType: r.MimeType,
FileName: r.FileName,
Size: r.FileSize,
CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
ID: r.ID,
MimeType: r.MimeType,
FileName: r.FileName,
Size: r.FileSize,
DownloadURL: url,
CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
}
}