add: check multiple preview file extensions

v0.3
rrr-marble 4 years ago
parent 7e5b499830
commit 3d380dfa43

@ -1,9 +1,7 @@
<template> <template>
<div class="flex md6 lg4"> <div class="flex md6 lg4">
<va-card id="preview" class="content-container"> <va-card id="preview" class="content-container">
<va-image <va-image contain :src="slotPreviewPath" :alt="`${this.itemDetails.description}`">
:src="`${this.baseURL}/static/previews/${this.itemDetails.fadr}+/${this.itemDetails.internal_id}.bmp`"
:alt="`${this.itemDetails.description}`">
<template #loader> <template #loader>
<va-progress-circle indeterminate /> <va-progress-circle indeterminate />
</template> </template>
@ -64,6 +62,7 @@ export default {
], ],
itemPreview: {}, itemPreview: {},
baseURL: "http://localhost:8080", baseURL: "http://localhost:8080",
imageExtension: "bmp"
}; };
}, },
methods: { methods: {
@ -74,17 +73,34 @@ export default {
.then(data => this.itemDetails = data) .then(data => this.itemDetails = data)
.catch((e) => console.log(e)); .catch((e) => console.log(e));
}, },
async fetchItemPreview() { getPreviewPath(){
const baseURL = "http://localhost:8080/api/v1"; for (let extension of ["jpg", "png", "bmp"]) {
fetch(`${baseURL}/static/previews/${this.itemDetails.fadr}+/${this.itemDetails.internal_id}.bmp`) const path = `${this.baseURL}/static/previews/${this.itemDetails.fadr}+/${this.itemDetails.internal_id}.${extension}`
.then(res => res.json()) fetch(path, {method: 'HEAD'})
.then(data => this.itemPreview = data) .then(resp => {
.catch((e) => console.log(e)); if (resp.status === 200) {
this.imageExtension = extension;
}
})
.catch(e => {
// 404 are expected here, so ignore it
if (e.status !== 404){
//console.log(e)
}
})
}
return `${this.baseURL}/static/previews/${this.itemDetails.fadr}+/${this.itemDetails.internal_id}.${this.imageExtension}`
} }
}, },
created() { created() {
this.fetchItemDetails(); this.fetchItemDetails();
}, },
computed: {
slotPreviewPath(){
return this.getPreviewPath()
}
},
components: { MapComponent } components: { MapComponent }
} }
</script> </script>

Loading…
Cancel
Save