Skip to content

Commit

Permalink
On-upload: Tag files immediately #38
Browse files Browse the repository at this point in the history
On-upload: If scan fails, tag uploaded file as "Unscanned"
  • Loading branch information
Philip Stadermann committed Jun 12, 2024
1 parent 14e4bda commit 19bca77
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/Service/VerdictService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -143,7 +143,6 @@ public function scan(string $filePath): VaasVerdict {
try {
$verdict = $this->vaas->ForFile($filePath);

$this->lastLocalPath = $filePath;
$this->lastVaasVerdict = $verdict;

return $verdict;
Expand All @@ -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);
}
}
}

Expand Down

0 comments on commit 19bca77

Please sign in to comment.