@@ -120,6 +120,67 @@ export class ElementsPartsComponent implements OnInit {
120
120
return result . trim ( ) ;
121
121
}
122
122
123
+ /**
124
+ * 获取录像源的逻辑
125
+ *
126
+ * @param item
127
+ * @param sessionId
128
+ * @param isFirstPush
129
+ */
130
+ async fetchSection ( item : IFile , sessionId : string , isFirstPush : boolean ) : Promise < boolean > {
131
+ let section : Section ;
132
+ try {
133
+ const res : Replay = await this . _http . getPartFileReplay ( sessionId , item . name ) . toPromise ( ) ;
134
+
135
+ if ( res ) {
136
+ // 3.5 的 TS 版本无法使用 ?.
137
+ // @ts -ignore
138
+ const data = res . type ? res : ( res . resp ? res . resp . data : undefined ) ;
139
+
140
+ if ( data && data . src && res . status !== 'running' ) {
141
+ section = {
142
+ id : this . id ,
143
+ account : data . account ,
144
+ asset : data . asset ,
145
+ date_end : data . date_end ,
146
+ date_start : data . date_start ,
147
+ download_url : data . download_url ,
148
+ src : data . src ,
149
+ type : data . type ,
150
+ user : data . user ,
151
+ size : this . formatFileSize ( item . size ) ,
152
+ name : `Part ${ this . folders . length + 1 } ` ,
153
+ updated : this . formatDuration ( item . duration ) ,
154
+ } ;
155
+
156
+ this . folders . push ( section ) ;
157
+
158
+ if ( isFirstPush && section . src ) {
159
+ this . currentVideo = section ;
160
+ this . videoLoading = true ;
161
+ this . cdRef . detectChanges ( ) ;
162
+
163
+ setTimeout ( ( ) => {
164
+ this . videoLoading = false ;
165
+ } , 300 ) ;
166
+
167
+ return false ;
168
+ }
169
+
170
+ } else if ( res && res . status === 'running' ) {
171
+ this . alertShown = true ;
172
+ await this . delay ( 3000 ) ;
173
+ return await this . fetchSection ( item , sessionId , isFirstPush ) ;
174
+ }
175
+ }
176
+ } catch ( e ) {
177
+ this . _logger . error ( e ) ;
178
+ } finally {
179
+ this . alertShown = false ;
180
+ }
181
+ return isFirstPush ;
182
+ }
183
+
123
184
/**
124
185
* 分割 File 对象
125
186
* @param file
@@ -129,57 +190,7 @@ export class ElementsPartsComponent implements OnInit {
129
190
let isFirstPush = true ;
130
191
131
192
for ( const item of file ) {
132
- let res : Replay ;
133
- let retry = true ;
134
-
135
- while ( retry ) {
136
- try {
137
- res = await this . _http
138
- . getPartFileReplay ( sessionId , item . name )
139
- . toPromise ( ) ;
140
-
141
- if ( res && res . status !== 'running' ) {
142
- const section : Section = {
143
- id : this . id ,
144
- account : res . account ,
145
- asset : res . asset ,
146
- date_end : res . date_end ,
147
- date_start : res . date_start ,
148
- download_url : res . download_url ,
149
- src : res . src ,
150
- type : res . type ,
151
- user : res . user ,
152
- size : this . formatFileSize ( item . size ) ,
153
- name : `Part ${ this . folders . length + 1 } ` ,
154
- updated : this . formatDuration ( item . duration ) ,
155
- } ;
156
-
157
- this . folders . push ( section ) ;
158
-
159
- if ( isFirstPush ) {
160
- this . currentVideo = section ;
161
- this . videoLoading = true ;
162
- this . cdRef . detectChanges ( ) ;
163
-
164
- setTimeout ( ( ) => {
165
- this . videoLoading = false ;
166
- } , 300 ) ;
167
-
168
- isFirstPush = false ;
169
- }
170
-
171
- retry = false ;
172
- } else if ( res && res . status === 'running' ) {
173
- this . alertShown = true ;
174
- await this . delay ( 3000 ) ;
175
- }
176
- } catch ( e ) {
177
- this . _logger . error ( e ) ;
178
- retry = false ;
179
- } finally {
180
- this . alertShown = false ;
181
- }
182
- }
193
+ isFirstPush = await this . fetchSection ( item , sessionId , isFirstPush ) ;
183
194
}
184
195
}
185
196
0 commit comments