Skip to content

Commit 395018c

Browse files
committed
Automatic file extension for blob downloads
1 parent dfa30d2 commit 395018c

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

components/modals/BlobModal.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const props = defineProps({
1919
show: Boolean,
2020
})
2121
22+
const supportedContentTypeForPreview = ["image/png", "image/jpeg", "video/mp4", "text/plain; charset=utf-8"]
23+
2224
const isLoading = ref(true)
2325
const isStopped = ref(false)
2426
const blob = ref({})
@@ -121,12 +123,18 @@ const handleDownload = () => {
121123
.map((e) => parseInt(e, 16)),
122124
)
123125
126+
let extension = "bin"
127+
if (supportedContentTypeForPreview.includes(blob.value?.content_type)) {
128+
const ct = blob.value.content_type.split(";")[0].split("/")[1]
129+
extension = ct === "plain" ? "txt" : ct
130+
}
131+
124132
const a = window.document.createElement("a")
125133
a.href = window.URL.createObjectURL(new Blob([byteArray], { type: "application/octet-stream" }))
126134
a.download = `${getNamespaceID(cacheStore.selectedBlob.namespace_id)}_${cacheStore.selectedBlob.commitment.slice(
127135
cacheStore.selectedBlob.commitment.length - 8,
128136
cacheStore.selectedBlob.commitment.length,
129-
)}.bin`
137+
)}.${extension}`
130138
document.body.appendChild(a)
131139
a.click()
132140
document.body.removeChild(a)

pages/blob.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ cacheStore.current.blob = {
100100
}
101101
102102
onMounted(() => {
103-
if (!supportedContentTypeForPreview.includes(blob.content_type)) cards.value.preview = false
103+
if (!supportedContentTypeForPreview.includes(blob.value?.content_type)) cards.value.preview = false
104104
105105
innerWidth.value = window.innerWidth
106106
if (innerWidth.value <= 1020) {
@@ -177,12 +177,18 @@ const handleDownload = () => {
177177
.map((e) => parseInt(e, 16)),
178178
)
179179
180+
let extension = "bin"
181+
if (supportedContentTypeForPreview.includes(blob.value?.content_type)) {
182+
const ct = blob.value.content_type.split(";")[0].split("/")[1]
183+
extension = ct === "plain" ? "txt" : ct
184+
}
185+
180186
const a = window.document.createElement("a")
181187
a.href = window.URL.createObjectURL(new Blob([byteArray], { type: "application/octet-stream" }))
182188
a.download = `${metadata.value.namespace.namespace_id}_${blob.value.commitment.slice(
183189
blob.value.commitment.length - 8,
184190
blob.value.commitment.length,
185-
)}.bin`
191+
)}.${extension}`
186192
document.body.appendChild(a)
187193
a.click()
188194
document.body.removeChild(a)

pages/stats/[metric].vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ if (!series.value.page) {
4141
router.push("/stats")
4242
}
4343
44-
const metricName = computed(() => capitalizeAndReplaceUnderscore(series.value?.page))
44+
const metricName = computed(() => {
45+
if (series.value.page === "tvs") return series.value.title
46+
return capitalizeAndReplaceUnderscore(series.value?.page)
47+
})
4548
4649
// defineOgImage({
4750
// title: "Rollup",

services/constants/stats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export const STATS_SERIES = [
114114
{
115115
subGroup: 'economy',
116116
name: 'tvs',
117-
title: 'TVS',
117+
title: 'Total Value Secured',
118118
page: 'tvs',
119119
units: 'usd',
120120
},

0 commit comments

Comments
 (0)