public function post(Request $request)
 {
     if ($request->has('delete')) {
         $fileId = $request->get('delete');
         $file = FileRecord::findOrFail($fileId);
         $file->delete();
         return redirect()->back()->with('success', new MessageBag(['File deleted']));
     }
 }
Exemple #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $files = FileRecord::withTrashed()->where('hash', '=', '')->get();
     /** @var FileRecord $file */
     foreach ($files as $index => $file) {
         if ($file->fileExists()) {
             $fileHash = hash_file('sha256', $file->filePath());
             $file->hash = $fileHash;
             $file->save();
         } else {
             $this->output->error('File doesn\'t exist: ' . $file->filePath());
         }
         $this->output->write(sprintf("\r%d/%d", $index + 1, $files->count()));
     }
     $this->output->success('Done');
 }
Exemple #3
0
 protected function actionScanResult(FileRecord $file, Scan $scan)
 {
     $detectionRatio = $scan->positives / $scan->total;
     if ($detectionRatio >= config('virustotal.detection_threshold')) {
         $this->info(sprintf('Deleting file: %s (#%d)', $file->client_name, $file->id));
         return $file->delete();
     } else {
         return false;
     }
 }
 protected function fileRecordDeletingListener()
 {
     FileRecord::deleting(function ($fileRecord) {
         $fileRecord->deleteFile();
     });
 }
Exemple #5
0
 /**
  * Generate a unique name for file
  *
  * @param $extension
  * @return string
  */
 protected function generateName($extension)
 {
     for ($i = 0; $i < 10; $i++) {
         // 6 chars long
         $randMin = base_convert('100000', 36, 10);
         $randMax = base_convert('zzzzzz', 36, 10);
         // Generate
         $generatedName = base_convert(mt_rand($randMin, $randMax), 10, 36);
         // Add extension if we have it
         if (!empty($extension)) {
             $generatedName .= '.' . $extension;
         }
         // Check name is unique
         $count = FileRecord::withTrashed()->where('generated_name', '=', $generatedName)->count();
         if ($count === 0) {
             // Unique, return the name
             return $generatedName;
         } else {
             // Try again
             continue;
         }
     }
     // 10 tries and still no unique name, throw exception
     throw new NoUniqueGeneratedNameException();
 }