metadata: use loaded image info

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/900/head
Varun Patil 2023-10-29 11:56:06 -07:00
parent 9e001730c2
commit 9251bba6fc
1 changed files with 31 additions and 18 deletions

View File

@ -1,8 +1,5 @@
<template> <template>
<div class="loading-icon fill-block" v-if="loading"> <div class="outer" v-if="fileid">
<XLoadingIcon />
</div>
<div class="outer" v-else-if="fileid">
<div v-if="title || description" class="exif-head" @click="editEXIF()"> <div v-if="title || description" class="exif-head" @click="editEXIF()">
<div class="title" v-if="title">{{ title }}</div> <div class="title" v-if="title">{{ title }}</div>
<div class="description" v-if="description">{{ description }}</div> <div class="description" v-if="description">{{ description }}</div>
@ -60,6 +57,9 @@
<iframe class="fill-block" :src="mapUrl" /> <iframe class="fill-block" :src="mapUrl" />
</div> </div>
</div> </div>
<div class="loading-icon fill-block" v-else-if="loading">
<XLoadingIcon />
</div>
<div v-else> <div v-else>
{{ t('memries', 'Failed to load metadata') }} {{ t('memries', 'Failed to load metadata') }}
</div> </div>
@ -389,6 +389,17 @@ export default defineComponent({
this.fileid = null; this.fileid = null;
this.exif = {}; this.exif = {};
// get photo from id if this is the current viewer photo
if (_m.viewer.currentPhoto?.fileid === photo) {
photo = _m.viewer.currentPhoto;
}
// try to get as much information as we can from
// the image info already loaded
if (typeof photo === 'object' && photo.imageInfo) {
this.setImageInfo(photo.imageInfo);
}
// which clusters to get // which clusters to get
const clusters = this.routeIsPublic const clusters = this.routeIsPublic
? String() ? String()
@ -407,16 +418,15 @@ export default defineComponent({
const url = API.Q(utils.getImageInfoUrl(photo), { tags, clusters }); const url = API.Q(utils.getImageInfoUrl(photo), { tags, clusters });
const res = await this.guardState(axios.get<IImageInfo>(url)); const res = await this.guardState(axios.get<IImageInfo>(url));
if (!res) return null; if (!res) return null;
this.setImageInfo(res.data);
// unwrap basic info
this.fileid = res.data.fileid;
this.filename = res.data.basename;
this.exif = res.data.exif || {};
this.baseInfo = res.data;
return this.baseInfo; return this.baseInfo;
}, },
async refresh() {
if (this.fileid) await this.update(this.fileid);
},
editDate() { editDate() {
_m.modals.editMetadata([_m.viewer.currentPhoto!], [1]); _m.modals.editMetadata([_m.viewer.currentPhoto!], [1]);
}, },
@ -433,8 +443,17 @@ export default defineComponent({
_m.modals.editMetadata([_m.viewer.currentPhoto!], [4]); _m.modals.editMetadata([_m.viewer.currentPhoto!], [4]);
}, },
async refresh() { setImageInfo(info: IImageInfo) {
if (this.fileid) await this.update(this.fileid); this.fileid = info.fileid;
this.filename = info.basename;
this.exif = info.exif ?? {};
this.baseInfo = info;
},
handleFileUpdated({ fileid }: utils.BusEvent['files:file:updated']) {
if (fileid && this.fileid === fileid) {
this.refresh();
}
}, },
async guardState<T>(promise: Promise<T>): Promise<T | null> { async guardState<T>(promise: Promise<T>): Promise<T | null> {
@ -450,12 +469,6 @@ export default defineComponent({
if (state === this.state) this.loading--; if (state === this.state) this.loading--;
} }
}, },
handleFileUpdated({ fileid }: utils.BusEvent['files:file:updated']) {
if (fileid && this.fileid === fileid) {
this.refresh();
}
},
}, },
}); });
</script> </script>