12 changed files with 179 additions and 33 deletions
@ -0,0 +1,22 @@ |
|||||
|
<h2 mat-dialog-title>{{status.done?"Файл успешно преобразован":"Подождите, перекодировка файла"}}</h2> |
||||
|
<mat-dialog-content> |
||||
|
<mat-spinner *ngIf="loading"></mat-spinner> |
||||
|
<ng-container *ngIf="!loading && !status.done"> |
||||
|
<p>Прогресс загрузки h264x {{status.h264}} %</p> |
||||
|
<mat-progress-bar [mode]="'determinate'" [value]="status.h264"></mat-progress-bar> |
||||
|
<p>Прогресс загрузки avi {{status.avi}} %</p> |
||||
|
<mat-progress-bar [mode]="'determinate'" [value]="status.avi"></mat-progress-bar> |
||||
|
<p>Прогресс загрузки avi {{status.mp4}} %</p> |
||||
|
<mat-progress-bar [mode]="'determinate'" [value]="status.mp4"></mat-progress-bar> |
||||
|
</ng-container> |
||||
|
<ng-container *ngIf="!loading && status.done"> |
||||
|
<video controls> |
||||
|
<source [src]="'api/transcode/download?b64=' + status.b64" type="video/mp4"/> |
||||
|
</video> |
||||
|
<br> |
||||
|
<a [href]="'api/transcode/download?b64=' + status.b64">Скачать MP4 ({{baseUtils.getFancySize(status.outSize)}})</a> |
||||
|
</ng-container> |
||||
|
</mat-dialog-content> |
||||
|
<mat-dialog-actions> |
||||
|
<button mat-button (click)="close()">Закрыть</button> |
||||
|
</mat-dialog-actions> |
@ -0,0 +1,23 @@ |
|||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
||||
|
|
||||
|
import { TranscodeModalComponent } from './transcode-modal.component'; |
||||
|
|
||||
|
describe('TranscodeModalComponent', () => { |
||||
|
let component: TranscodeModalComponent; |
||||
|
let fixture: ComponentFixture<TranscodeModalComponent>; |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
await TestBed.configureTestingModule({ |
||||
|
declarations: [ TranscodeModalComponent ] |
||||
|
}) |
||||
|
.compileComponents(); |
||||
|
|
||||
|
fixture = TestBed.createComponent(TranscodeModalComponent); |
||||
|
component = fixture.componentInstance; |
||||
|
fixture.detectChanges(); |
||||
|
}); |
||||
|
|
||||
|
it('should create', () => { |
||||
|
expect(component).toBeTruthy(); |
||||
|
}); |
||||
|
}); |
@ -0,0 +1,49 @@ |
|||||
|
import {Component, Inject, OnInit} from '@angular/core'; |
||||
|
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; |
||||
|
import {HttpClient} from "@angular/common/http"; |
||||
|
import {IBackendResponse} from "../../entities/IBackendResponse"; |
||||
|
import {TranscodeStatus} from "../../entities/TranscodeStatus"; |
||||
|
import {BaseUtils} from "../../utils/BaseUtils"; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'app-transcode-modal', |
||||
|
templateUrl: './transcode-modal.component.html', |
||||
|
styleUrls: ['./transcode-modal.component.css'], |
||||
|
}) |
||||
|
export class TranscodeModalComponent implements OnInit { |
||||
|
|
||||
|
status: TranscodeStatus = new TranscodeStatus(); |
||||
|
interval:any; |
||||
|
loading:boolean = true; |
||||
|
baseUtils = BaseUtils; |
||||
|
|
||||
|
constructor( |
||||
|
private dialogRef: MatDialogRef<TranscodeModalComponent>, |
||||
|
@Inject(MAT_DIALOG_DATA) private data:{b64:string, recorder_index:number}, |
||||
|
private client: HttpClient |
||||
|
) { } |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
console.log(this.data); |
||||
|
this.interval = setInterval(() => { |
||||
|
this.getStatus() |
||||
|
}, 1000); |
||||
|
} |
||||
|
|
||||
|
close():void { |
||||
|
clearInterval(this.interval); |
||||
|
this.dialogRef.close(); |
||||
|
} |
||||
|
|
||||
|
getStatus() { |
||||
|
this.client.get(`api/transcode/status/${this.data.recorder_index}?b64=${this.data.b64}`) |
||||
|
.subscribe((data:any) => { |
||||
|
this.status = new TranscodeStatus().fromData(data["data"]); |
||||
|
this.loading = false; |
||||
|
if (this.status.done) |
||||
|
clearInterval(this.interval); |
||||
|
console.log(this.status); |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
export interface IBackendResponse { |
||||
|
ok:boolean, |
||||
|
data:any, |
||||
|
error:any|null |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
export class TranscodeStatus { |
||||
|
b64:string = ""; |
||||
|
uuid:string = ""; |
||||
|
h264:number = 0; |
||||
|
downloaded_h264_bytes:number = 0; |
||||
|
total_h264_bytes:number = 0; |
||||
|
avi:number = 0; |
||||
|
mp4:number = 0; |
||||
|
outFile:string|null = null; |
||||
|
done:boolean = false; |
||||
|
outSize:number = 0; |
||||
|
|
||||
|
fromData(data:any):TranscodeStatus { |
||||
|
this.b64 = data["b64"]; |
||||
|
this.uuid = data["uuid"]; |
||||
|
this.h264 = data["h264"]; |
||||
|
this.downloaded_h264_bytes = data["downloaded_h264_bytes"]; |
||||
|
this.total_h264_bytes = data["total_h264_bytes"]; |
||||
|
this.avi = data["avi"]; |
||||
|
this.mp4 = data["mp4"]; |
||||
|
this.outFile = data["outFile"]; |
||||
|
this.done = data["done"]; |
||||
|
this.outSize = data["outSize"]; |
||||
|
return this; |
||||
|
} |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
export class BaseUtils { |
||||
|
static getFancySize(size:number):string { |
||||
|
if (size > 1024*1024*1024) return `${Math.round(size / 1024/1024/1024)} Гб`; |
||||
|
if (size > 1024*1024) return `${Math.round(size / 1024/1024)} Мб`; |
||||
|
if (size > 1024) return `${Math.round(size / 1024)} Кб`; |
||||
|
return `${size} Б` |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue