Skip to content

Commit

Permalink
refs #22 directly process image urls when providing markdown file con…
Browse files Browse the repository at this point in the history
…tent

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Dec 28, 2022
1 parent 98ee680 commit dfc3450
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\IUserManager;

function startsWith(string $haystack, string $needle): bool {
Expand All @@ -42,13 +43,19 @@ class FileService {
* @var IUserManager
*/
private $userManager;
/**
* @var IURLGenerator
*/
private $urlGenerator;

public function __construct (IRootFolder $root,
IConfig $config,
IURLGenerator $urlGenerator,
IUserManager $userManager) {
$this->root = $root;
$this->config = $config;
$this->userManager = $userManager;
$this->urlGenerator = $urlGenerator;
}

/**
Expand Down Expand Up @@ -155,7 +162,8 @@ private function replaceImagePaths(string $content, Folder $folder): string {
$file = $folder->get($decodedPath);
if ($file instanceof File) {
$fullMatch = $match[0];
$newLink = str_replace($path, 'a?fileId=' . $file->getId(), $fullMatch);
$welcomeImageUrl = $this->urlGenerator->linkToRoute(Application::APP_ID . '.config.getWidgetImage', ['fileId' => $file->getId()]);
$newLink = str_replace($path, $welcomeImageUrl, $fullMatch);
$content = str_replace($fullMatch, $newLink, $content);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export default {
this.content = response.data.content
// eslint-disable-next-line
this.content = this.content.replaceAll(/\!\[(.*)\]\(.*\?fileId=(\d+).*/g, (match, p1, p2) => {
// return '![' + p1 + '](' + generateUrl('/core/preview?fileId=' + p2 + '&x=200&y=200&a=true') + ')'
// we get the image we an app-specific endpoint
return '![' + p1 + '](' + generateUrl('/apps/welcome/widget/image/{fileId}', { fileId: p2 }) + ')'
})
Expand Down

0 comments on commit dfc3450

Please sign in to comment.