nx: attempt to share local file

Signed-off-by: Varun Patil <radialapps@gmail.com>
dexie
Varun Patil 2023-09-30 15:01:12 -07:00
parent 3ec3a7bcd2
commit e787b1c14e
2 changed files with 16 additions and 7 deletions

View File

@ -176,10 +176,18 @@ export default defineComponent({
},
async shareOriginal() {
if (this.isLocal) {
return this.l(async () => await nativex.shareLocal(this.photo!.fileid));
if (nativex.has()) {
try {
return await this.l(async () => await nativex.shareLocal(this.photo!));
} catch (e) {
// maybe the file doesn't exist locally
}
this.shareWithHref(dav.getDownloadLink(this.photo!));
// if it's purel local, we can't share it
if (this.isLocal) return;
}
await this.shareWithHref(dav.getDownloadLink(this.photo!));
},
async shareLink() {

View File

@ -77,10 +77,10 @@ export const API = {
/**
* Share a local file (as blob) with native page.
* @regex ^/api/share/local/\d+$
* @param fileId File ID of the photo
* @param auid AUID of the photo
* @returns {void}
*/
SHARE_LOCAL: (fileId: number) => `${BASE_URL}/api/share/local/${fileId}`,
SHARE_LOCAL: (auid: number) => `${BASE_URL}/api/share/local/${auid}`,
/**
* Get list of local folders configuration.
@ -257,8 +257,9 @@ export async function shareBlobFromUrl(url: string) {
/**
* Share a local file with native page.
*/
export async function shareLocal(fileId: number) {
await axios.get(API.SHARE_LOCAL(fileId));
export async function shareLocal(photo: IPhoto) {
if (!photo.auid) throw new Error('Cannot share local file without AUID');
await axios.get(API.SHARE_LOCAL(photo.auid));
}
/**