Skip to content

Commit c04d06a

Browse files
committed
Download via href?
1 parent f88f676 commit c04d06a

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/components/Compile.vue

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
persistent
77
@after-enter="submitJob"
88
>
9-
<v-card
9+
<v-card
1010
max-width="400"
1111
title="Compiling..."
1212
>
@@ -15,41 +15,50 @@
1515
<div class="d-flex justify-center">
1616
<v-progress-circular :size="64" :width="6" class="ma-6" indeterminate/>
1717
</div>
18-
<!-- <p v-if=jobID class="text-md-center">JobID: {{ jobID }}</p> -->
1918
</template>
19+
2020
<template #actions>
2121
<v-btn class="ms-auto" text="Abort" @click="abort"/>
22+
<a class="d-none" ref="download" :download="firmwareName" :href="firmwareURL"/>
2223
</template>
2324
</v-card>
2425
</v-dialog>
2526
</template>
2627

2728
<script lang="ts" setup>
28-
import { ref } from 'vue'
29+
import { ref, computed, useTemplateRef } from 'vue'
2930
import { useFetch, useIntervalFn } from '@vueuse/core'
3031
import { useKeymapState } from '@/composables/useKeymapState'
31-
import { saveAs } from 'file-saver';
3232
33-
const { keymap } = useKeymapState()
33+
const { keymap } = useKeymapState();
3434
3535
const dialog = ref(false);
36-
const jobID = ref('')
36+
const downloadBtn = useTemplateRef('download');
37+
38+
const jobID = ref('');
39+
const firmwareName = ref('');
40+
41+
const firmwareURL = computed(() => {
42+
return `https://api.qmk.fm/v1/compile/${jobID.value}/download`;
43+
})
3744
3845
const { pause, resume } = useIntervalFn(async () => {
39-
const { data } = await useFetch(`https://api.qmk.fm/v1/compile/${jobID.value}`).get().json()
46+
const { data } = await useFetch(`https://api.qmk.fm/v1/compile/${jobID.value}`).get().json();
4047
4148
if(data.value.status === 'finished') {
42-
abort();
49+
firmwareName.value = data.value.result.firmware_filename;
4350
44-
saveAs(`https://api.qmk.fm/v1/compile/${jobID.value}/download`, data.value.result.firmware_filename);
51+
setTimeout(() => {
52+
download();
53+
});
4554
}
4655
}, 2500, {immediate: false})
4756
4857
const submitJob = async () => {
49-
const { data } = await useFetch('https://api.qmk.fm/v1/compile').post(keymap.value).json()
58+
const { data } = await useFetch('https://api.qmk.fm/v1/compile').post(keymap.value).json();
5059
5160
if (!data.value.enqueued) {
52-
console.log("error?")
61+
console.log("error?");
5362
return;
5463
}
5564
@@ -62,4 +71,10 @@ const abort = () => {
6271
dialog.value = false;
6372
}
6473
74+
const download = () => {
75+
abort();
76+
77+
downloadBtn.value?.click();
78+
}
79+
6580
</script>

0 commit comments

Comments
 (0)