@@ -6,10 +6,13 @@ import { globalCapture, selectedADir, selectedMusic } from "@/store/refs";
66import { MusicXmlWithABJacket } from "@/client/apiGen" ;
77import { useI18n } from 'vue-i18n' ;
88
9+ export let upload = async ( fileHandle ?: FileSystemFileHandle ) => {
10+ }
11+
912export default defineComponent ( {
1013 props : {
11- info : { type : Object as PropType < MusicXmlWithABJacket > , required : true } ,
12- upload : { type : Boolean , default : true }
14+ info : { type : Object as PropType < MusicXmlWithABJacket > , required : true } ,
15+ upload : { type : Boolean , default : true }
1316 } ,
1417 setup ( props ) {
1518 const dialog = useDialog ( ) ;
@@ -18,47 +21,49 @@ export default defineComponent({
1821 getUrl ( `GetJacketApi/${ props . info . assetDir } /${ props . info . id } ?${ updateTime . value } ` ) : noJacket )
1922 const { t } = useI18n ( ) ;
2023
21- const upload = async ( ) => {
22- if ( ! props . upload ) return ;
23- try {
24- const [ fileHandle ] = await window . showOpenFilePicker ( {
25- id : 'jacket' ,
26- startIn : 'downloads' ,
27- types : [
28- {
29- description : t ( 'genre.imageDescription' ) ,
30- accept : {
31- "application/jpeg" : [ ".jpeg" , ".jpg" ] ,
32- "application/png" : [ ".png" ] ,
33- } ,
34- } ,
35- ] ,
36- } ) ;
37-
38- if ( ! fileHandle ) return ;
39- const file = await fileHandle . getFile ( ) ;
24+ if ( props . upload )
25+ upload = async ( fileHandle ?: FileSystemFileHandle ) => {
26+ if ( ! props . upload ) return ;
27+ try {
28+ if ( ! fileHandle ) {
29+ [ fileHandle ] = await window . showOpenFilePicker ( {
30+ id : 'jacket' ,
31+ startIn : 'downloads' ,
32+ types : [
33+ {
34+ description : t ( 'genre.imageDescription' ) ,
35+ accept : {
36+ "application/jpeg" : [ ".jpeg" , ".jpg" ] ,
37+ "application/png" : [ ".png" ] ,
38+ } ,
39+ } ,
40+ ] ,
41+ } ) ;
42+ }
43+ if ( ! fileHandle ) return ;
44+ const file = await fileHandle . getFile ( ) ;
4045
41- const res = await api . SetMusicJacket ( props . info . id ! , selectedADir . value , { file} ) ;
42- if ( res . error ) {
43- const error = res . error as any ;
44- dialog . warning ( { title : t ( 'jacket.setFailed' ) , content : error . message || error } ) ;
45- return ;
46- }
47- if ( res . data ) {
48- dialog . info ( { title : t ( 'jacket.setFailed' ) , content : res . data } )
49- return ;
46+ const res = await api . SetMusicJacket ( props . info . id ! , selectedADir . value , { file } ) ;
47+ if ( res . error ) {
48+ const error = res . error as any ;
49+ dialog . warning ( { title : t ( 'jacket.setFailed' ) , content : error . message || error } ) ;
50+ return ;
51+ }
52+ if ( res . data ) {
53+ dialog . info ( { title : t ( 'jacket.setFailed' ) , content : res . data } )
54+ return ;
55+ }
56+ updateTime . value = Date . now ( )
57+ props . info . hasJacket = true ;
58+ selectedMusic . value ! . hasJacket = true ;
59+ ( selectedMusic . value as any ) . updateTime = updateTime . value
60+ } catch ( e : any ) {
61+ if ( e . name === 'AbortError' ) return
62+ console . log ( e )
63+ globalCapture ( e , t ( 'jacket.replaceFailed' ) )
5064 }
51- updateTime . value = Date . now ( )
52- props . info . hasJacket = true ;
53- selectedMusic . value ! . hasJacket = true ;
54- ( selectedMusic . value as any ) . updateTime = updateTime . value
55- } catch ( e : any ) {
56- if ( e . name === 'AbortError' ) return
57- console . log ( e )
58- globalCapture ( e , t ( 'jacket.replaceFailed' ) )
5965 }
60- }
6166
62- return ( ) => < img src = { jacketUrl . value } class = { `object-fill rounded-lg ${ props . upload && 'cursor-pointer' } ` } onClick = { upload } />
67+ return ( ) => < img src = { jacketUrl . value } class = { `object-fill rounded-lg ${ props . upload && 'cursor-pointer' } ` } onClick = { ( ) => upload ( ) } />
6368 }
6469} )
0 commit comments