mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-11-30 23:37:16 +01:00
Add direct deep-link to attachments
This commit is contained in:
@@ -67,7 +67,8 @@ class AttachmentApiController extends ApiController {
|
||||
return new JSONResponse([
|
||||
'file_id' => $fileId,
|
||||
'preview_url' => $this->fileService->getPreviewUrl($fileId, 512),
|
||||
'redirect_url' => $this->fileService->getRedirectToFileUrl($fileId)
|
||||
'redirect_url' => $this->fileService->getRedirectToFileUrl($fileId),
|
||||
'deep_link_url' => $this->fileService->getDeepLinkUrl($fileId)
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class Attach extends Entity implements JsonSerializable {
|
||||
protected $createdAt;
|
||||
protected $previewUrl;
|
||||
protected $redirectUrl;
|
||||
protected $deepLinkUrl;
|
||||
|
||||
public function setPreviewUrl($previewUrl) {
|
||||
$this->previewUrl = $previewUrl;
|
||||
@@ -21,6 +22,10 @@ class Attach extends Entity implements JsonSerializable {
|
||||
$this->redirectUrl = $redirectUrl;
|
||||
}
|
||||
|
||||
public function setDeepLinkUrl($deepLinkUrl) {
|
||||
$this->deepLinkUrl = $deepLinkUrl;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
@@ -28,7 +33,8 @@ class Attach extends Entity implements JsonSerializable {
|
||||
'file_id' => $this->fileId,
|
||||
'created_at' => $this->createdAt,
|
||||
'preview_url' => $this->previewUrl,
|
||||
'redirect_url' => $this->redirectUrl
|
||||
'redirect_url' => $this->redirectUrl,
|
||||
'deep_link_url' => $this->deepLinkUrl
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,28 @@ class FileService {
|
||||
$params['dir'] = $userFolder->getRelativePath($file->getParent()->getPath());
|
||||
$params['scrollto'] = $file->getName();
|
||||
|
||||
return $this->urlGenerator->linkToRoute('files.view.index', $params);
|
||||
return $this->urlGenerator->getAbsoluteURL(
|
||||
$this->urlGenerator->linkToRoute('files.view.index', $params)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a deep link that can open directly on clients to the given file id
|
||||
*
|
||||
* @param int $fileId file id to open
|
||||
*/
|
||||
public function getDeepLinkUrl(int $fileId): ?string {
|
||||
$userFolder = $this->rootFolder->getUserFolder($this->userId);
|
||||
$file = current($userFolder->getById($fileId));
|
||||
|
||||
if (!($file instanceof File)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// return "nc://directlink/f/" . $fileId;
|
||||
return $this->urlGenerator->getAbsoluteURL(
|
||||
"/f/" . $fileId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -125,8 +125,13 @@ class NoteService {
|
||||
if (is_null($redirectUrl))
|
||||
continue;
|
||||
|
||||
$deepLinkUrl = $this->fileService->getDeepLinkUrl($attach->getFileId());
|
||||
if (is_null($deepLinkUrl))
|
||||
continue;
|
||||
|
||||
$attach->setPreviewUrl($previewUrl);
|
||||
$attach->setRedirectUrl($redirectUrl);
|
||||
$attach->setDeepLinkUrl($deepLinkUrl);
|
||||
|
||||
$rAttachts[] = $attach;
|
||||
}
|
||||
@@ -372,6 +377,7 @@ class NoteService {
|
||||
foreach ($attachts as $attach) {
|
||||
$attach->setPreviewUrl($this->fileService->getPreviewUrl($attach->getFileId(), 512));
|
||||
$attach->setRedirectUrl($this->fileService->getRedirectToFileUrl($attach->getFileId()));
|
||||
$attach->setDeepLinkUrl($this->fileService->getDeepLinkUrl($attach->getFileId()));
|
||||
}
|
||||
$newnote->setAttachts($attachts);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user