From 19bca771835f7681cd0273152dc5966979b03bd1 Mon Sep 17 00:00:00 2001 From: Philip Stadermann Date: Wed, 12 Jun 2024 12:28:44 +0200 Subject: [PATCH] On-upload: Tag files immediately #38 On-upload: If scan fails, tag uploaded file as "Unscanned" --- lib/Service/VerdictService.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Service/VerdictService.php b/lib/Service/VerdictService.php index 24df41a5..0e4fa78a 100644 --- a/lib/Service/VerdictService.php +++ b/lib/Service/VerdictService.php @@ -103,15 +103,15 @@ public function scanFileById(int $fileId): VaasVerdict { . $verdict->Verdict->value . ", Detection: " . $verdict->Detection . ", SHA256: " . $verdict->Sha256 . ", FileType: " . $verdict->FileType . ", MimeType: " . $verdict->MimeType . ", UUID: " . $verdict->Guid); - $this->tagFile($fileId, $verdict); + $this->tagFile($fileId, $verdict->Verdict->value); return $verdict; } - private function tagFile(int $fileId, VaasVerdict $vaasVerdict) { + private function tagFile(int $fileId, string $tagName) { $this->tagService->removeAllTagsFromFile($fileId); - switch ($vaasVerdict->Verdict->value) { + switch ($tagName) { case TagService::CLEAN: $this->tagService->setTag($fileId, TagService::CLEAN); break; @@ -133,7 +133,7 @@ private function tagFile(int $fileId, VaasVerdict $vaasVerdict) { } public function scan(string $filePath): VaasVerdict { - $this->lastLocalPath = ""; + $this->lastLocalPath = $filePath; $this->lastVaasVerdict = null; if ($this->vaas == null) { @@ -143,7 +143,6 @@ public function scan(string $filePath): VaasVerdict { try { $verdict = $this->vaas->ForFile($filePath); - $this->lastLocalPath = $filePath; $this->lastVaasVerdict = $verdict; return $verdict; @@ -162,8 +161,12 @@ public function onRename(string $localSource, string $localTarget) } public function tagLastScannedFile(string $localPath, int $fileId) { - if ($localPath === $this->lastLocalPath && $this->lastVaasVerdict !== null) { - $this->tagFile($fileId, $this->lastVaasVerdict); + if ($localPath === $this->lastLocalPath) { + if ($this->lastVaasVerdict !== null) { + $this->tagFile($fileId, $this->lastVaasVerdict->Verdict->value); + } else { + $this->tagFile($fileId, TagService::UNSCANNED); + } } }