办学质量监测教学评价系统
康鲁杰
8 天以前 3041043370ee9dbbd7917b7843f4c72c03081e5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<script setup lang="ts">
import { mlog } from "@/api";
import { FeedTask, sleep, sunoFetch } from "@/api/suno";
import {NTag} from   "naive-ui";
import { ref } from "vue";
 
const fsRef= ref()
const st = ref({process:'',id:'',isUpload:false});
 
const  uploadFetch= async ( lid:string)=>{
    for(let i=0;i<50;i++){
        let dt:any = await sunoFetch(`/uploads/audio/${lid}`);
        mlog("ddd",dt )
        let time= (i+1)
        if(time>20) time=20;
        if( dt.status=='complete' || dt.status=='error' ) return dt ;
        await sleep( time*1000 )
        
    }
    return null;
   
}
async function  selectFile(input:any){
    try{
        st.value.isUpload= true
        mlog("uploadFile", input.target.files[0] )
        const d:any = await sunoFetch('/uploads/audio',{"extension":"mp3"})
        mlog("init ", d )
        st.value.id= d.id;
        const formData = new FormData();
        for(let p in d.fields){
            formData.append( p,d.fields[p] )
        }
        formData.append('file', input.target.files[0])
        const response = await fetch(d.url , { method: 'POST',   body: formData });
        if (!response.ok) {
        throw new Error('Network response was not ok');
        }
        mlog("uploaded ")
        const f:any = await sunoFetch('/uploads/audio/'+ d.id+'/upload-finish',{"upload_type":"file_upload","upload_filename": input.target.files[0].name })
        mlog("finish ", f )
 
        const fd:any= await uploadFetch(d.id )
        mlog("uploadFetch ", fd  )
        const ft:any = await sunoFetch('/uploads/audio/'+ d.id+'/initialize-clip',{ })
        mlog("clip ", ft )
 
        //到这里拿到 就可以结束了
        FeedTask( [ ft.clip_id])
    }catch(e ){
 
    }
    st.value.isUpload= false
    fsRef.value.value='';
 
}
</script>
<template>
    <NTag   type="info" size="small" round  :bordered="false">
        <span class="cursor-pointer"   v-if="st.isUpload">Upload...</span>
        <span class="cursor-pointer" @click="fsRef.click()" v-else>{{ $t('suno.upMps') }}</span>
    </NTag>
    
    <input type="file"  @change="selectFile"  ref="fsRef" style="display: none" accept=".mp3" />
 
</template>