is_file && in_array($this->mime_type, self::ARCHIVE_MIMES); } public function isImage(): bool { return preg_match('/^image\/(?!svg\+xml)/', $this->mime_type); } public function getIcon(): string { if ($this->is_directory) { return 'tabler-folder'; } if ($this->isArchive()) { return 'tabler-file-zip'; } if ($this->isImage()) { return 'tabler-photo'; } return $this->is_symlink ? 'tabler-file-symlink' : 'tabler-file'; } public function canEdit(): bool { if ($this->is_directory || $this->isArchive() || $this->is_symlink || $this->isImage()) { return false; } return $this->is_file && !in_array($this->mime_type, ['application/jar', 'application/octet-stream', 'inode/directory']); } public function server(): Server { return self::$server; } protected function casts(): array { return [ 'created_at' => 'datetime', 'modified_at' => 'datetime', ]; } public function getSchema(): array { return [ 'name' => 'string', 'created_at' => 'string', 'modified_at' => 'string', 'mode' => 'string', 'mode_bits' => 'integer', 'size' => 'integer', 'is_directory' => 'boolean', 'is_file' => 'boolean', 'is_symlink' => 'boolean', 'mime_type' => 'string', ]; } public function getRows(): array { try { $fileRepository = (new DaemonFileRepository())->setServer(self::$server); if (!is_null(self::$searchTerm)) { $contents = cache()->remember('file_search_' . self::$path . '_' . self::$searchTerm, now()->addMinute(), fn () => $fileRepository->search(self::$searchTerm, self::$path)); } else { $contents = $fileRepository->getDirectory(self::$path ?? '/'); } if (isset($contents['error'])) { throw new Exception($contents['error']); } return array_map(function ($file) { return [ 'name' => $file['name'], 'created_at' => Carbon::parse($file['created'])->timezone('UTC'), 'modified_at' => Carbon::parse($file['modified'])->timezone('UTC'), 'mode' => $file['mode'], 'mode_bits' => (int) $file['mode_bits'], 'size' => (int) $file['size'], 'is_directory' => $file['directory'], 'is_file' => $file['file'], 'is_symlink' => $file['symlink'], 'mime_type' => $file['mime'], ]; }, $contents); } catch (Exception $exception) { report($exception); $message = str($exception->getMessage()); if ($message->startsWith('cURL error 7: ')) { $message = $message->after('cURL error 7: ')->before(' after '); } AlertBanner::make() ->title('Could not load files') ->body($message->toString()) ->danger() ->send(); return []; } } protected function sushiShouldCache(): bool { return false; } }