From c231e48df90b531f2ae577ed91e067230f410808 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Wed, 2 Aug 2023 19:30:04 -0700 Subject: [PATCH] refactor: move local check to utils Signed-off-by: Varun Patil --- src/components/modal/ShareModal.vue | 16 ++++++++-------- src/components/viewer/PsVideo.ts | 2 +- src/components/viewer/Viewer.vue | 4 ++-- src/services/dav/base.ts | 2 +- src/services/utils/helpers.ts | 16 ++++++++++++---- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/components/modal/ShareModal.vue b/src/components/modal/ShareModal.vue index 302200ec..4c61b5e5 100644 --- a/src/components/modal/ShareModal.vue +++ b/src/components/modal/ShareModal.vue @@ -118,24 +118,24 @@ export default defineComponent({ }, computed: { - isVideo() { - return this.photo && (this.photo.mimetype?.startsWith('video/') || this.photo.flag & this.c.FLAG_IS_VIDEO); + isVideo(): boolean { + return !!this.photo && (this.photo.mimetype?.startsWith('video/') || !!(this.photo.flag & this.c.FLAG_IS_VIDEO)); }, - canShareNative() { + canShareNative(): boolean { return 'share' in navigator || nativex.has(); }, - canShareHighRes() { + canShareHighRes(): boolean { return !this.isLocal && (!this.isVideo || !this.config.vod_disable); }, - canShareLink() { - return this.photo?.imageInfo?.permissions?.includes('S'); + canShareLink(): boolean { + return !!this.photo?.imageInfo?.permissions?.includes('S'); }, - isLocal() { - return Boolean((this.photo?.flag ?? 0) & this.c.FLAG_IS_LOCAL); + isLocal(): boolean { + return utils.isLocalPhoto(this.photo); }, }, diff --git a/src/components/viewer/PsVideo.ts b/src/components/viewer/PsVideo.ts index 59d3b7fe..828952d6 100644 --- a/src/components/viewer/PsVideo.ts +++ b/src/components/viewer/PsVideo.ts @@ -142,7 +142,7 @@ class VideoContentSetup { const fileid = content.data.photo.fileid; // Local videos are played back directly - if (content.data.photo.flag & utils.constants.c.FLAG_IS_LOCAL) { + if (utils.isLocalPhoto(content.data.photo)) { nativex.playVideoLocal(fileid); return; } diff --git a/src/components/viewer/Viewer.vue b/src/components/viewer/Viewer.vue index 6d729bc9..58b3c3f1 100644 --- a/src/components/viewer/Viewer.vue +++ b/src/components/viewer/Viewer.vue @@ -330,7 +330,7 @@ export default defineComponent({ /** Is the current slide a local photo */ isLocal(): boolean { - return Boolean((this.currentPhoto?.flag ?? 0) & this.c.FLAG_IS_LOCAL); + return utils.isLocalPhoto(this.currentPhoto); }, /** Show bottom bar info such as date taken */ @@ -808,7 +808,7 @@ export default defineComponent({ // Get full image URL const fullUrl = isvideo ? null - : photo.flag & this.c.FLAG_IS_LOCAL + : utils.isLocalPhoto(photo) ? nativex.API.IMAGE_FULL(photo.fileid) : API.IMAGE_DECODABLE(photo.fileid, photo.etag); const fullLoadCond = this.config.full_res_always ? 'always' : this.config.full_res_on_zoom ? 'zoom' : 'never'; diff --git a/src/services/dav/base.ts b/src/services/dav/base.ts index 06e2c6c4..1fa082e3 100644 --- a/src/services/dav/base.ts +++ b/src/services/dav/base.ts @@ -55,7 +55,7 @@ export async function getFiles(photos: IPhoto[]): Promise { let fileInfos: IFileInfo[] = []; // Remove any local photos - photos = photos.filter((photo) => !(photo.flag & utils.constants.c.FLAG_IS_LOCAL)); + photos = photos.filter((photo) => !utils.isLocalPhoto(photo)); // Get file IDs array const fileIds = photos.map((photo) => photo.fileid); diff --git a/src/services/utils/helpers.ts b/src/services/utils/helpers.ts index 6eab58f6..1c9e6df1 100644 --- a/src/services/utils/helpers.ts +++ b/src/services/utils/helpers.ts @@ -54,7 +54,7 @@ export function getPreviewUrl(opts: PreviewOptsSize | PreviewOptsMsize | Preview if (square) size = sqsize as any; // Native preview - if (photo.flag & constants.c.FLAG_IS_LOCAL) { + if (isLocalPhoto(photo)) { return API.Q(nativex.API.IMAGE_PREVIEW(photo.fileid), { c: photo.etag }); } @@ -86,15 +86,23 @@ export function getPreviewUrl(opts: PreviewOptsSize | PreviewOptsMsize | Preview }); } +/** + * Check if the object is a local photo + * @param photo Photo object + */ +export function isLocalPhoto(photo: any): boolean { + return typeof photo === 'object' && photo?.fileid && Boolean((photo?.flag ?? 0) & constants.c.FLAG_IS_LOCAL); +} + /** * Get the URL for the imageInfo of a photo * * @param photo Photo object or fileid (remote only) */ -export function getImageInfoUrl(photo: IPhoto | number) { - const fileid = typeof photo === 'object' ? photo.fileid : photo; +export function getImageInfoUrl(photo: IPhoto | number): string { + const fileid = typeof photo === 'number' ? photo : photo.fileid; - if (typeof photo === 'object' && photo.flag & constants.c.FLAG_IS_LOCAL) { + if (isLocalPhoto(photo)) { return nativex.API.IMAGE_INFO(fileid); }