@@ -117,29 +117,8 @@ class ShareService {
117117 // 处理图片和DataViews媒体资源
118118 const data = resp . data
119119
120- // 处理常规媒体资源
121- const media = data . media
122- if ( media && media . length > 0 ) {
123- showMessage ( this . pluginInstance . i18n [ "shareService" ] [ "msgProcessPic" ] , 7000 , "info" )
124- // 异步处理图片
125- this . addLog ( this . pluginInstance . i18n [ "shareService" ] [ "msgStartPicBack" ] , "info" )
126- void this . processShareMedia ( docId , media )
127- this . addLog ( this . pluginInstance . i18n [ "shareService" ] [ "msgEndPicBack" ] , "info" )
128- }
129-
130- // 处理数据库媒体资源
131- const dataViewMedia = data . dataViewMedia
132- if ( dataViewMedia && dataViewMedia . length > 0 ) {
133- showMessage ( this . pluginInstance . i18n [ "shareService" ] [ "msgProcessPic" ] , 7000 , "info" )
134- // 异步处理数据库媒体资源
135- this . addLog ( this . pluginInstance . i18n [ "shareService" ] [ "msgStartDataViewMediaBack" ] , "info" )
136- void this . processDataViewMedia ( docId , dataViewMedia )
137- this . addLog ( this . pluginInstance . i18n [ "shareService" ] [ "msgEndDataViewMediaBack" ] , "info" )
138- }
139-
140- if ( ! media || media . length === 0 ) {
141- showMessage ( this . pluginInstance . i18n [ "shareService" ] [ "msgShareSuccess" ] , 3000 , "info" )
142- }
120+ // 异步处理所有媒体资源,确保按顺序执行
121+ void this . processAllMediaResources ( docId , data . media , data . dataViewMedia )
143122 } catch ( e ) {
144123 const exceptionMsg = this . pluginInstance . i18n [ "shareService" ] [ "shareErrorWithDoc" ] . replace ( "[param1]" , docId ) + e
145124 this . addLog ( exceptionMsg , "error" )
@@ -510,6 +489,34 @@ class ShareService {
510489 }
511490 }
512491
492+ /**
493+ * 顺序处理所有媒体资源,先处理常规媒体资源,再处理DataViews媒体资源
494+ * 避免并发执行导致的后端处理混乱
495+ */
496+ private async processAllMediaResources ( docId : string , media : any [ ] , dataViewMedia : any [ ] ) {
497+ // 先处理常规媒体资源
498+ if ( media && media . length > 0 ) {
499+ showMessage ( this . pluginInstance . i18n [ "shareService" ] [ "msgProcessPic" ] , 7000 , "info" )
500+ this . addLog ( this . pluginInstance . i18n [ "shareService" ] [ "msgStartPicBack" ] , "info" )
501+ await this . processShareMedia ( docId , media )
502+ this . addLog ( this . pluginInstance . i18n [ "shareService" ] [ "msgEndPicBack" ] , "info" )
503+ }
504+
505+ // 再处理DataViews媒体资源
506+ if ( dataViewMedia && dataViewMedia . length > 0 ) {
507+ showMessage ( this . pluginInstance . i18n [ "shareService" ] [ "msgProcessPic" ] , 7000 , "info" )
508+ this . addLog ( this . pluginInstance . i18n [ "shareService" ] [ "msgStartDataViewMediaBack" ] , "info" )
509+ await this . processDataViewMedia ( docId , dataViewMedia )
510+ this . addLog ( this . pluginInstance . i18n [ "shareService" ] [ "msgEndDataViewMediaBack" ] , "info" )
511+ }
512+
513+ // 只有在没有媒体资源的情况下显示分享成功消息
514+ // 如果有媒体资源,成功消息会在各自的处理方法中显示
515+ if ( ( ! media || media . length === 0 ) && ( ! dataViewMedia || dataViewMedia . length === 0 ) ) {
516+ showMessage ( this . pluginInstance . i18n [ "shareService" ] [ "msgShareSuccess" ] , 3000 , "info" )
517+ }
518+ }
519+
513520 private addLog ( msg : string , type : "info" | "error" ) {
514521 updateStatusBar ( this . pluginInstance , msg )
515522 if ( type === "info" ) {
0 commit comments