Skip to content

Commit

Permalink
serve image previews
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
  • Loading branch information
Julien Veyssier committed Nov 4, 2021
1 parent 76ad986 commit d477769
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
18 changes: 14 additions & 4 deletions lib/Service/ImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
use OCP\Files\Folder;
use OCP\Files\File;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IPreview;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IShare;
use Throwable;
Expand Down Expand Up @@ -64,15 +66,21 @@ class ImageService {
* @var LoggerInterface
*/
private $logger;
/**
* @var IPreview
*/
private $previewManager;

public function __construct(IRootFolder $rootFolder,
LoggerInterface $logger,
ShareManager $shareManager,
IPreview $previewManager,
IClientService $clientService) {
$this->rootFolder = $rootFolder;
$this->shareManager = $shareManager;
$this->clientService = $clientService;
$this->logger = $logger;
$this->previewManager = $previewManager;
}

/**
Expand All @@ -88,7 +96,7 @@ public function __construct(IRootFolder $rootFolder,
* @throws \OCP\Lock\LockedException
* @throws \OC\User\NoUserException
*/
public function getImage(int $textFileId, string $imageFileName, string $userId): ?File {
public function getImage(int $textFileId, string $imageFileName, string $userId): ?ISimpleFile {
$textFile = $this->getTextFile($textFileId, $userId);
$attachmentFolder = $this->getOrCreateAttachmentDirectoryForFile($textFile);
if ($attachmentFolder !== null) {
Expand All @@ -98,7 +106,8 @@ public function getImage(int $textFileId, string $imageFileName, string $userId)
return null;
}
if ($imageFile instanceof File) {
return $imageFile;
// return $imageFile;
return $this->previewManager->getPreview($imageFile, 1024, 1024);
}
}
return null;
Expand All @@ -117,7 +126,7 @@ public function getImage(int $textFileId, string $imageFileName, string $userId)
* @throws \OCP\Lock\LockedException
* @throws \OC\User\NoUserException
*/
public function getImagePublic(int $textFileId, string $imageFileName, string $shareToken): ?File {
public function getImagePublic(int $textFileId, string $imageFileName, string $shareToken): ?ISimpleFile {
$textFile = $this->getTextFilePublic($textFileId, $shareToken);
$attachmentFolder = $this->getOrCreateAttachmentDirectoryForFile($textFile);
if ($attachmentFolder !== null) {
Expand All @@ -127,7 +136,8 @@ public function getImagePublic(int $textFileId, string $imageFileName, string $s
return null;
}
if ($imageFile instanceof File) {
return $imageFile;
// return $imageFile;
return $this->previewManager->getPreview($imageFile, 1024, 1024);
}
}
return null;
Expand Down
1 change: 0 additions & 1 deletion src/components/PublicFilesEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export default {
},
computed: {
fileName() {
console.debug('PUBLIC FILE ID', this.fileId)
return this.relativePath.substring(this.relativePath.lastIndexOf('/') + 1)
},
},
Expand Down
1 change: 0 additions & 1 deletion src/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ documentReady(() => {
registerFileCreate()
} else {
// single file share
console.debug('SINGLE FILE SHARE !!!!!!!!!!!')
const container = document.createElement('div')
container.id = 'texteditor'
const body = document.getElementById('app-content')
Expand Down

0 comments on commit d477769

Please sign in to comment.