|
|
@@ -0,0 +1,41 @@
|
|
|
+import { Component } from '@angular/core';
|
|
|
+import { NgForm } from '@angular/forms';
|
|
|
+import { TracksApiService } from 'src/app/tracks-api.service';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-create-track-page',
|
|
|
+ templateUrl: './create-track-page.component.html',
|
|
|
+ styleUrls: ['./create-track-page.component.scss']
|
|
|
+})
|
|
|
+export class CreateTrackPageComponent {
|
|
|
+ public fileName: string = '';
|
|
|
+
|
|
|
+ public constructor(
|
|
|
+ private readonly tracksApi: TracksApiService
|
|
|
+ ) { }
|
|
|
+
|
|
|
+ public onFileChange(event: Event): void {
|
|
|
+ const element = event.currentTarget as HTMLInputElement;
|
|
|
+ let fileList: FileList | null = element.files;
|
|
|
+ if (fileList) {
|
|
|
+ this.fileName = fileList.item(0)?.name || '';
|
|
|
+ const extIndex = this.fileName.lastIndexOf('.');
|
|
|
+ if (extIndex > 0) {
|
|
|
+ this.fileName = this.fileName.substring(0, extIndex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public uploadFile(event: SubmitEvent, form: NgForm): void {
|
|
|
+
|
|
|
+ const file: File | undefined = ((event.target as HTMLFormElement).elements.namedItem('trackFile') as HTMLInputElement).files?.[0];
|
|
|
+
|
|
|
+ if (file) {
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append("file", file);
|
|
|
+ formData.append("name", form.value.fileName);
|
|
|
+
|
|
|
+ this.tracksApi.createTrack(formData).then(track => console.log('created track', track));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|