refactor: move local check to utils

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/767/head
Varun Patil 2023-08-02 19:30:04 -07:00
parent 4b1759fb11
commit c231e48df9
5 changed files with 24 additions and 16 deletions

View File

@ -118,24 +118,24 @@ export default defineComponent({
}, },
computed: { computed: {
isVideo() { isVideo(): boolean {
return this.photo && (this.photo.mimetype?.startsWith('video/') || this.photo.flag & this.c.FLAG_IS_VIDEO); 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(); return 'share' in navigator || nativex.has();
}, },
canShareHighRes() { canShareHighRes(): boolean {
return !this.isLocal && (!this.isVideo || !this.config.vod_disable); return !this.isLocal && (!this.isVideo || !this.config.vod_disable);
}, },
canShareLink() { canShareLink(): boolean {
return this.photo?.imageInfo?.permissions?.includes('S'); return !!this.photo?.imageInfo?.permissions?.includes('S');
}, },
isLocal() { isLocal(): boolean {
return Boolean((this.photo?.flag ?? 0) & this.c.FLAG_IS_LOCAL); return utils.isLocalPhoto(this.photo);
}, },
}, },

View File

@ -142,7 +142,7 @@ class VideoContentSetup {
const fileid = content.data.photo.fileid; const fileid = content.data.photo.fileid;
// Local videos are played back directly // 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); nativex.playVideoLocal(fileid);
return; return;
} }

View File

@ -330,7 +330,7 @@ export default defineComponent({
/** Is the current slide a local photo */ /** Is the current slide a local photo */
isLocal(): boolean { 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 */ /** Show bottom bar info such as date taken */
@ -808,7 +808,7 @@ export default defineComponent({
// Get full image URL // Get full image URL
const fullUrl = isvideo const fullUrl = isvideo
? null ? null
: photo.flag & this.c.FLAG_IS_LOCAL : utils.isLocalPhoto(photo)
? nativex.API.IMAGE_FULL(photo.fileid) ? nativex.API.IMAGE_FULL(photo.fileid)
: API.IMAGE_DECODABLE(photo.fileid, photo.etag); : API.IMAGE_DECODABLE(photo.fileid, photo.etag);
const fullLoadCond = this.config.full_res_always ? 'always' : this.config.full_res_on_zoom ? 'zoom' : 'never'; const fullLoadCond = this.config.full_res_always ? 'always' : this.config.full_res_on_zoom ? 'zoom' : 'never';

View File

@ -55,7 +55,7 @@ export async function getFiles(photos: IPhoto[]): Promise<IFileInfo[]> {
let fileInfos: IFileInfo[] = []; let fileInfos: IFileInfo[] = [];
// Remove any local photos // 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 // Get file IDs array
const fileIds = photos.map((photo) => photo.fileid); const fileIds = photos.map((photo) => photo.fileid);

View File

@ -54,7 +54,7 @@ export function getPreviewUrl(opts: PreviewOptsSize | PreviewOptsMsize | Preview
if (square) size = sqsize as any; if (square) size = sqsize as any;
// Native preview // 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 }); 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 * Get the URL for the imageInfo of a photo
* *
* @param photo Photo object or fileid (remote only) * @param photo Photo object or fileid (remote only)
*/ */
export function getImageInfoUrl(photo: IPhoto | number) { export function getImageInfoUrl(photo: IPhoto | number): string {
const fileid = typeof photo === 'object' ? photo.fileid : photo; 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); return nativex.API.IMAGE_INFO(fileid);
} }