2022-02-28 21:09:27 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
import { ProcessingViewMetadata } from 'src/app/models/processing-view-metadata';
|
2022-02-28 23:18:07 +01:00
|
|
|
import { ImageService } from 'src/app/api/image.service';
|
|
|
|
|
import { HasFailed } from 'picsur-shared/dist/types';
|
2022-03-01 21:51:21 +01:00
|
|
|
import { UtilService } from 'src/app/util/util.service';
|
2022-02-28 21:09:27 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
templateUrl: './processing.component.html',
|
|
|
|
|
styleUrls: ['./processing.component.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class ProcessingComponent implements OnInit {
|
2022-03-01 21:51:21 +01:00
|
|
|
constructor(
|
|
|
|
|
private router: Router,
|
|
|
|
|
private imageService: ImageService,
|
|
|
|
|
private utilService: UtilService
|
|
|
|
|
) {}
|
2022-02-28 21:09:27 +01:00
|
|
|
|
2022-02-28 23:18:07 +01:00
|
|
|
async ngOnInit() {
|
2022-02-28 21:09:27 +01:00
|
|
|
const state = history.state as ProcessingViewMetadata;
|
|
|
|
|
if (!state) {
|
2022-03-01 21:51:21 +01:00
|
|
|
return this.utilService.quitError('Error');
|
2022-02-28 21:09:27 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-28 23:18:07 +01:00
|
|
|
history.replaceState(null, '');
|
|
|
|
|
|
|
|
|
|
const hash = await this.imageService.UploadImage(state.imageFile);
|
|
|
|
|
if (HasFailed(hash)) {
|
2022-03-01 21:51:21 +01:00
|
|
|
return this.utilService.quitError(hash.getReason());
|
2022-02-28 23:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.router.navigate([`/view/`, hash], { replaceUrl: true });
|
2022-02-28 21:09:27 +01:00
|
|
|
}
|
|
|
|
|
}
|