Skip to content

Commit 940d592

Browse files
authored
Merge pull request #1174 from jumpserver/dev
v4.3.0
2 parents 81e3fad + 1fd2588 commit 940d592

File tree

3 files changed

+64
-52
lines changed

3 files changed

+64
-52
lines changed

src/app/elements/replay/parts/parts.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<div class="loading-spinner">
3838
<mat-spinner *ngIf="videoLoading"></mat-spinner>
3939
</div>
40-
<elements-replay-guacamole class='guacamole-video' [replay]="currentVideo" *ngIf="currentVideo"></elements-replay-guacamole>
40+
<elements-replay-guacamole class='guacamole-video' [replay]="currentVideo" *ngIf="currentVideo && currentVideo.src"></elements-replay-guacamole>
4141
</mat-card>
4242
</div>
4343
<mat-card class="video-list">

src/app/elements/replay/parts/parts.component.ts

+62-51
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,67 @@ export class ElementsPartsComponent implements OnInit {
120120
return result.trim();
121121
}
122122

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+
123184
/**
124185
* 分割 File 对象
125186
* @param file
@@ -129,57 +190,7 @@ export class ElementsPartsComponent implements OnInit {
129190
let isFirstPush = true;
130191

131192
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);
183194
}
184195
}
185196

src/app/utils/common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export function connectOnNewPage(node: TreeNode, newWindowMode?: string) {
303303
count = 0;
304304
}
305305
let left = 100 + count * 100;
306+
top = 50 + count * 50;
306307
if (left + screen.width / 3 > screen.width) {
307308
// 支持两排足以
308309
top = screen.height / 3;

0 commit comments

Comments
 (0)