summaryrefslogtreecommitdiffstats
path: root/lib/private/Preview/TXT.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-06-25 15:05:54 +0200
committerGitHub <noreply@github.com>2019-06-25 15:05:54 +0200
commitd4a44d9b784eef554a0e5450d07bd5d5d2d61193 (patch)
tree65c3940185836f6635558b62b16e5ee65b94a1a2 /lib/private/Preview/TXT.php
parent335af0c46c0034ea9052a90fa2b43a0b9bc985e7 (diff)
parent615061437422499025e038483504d4ef2004c8e1 (diff)
downloadnextcloud-server-d4a44d9b784eef554a0e5450d07bd5d5d2d61193.tar.gz
nextcloud-server-d4a44d9b784eef554a0e5450d07bd5d5d2d61193.zip
Merge pull request #15870 from nextcloud/preview-provider-v2
Add new Provider interface for preview providers
Diffstat (limited to 'lib/private/Preview/TXT.php')
-rw-r--r--lib/private/Preview/TXT.php20
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/private/Preview/TXT.php b/lib/private/Preview/TXT.php
index 2bb121775d6..1ac98d62338 100644
--- a/lib/private/Preview/TXT.php
+++ b/lib/private/Preview/TXT.php
@@ -26,36 +26,40 @@
*/
namespace OC\Preview;
-class TXT extends Provider {
+use OCP\Files\File;
+use OCP\Files\FileInfo;
+use OCP\IImage;
+
+class TXT extends ProviderV2 {
/**
* {@inheritDoc}
*/
- public function getMimeType() {
+ public function getMimeType(): string {
return '/text\/plain/';
}
/**
* {@inheritDoc}
*/
- public function isAvailable(\OCP\Files\FileInfo $file) {
+ public function isAvailable(FileInfo $file): bool {
return $file->getSize() > 0;
}
/**
* {@inheritDoc}
*/
- public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
- $content = $fileview->fopen($path, 'r');
+ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
+ $content = $file->fopen('r');
if ($content === false) {
- return false;
+ return null;
}
$content = stream_get_contents($content,3000);
//don't create previews of empty text files
if(trim($content) === '') {
- return false;
+ return null;
}
$lines = preg_split("/\r\n|\n|\r/", $content);
@@ -95,6 +99,6 @@ class TXT extends Provider {
$imageObject = new \OC_Image();
$imageObject->setResource($image);
- return $imageObject->valid() ? $imageObject : false;
+ return $imageObject->valid() ? $imageObject : null;
}
}