From 6254aa585c5b16f7a7dadc02d3bea3b62b37134b Mon Sep 17 00:00:00 2001 From: Pasha Date: Thu, 21 Nov 2024 12:45:31 +0300 Subject: [PATCH] update script --- script/main.go | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/script/main.go b/script/main.go index 569f866..bb65643 100644 --- a/script/main.go +++ b/script/main.go @@ -19,6 +19,7 @@ const ( mongoURI = "mongodb://test:test@localhost:27024/?authSource=admin" mongoDBName = "admin" collectionName = "verification" + folder = "folder" ) func main() { @@ -107,13 +108,36 @@ func getVerificationRecords(ctx context.Context, collection *mongo.Collection) ( // проверка на существования файла минио в монге по урлу func checkContains(verifications []models.Verification, fileKey string) bool { - fileURL := fmt.Sprintf("%s/%s/%s", minioEndpoint, bucketName, fileKey) - for _, verification := range verifications { - for _, file := range verification.Files { - if file.Url == fileURL { - return true + firstTry := func(verifications []models.Verification, fileKey string) bool { + fileURL := fmt.Sprintf("%s/%s/%s", minioEndpoint, bucketName, fileKey) + for _, verification := range verifications { + for _, file := range verification.Files { + if file.Url == fileURL { + return true + } } } + return false + } + + secondTry := func(verifications []models.Verification, fileKey string) bool { + for _, verification := range verifications { + for _, file := range verification.Files { + fileURL := fmt.Sprintf("%s/%s/%s/%s/%s", minioEndpoint, bucketName, folder, verification.UserID, fileKey) + if file.Url == fileURL { + return true + } + } + } + return false + } + + if firstTry(verifications, fileKey) { + return true + } + + if secondTry(verifications, fileKey) { + return true } return false }