avoid collisions and delete the thumnbnail after successful response

This commit is contained in:
2025-03-25 11:02:15 +01:00
parent 03ac9d3656
commit 269d7cfbf5
8 changed files with 46 additions and 61 deletions

View File

@@ -8,6 +8,7 @@ import (
"path"
"path/filepath"
"strings"
"sync"
"time"
pb "thumbnailclient/proto"
@@ -32,13 +33,20 @@ func main() {
{pb.FileType_PDF, "testdata/pdf-sample.pdf"},
{pb.FileType_VIDEO, "testdata/video-sample.webm"}}
a := sync.WaitGroup{}
for _, f := range filePath {
newFunction(f.Path, f.Type, client)
a.Add(1)
go func() {
createPreview(f.Path, f.Type, client)
a.Done()
}()
}
a.Wait()
}
func newFunction(filePath string, ftype pb.FileType, client pb.ThumbnailServiceClient) {
func createPreview(filePath string, ftype pb.FileType, client pb.ThumbnailServiceClient) {
fileContent, err := os.ReadFile(filePath)
if err != nil {
log.Fatalf("Error reading file: %v", err)