Files
Picsur/frontend/src/app/routes/processing/processing.component.ts

34 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-02-28 21:09:27 +01:00
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
2022-02-28 23:18:07 +01:00
import { HasFailed } from 'picsur-shared/dist/types';
2022-03-06 12:34:33 +01:00
import { ProcessingViewMetadata } from 'src/app/models/processing-view-metadata';
2022-03-16 15:59:06 +01:00
import { ImageService } from 'src/app/services/api/image.service';
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',
})
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
}
}