-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chat): add download link to attachments
Signed-off-by: Grigorii K. Shartsev <[email protected]>
- Loading branch information
1 parent
21b2f94
commit f1b9c4d
Showing
2 changed files
with
57 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { getCurrentUser } from '@nextcloud/auth' | ||
import { davRemoteURL } from '@nextcloud/files' | ||
|
||
/** | ||
* Generate a WebDAV url to a user files | ||
* @param filepath - The path to the user's file, e.g., Talk/20240101-000102.png | ||
* @param userid - The user id, e.g., 'admin'. Defaults to the current user id | ||
* @return {string} The WebDAV URL to the file, e.g., https://nextcloud.ltd/remote.php/dav/files/admin/Talk/20240101-000102.png | ||
*/ | ||
export function generateUserFileUrl(filepath: string, userid: string | undefined = getCurrentUser()?.uid) { | ||
if (!userid) { | ||
throw new TypeError('Cannot generate /files/<user>/ URL without a user') | ||
} | ||
return davRemoteURL + '/files/' + encodeURI(userid) + '/' + encodeURI(filepath) | ||
} | ||
|
||
/** | ||
* Generate a download link for a public share | ||
* @param shareLink - The public share link, e.g., https://nextcloud.ltd/s/CBeNTiJz5JeT2CH/ | ||
* @return {string} The download link, e.g., https://nextcloud.ltd/s/CBeNTiJz5JeT2CH/download | ||
*/ | ||
export function generatePublicShareDownloadUrl(shareLink: string) { | ||
return shareLink + '/download' | ||
} |