|
|
@@ -8,24 +8,10 @@ import { TracksApiService } from 'src/app/tracks-api.service';
|
|
|
styleUrls: ['./track-create.component.scss']
|
|
|
})
|
|
|
export class TrackCreateComponent {
|
|
|
- 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];
|
|
|
@@ -33,7 +19,6 @@ export class TrackCreateComponent {
|
|
|
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));
|
|
|
form.resetForm();
|