From a68925459af13c8f6db236effb684311f4b79ecc Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Tue, 1 Jul 2025 23:51:15 +0700 Subject: [PATCH] fix: do not cache m3u8 files Signed-off-by: Alexander Onnikov --- internal/pkg/storage/datalake.go | 5 ++++- internal/pkg/storage/s3.go | 2 +- internal/pkg/storage/storage.go | 7 ++++++- internal/pkg/uploader/uploader.go | 5 ++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/pkg/storage/datalake.go b/internal/pkg/storage/datalake.go index b9560e0710..e76e0b1a87 100644 --- a/internal/pkg/storage/datalake.go +++ b/internal/pkg/storage/datalake.go @@ -84,7 +84,7 @@ func getObjectKeyFromPath(s string) string { } // PutFile uploads file to the datalake -func (d *DatalakeStorage) PutFile(ctx context.Context, fileName string) error { +func (d *DatalakeStorage) PutFile(ctx context.Context, fileName string, options PutOptions) error { // #nosec file, err := os.Open(fileName) if err != nil { @@ -127,6 +127,9 @@ func (d *DatalakeStorage) PutFile(ctx context.Context, fileName string) error { req.Header.SetMethod(fasthttp.MethodPost) req.Header.Add("Authorization", "Bearer "+d.token) req.Header.SetContentType(writer.FormDataContentType()) + if options.NoCache { + req.Header.Add("Cache-Control", "max-age=0, must-revalidate") + } req.SetBody(body.Bytes()) if err := d.client.Do(req, res); err != nil { diff --git a/internal/pkg/storage/s3.go b/internal/pkg/storage/s3.go index e4f3050d09..aea0adec5b 100644 --- a/internal/pkg/storage/s3.go +++ b/internal/pkg/storage/s3.go @@ -84,7 +84,7 @@ func (u *S3Storage) DeleteFile(ctx context.Context, fileName string) error { } // PutFile uploads file to the s3 storage -func (u *S3Storage) PutFile(ctx context.Context, fileName string) error { +func (u *S3Storage) PutFile(ctx context.Context, fileName string, options PutOptions) error { var _, objectKey = filepath.Split(fileName) var logger = u.logger.With(zap.String("upload", u.bucketName), zap.String("fileName", fileName)) diff --git a/internal/pkg/storage/storage.go b/internal/pkg/storage/storage.go index 78d28cdf13..cd9c9b8aac 100644 --- a/internal/pkg/storage/storage.go +++ b/internal/pkg/storage/storage.go @@ -37,9 +37,14 @@ type BlobInfo struct { ETag string } +// PutOptions represents options for the PutFile operation +type PutOptions struct { + NoCache bool +} + // Storage represents file-based storage type Storage interface { - PutFile(ctx context.Context, fileName string) error + PutFile(ctx context.Context, fileName string, options PutOptions) error DeleteFile(ctx context.Context, fileName string) error GetFile(ctx context.Context, fileName, destination string) error StatFile(ctx context.Context, fileName string) (*BlobInfo, error) diff --git a/internal/pkg/uploader/uploader.go b/internal/pkg/uploader/uploader.go index baffcaa82e..2bdee38c76 100644 --- a/internal/pkg/uploader/uploader.go +++ b/internal/pkg/uploader/uploader.go @@ -316,7 +316,10 @@ func (u *uploaderImpl) uploadAndDelete(f string) { for attempt := range u.options.RetryCount { logger = logger.With(zap.Int("attempt", attempt)) var putCtx, putCancel = context.WithTimeout(u.uploadCtx, u.options.Timeout) - var err = u.storage.PutFile(putCtx, f) + var putOptions = storage.PutOptions{ + NoCache: u.shouldDeleteOnStop(f), + } + var err = u.storage.PutFile(putCtx, f, putOptions) putCancel() if err != nil {