Add new console compliance page brand tab
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -17,11 +17,8 @@ package trust
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"go.gearno.de/kit/pg"
|
||||
"go.probo.inc/probo/pkg/coredata"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
@@ -120,25 +117,12 @@ func (s TrustCenterService) GenerateNDAFileURL(
|
||||
return "", err
|
||||
}
|
||||
|
||||
presignClient := s3.NewPresignClient(s.svc.s3)
|
||||
|
||||
encodedFilename := url.QueryEscape(file.FileName)
|
||||
contentDisposition := fmt.Sprintf("attachment; filename=\"%s\"; filename*=UTF-8''%s",
|
||||
encodedFilename, encodedFilename)
|
||||
|
||||
presignedReq, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
|
||||
Bucket: aws.String(s.svc.bucket),
|
||||
Key: aws.String(file.FileKey),
|
||||
ResponseCacheControl: aws.String("max-age=3600, public"),
|
||||
ResponseContentDisposition: aws.String(contentDisposition),
|
||||
}, func(opts *s3.PresignOptions) {
|
||||
opts.Expires = expiresIn
|
||||
})
|
||||
presignedURL, err := s.svc.fileManager.GenerateFileUrl(ctx, file, expiresIn)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot presign GetObject request: %w", err)
|
||||
return "", fmt.Errorf("cannot generate file URL: %w", err)
|
||||
}
|
||||
|
||||
return presignedReq.URL, nil
|
||||
return presignedURL, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterService) GenerateLogoURL(
|
||||
@@ -146,21 +130,45 @@ func (s TrustCenterService) GenerateLogoURL(
|
||||
compliancePageID gid.GID,
|
||||
expiresIn time.Duration,
|
||||
) (*string, error) {
|
||||
compliancePage, _, err := s.Get(ctx, compliancePageID)
|
||||
file := &coredata.File{}
|
||||
compliancePage := &coredata.TrustCenter{}
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := compliancePage.LoadByID(ctx, conn, s.svc.scope, compliancePageID); err != nil {
|
||||
return fmt.Errorf("cannot load compliance page: %w", err)
|
||||
}
|
||||
|
||||
if compliancePage.LogoFileID == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, *compliancePage.LogoFileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get compliance page: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if compliancePage.LogoFileID == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
url, err := s.generateFileURL(ctx, *compliancePage.LogoFileID, expiresIn)
|
||||
if file.FileKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
presignedURL, err := s.svc.fileManager.GenerateFileUrl(ctx, file, expiresIn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot generate file URL: %w", err)
|
||||
}
|
||||
|
||||
return url, nil
|
||||
return &presignedURL, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterService) GenerateDarkLogoURL(
|
||||
@@ -168,51 +176,43 @@ func (s TrustCenterService) GenerateDarkLogoURL(
|
||||
compliancePageID gid.GID,
|
||||
expiresIn time.Duration,
|
||||
) (*string, error) {
|
||||
compliancePage, _, err := s.Get(ctx, compliancePageID)
|
||||
file := &coredata.File{}
|
||||
compliancePage := &coredata.TrustCenter{}
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := compliancePage.LoadByID(ctx, conn, s.svc.scope, compliancePageID); err != nil {
|
||||
return fmt.Errorf("cannot load compliance page: %w", err)
|
||||
}
|
||||
|
||||
if compliancePage.DarkLogoFileID == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, *compliancePage.DarkLogoFileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get compliance page: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if compliancePage.DarkLogoFileID == nil {
|
||||
if compliancePage.LogoFileID == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
url, err := s.generateFileURL(ctx, *compliancePage.DarkLogoFileID, expiresIn)
|
||||
if file.FileKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
presignedURL, err := s.svc.fileManager.GenerateFileUrl(ctx, file, expiresIn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot generate file URL: %w", err)
|
||||
}
|
||||
|
||||
return url, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterService) generateFileURL(ctx context.Context, fileID gid.GID, expiresIn time.Duration) (*string, error) {
|
||||
file := &coredata.File{}
|
||||
if err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return file.LoadByID(ctx, conn, s.svc.scope, fileID)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
presignClient := s3.NewPresignClient(s.svc.s3)
|
||||
|
||||
encodedFilename := url.QueryEscape(file.FileName)
|
||||
contentDisposition := fmt.Sprintf("attachment; filename=\"%s\"; filename*=UTF-8''%s",
|
||||
encodedFilename, encodedFilename)
|
||||
|
||||
presignedReq, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
|
||||
Bucket: aws.String(s.svc.bucket),
|
||||
Key: aws.String(file.FileKey),
|
||||
ResponseCacheControl: aws.String("max-age=3600, public"),
|
||||
ResponseContentDisposition: aws.String(contentDisposition),
|
||||
}, func(opts *s3.PresignOptions) {
|
||||
opts.Expires = expiresIn
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot presign GetObject request: %w", err)
|
||||
}
|
||||
|
||||
return &presignedReq.URL, nil
|
||||
return &presignedURL, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user