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

32 lines
988 B
TypeScript
Raw Normal View History

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-02-28 21:09:27 +01:00
@Component({
templateUrl: './processing.component.html',
styleUrls: ['./processing.component.scss'],
})
export class ProcessingComponent implements OnInit {
2022-02-28 23:18:07 +01:00
constructor(private router: Router, private imageService: ImageService) {}
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) {
this.router.navigate(['/'], { replaceUrl: true });
return;
}
2022-02-28 23:18:07 +01:00
history.replaceState(null, '');
const hash = await this.imageService.UploadImage(state.imageFile);
if (HasFailed(hash)) {
this.router.navigate(['/'], { replaceUrl: true });
return;
}
this.router.navigate([`/view/`, hash], { replaceUrl: true });
2022-02-28 21:09:27 +01:00
}
}