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:
@@ -65,9 +65,10 @@ class AttachmentApiController extends ApiController {
|
|||||||
|
|
||||||
$fileId = $this->fileService->upload($file['name'], file_get_contents($file['tmp_name']));
|
$fileId = $this->fileService->upload($file['name'], file_get_contents($file['tmp_name']));
|
||||||
return new JSONResponse([
|
return new JSONResponse([
|
||||||
'file_id' => $fileId,
|
'file_id' => $fileId,
|
||||||
'preview_url' => $this->fileService->getPreviewUrl($fileId, 512),
|
'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 $createdAt;
|
||||||
protected $previewUrl;
|
protected $previewUrl;
|
||||||
protected $redirectUrl;
|
protected $redirectUrl;
|
||||||
|
protected $deepLinkUrl;
|
||||||
|
|
||||||
public function setPreviewUrl($previewUrl) {
|
public function setPreviewUrl($previewUrl) {
|
||||||
$this->previewUrl = $previewUrl;
|
$this->previewUrl = $previewUrl;
|
||||||
@@ -21,14 +22,19 @@ class Attach extends Entity implements JsonSerializable {
|
|||||||
$this->redirectUrl = $redirectUrl;
|
$this->redirectUrl = $redirectUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setDeepLinkUrl($deepLinkUrl) {
|
||||||
|
$this->deepLinkUrl = $deepLinkUrl;
|
||||||
|
}
|
||||||
|
|
||||||
public function jsonSerialize() {
|
public function jsonSerialize() {
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'note_id' => $this->noteId,
|
'note_id' => $this->noteId,
|
||||||
'file_id' => $this->fileId,
|
'file_id' => $this->fileId,
|
||||||
'created_at' => $this->createdAt,
|
'created_at' => $this->createdAt,
|
||||||
'preview_url' => $this->previewUrl,
|
'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['dir'] = $userFolder->getRelativePath($file->getParent()->getPath());
|
||||||
$params['scrollto'] = $file->getName();
|
$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))
|
if (is_null($redirectUrl))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
$deepLinkUrl = $this->fileService->getDeepLinkUrl($attach->getFileId());
|
||||||
|
if (is_null($deepLinkUrl))
|
||||||
|
continue;
|
||||||
|
|
||||||
$attach->setPreviewUrl($previewUrl);
|
$attach->setPreviewUrl($previewUrl);
|
||||||
$attach->setRedirectUrl($redirectUrl);
|
$attach->setRedirectUrl($redirectUrl);
|
||||||
|
$attach->setDeepLinkUrl($deepLinkUrl);
|
||||||
|
|
||||||
$rAttachts[] = $attach;
|
$rAttachts[] = $attach;
|
||||||
}
|
}
|
||||||
@@ -372,6 +377,7 @@ class NoteService {
|
|||||||
foreach ($attachts as $attach) {
|
foreach ($attachts as $attach) {
|
||||||
$attach->setPreviewUrl($this->fileService->getPreviewUrl($attach->getFileId(), 512));
|
$attach->setPreviewUrl($this->fileService->getPreviewUrl($attach->getFileId(), 512));
|
||||||
$attach->setRedirectUrl($this->fileService->getRedirectToFileUrl($attach->getFileId()));
|
$attach->setRedirectUrl($this->fileService->getRedirectToFileUrl($attach->getFileId()));
|
||||||
|
$attach->setDeepLinkUrl($this->fileService->getDeepLinkUrl($attach->getFileId()));
|
||||||
}
|
}
|
||||||
$newnote->setAttachts($attachts);
|
$newnote->setAttachts($attachts);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user