88
99use Exception ;
1010use OCA \GDataVaas \AppInfo \Application ;
11+ use OCA \GDataVaas \Service \FileService ;
1112use OCA \GDataVaas \Service \VerdictService ;
1213use OCP \AppFramework \Controller ;
1314use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
1718use OCP \Files \NotPermittedException ;
1819use OCP \IAppConfig ;
1920use OCP \IRequest ;
21+ use Psr \Log \LoggerInterface ;
2022use VaasSdk \Exceptions \VaasAuthenticationException ;
23+ use VaasSdk \Verdict ;
2124
2225class ScanController extends Controller {
26+ private readonly LoggerInterface $ logger ;
2327 private IAppConfig $ config ;
2428 private VerdictService $ verdictService ;
29+ private FileService $ fileService ;
2530
26- public function __construct ($ appName , IRequest $ request , VerdictService $ verdictService , IAppConfig $ config ) {
31+ public function __construct (
32+ $ appName ,
33+ IRequest $ request ,
34+ VerdictService $ verdictService ,
35+ IAppConfig $ config ,
36+ FileService $ fileService ,
37+ LoggerInterface $ logger
38+ ) {
2739 parent ::__construct ($ appName , $ request );
2840
41+ $ this ->logger = $ logger ;
2942 $ this ->config = $ config ;
3043 $ this ->verdictService = $ verdictService ;
44+ $ this ->fileService = $ fileService ;
3145 }
3246
3347 /**
@@ -39,6 +53,14 @@ public function __construct($appName, IRequest $request, VerdictService $verdict
3953 public function scan (int $ fileId ): JSONResponse {
4054 try {
4155 $ verdict = $ this ->verdictService ->scanFileById ($ fileId );
56+ if ($ verdict ->verdict === Verdict::MALICIOUS ) {
57+ try {
58+ $ this ->fileService ->setMaliciousPrefixIfActivated ($ fileId );
59+ $ this ->fileService ->moveFileToQuarantineFolderIfDefined ($ fileId );
60+ } catch (Exception $ e ) {
61+ $ this ->logger ->error ("Failed to handle malicious file ' {$ fileId }': {$ e ->getMessage ()}" );
62+ }
63+ }
4264 return new JSONResponse (['verdict ' => $ verdict ->verdict ->value ], 200 );
4365 } catch (EntityTooLargeException ) {
4466 return new JSONResponse (
0 commit comments