integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { FileOptions, PreviewResponse, SourceType } from './api.types';
|
||||
|
||||
/** Previews of uploaded files: multipart for one file, JSON payload for any source. */
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class FileSourceApi {
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
preview(file: File, kind: SourceType, target: string | null, options: FileOptions = {}): Observable<PreviewResponse> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
form.append('source_kind', kind);
|
||||
if (target) form.append('target', target);
|
||||
if (Object.keys(options).length > 0) form.append('options', JSON.stringify(options));
|
||||
return this.http.post<PreviewResponse>('/imports/sources/file/preview', form);
|
||||
}
|
||||
|
||||
/** Same payload an import source carries, e.g. several EDF files at once. */
|
||||
previewPayload(kind: SourceType, payload: Record<string, unknown>, target: string | null): Observable<PreviewResponse> {
|
||||
return this.http.post<PreviewResponse>(`/imports/sources/${kind}/preview`, { payload, ...(target ? { target } : {}) });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user