-
+
@@ -130,7 +159,10 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent)
-
+ selected_file = file"
+ />
diff --git a/composables/useDownload.ts b/composables/useDownload.ts
new file mode 100644
index 0000000..301ddc0
--- /dev/null
+++ b/composables/useDownload.ts
@@ -0,0 +1,16 @@
+export const useDownload = (url: string, filename: string) => {
+ const download = () => {
+ fetch(url)
+ .then((response) => response.blob())
+ .then((blob) => {
+ const url = window.URL.createObjectURL(new Blob([blob]))
+ const link = document.createElement('a')
+ link.href = url
+ link.setAttribute('download', filename)
+ document.body.appendChild(link)
+ link.click()
+ link.parentNode?.removeChild(link)
+ })
+ }
+ return { download }
+}
\ No newline at end of file
diff --git a/composables/useFileGo.ts b/composables/useFileGo.ts
index ec56618..19cbbea 100644
--- a/composables/useFileGo.ts
+++ b/composables/useFileGo.ts
@@ -1,4 +1,4 @@
-import {useFetchWrapped} from '~/composables/useFetchWrapped';
+import { useFetchWrapped } from '~/composables/useFetchWrapped'
const putOSS = (file: File, signed_url: string) => new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest()
@@ -16,17 +16,17 @@ const putOSS = (file: File, signed_url: string) => new Promise((resolve, r
})
export const useFileGo = (file: File) => new Promise((resolve, reject) => {
- useFetchWrapped('App.Tools_Upload.GoOss', {
+ useFetchWrapped>('App.Tools_Upload.UploadOssMaterial', {
token: useLoginState().token!,
user_id: useLoginState().user.id,
file_name: file.name,
file_type: file.type,
file_size: file.size,
}).then(async res => {
- if (res !== '') {
+ if (res.data !== '') {
try {
- await putOSS(file, res)
- let url = res.split('?')[0]
+ await putOSS(file, res.data)
+ let url = res.data.split('?')[0]
resolve(url)
} catch (err) {
reject(err)