Files
wgenerator/src/app/modules/songs/services/file.service.ts
benjamin 5efd44e710
Some checks failed
Angular Build / build (push) Has been cancelled
fix bundle size
2026-03-20 19:43:50 +01:00

29 lines
1.1 KiB
TypeScript

import {EnvironmentInjector, inject, Injectable, runInInjectionContext} from '@angular/core';
import {deleteObject, getDownloadURL, ref, Storage} from '@angular/fire/storage';
import {from, Observable} from 'rxjs';
import {FileDataService} from './file-data.service';
@Injectable()
export class FileService {
private storage = inject(Storage);
private fileDataService = inject(FileDataService);
private environmentInjector = inject(EnvironmentInjector);
public getDownloadUrl(path: string): Observable<string> {
return from(runInInjectionContext(this.environmentInjector, () => this.resolveDownloadUrl(path)));
}
public delete(path: string, songId: string, fileId: string): void {
void runInInjectionContext(this.environmentInjector, () => this.deleteFromStorage(path));
void this.fileDataService.delete(songId, fileId);
}
private resolveDownloadUrl(path: string): Promise<string> {
return getDownloadURL(ref(this.storage, path));
}
private deleteFromStorage(path: string): Promise<void> {
return deleteObject(ref(this.storage, path));
}
}