mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-29 19:56:09 +01:00
36 lines
877 B
JavaScript
36 lines
877 B
JavaScript
import rxjs from "../../lib/rx.js";
|
|
import ajax from "../../lib/ajax.js";
|
|
|
|
const isSaving$ = new rxjs.BehaviorSubject(false);
|
|
|
|
const config$ = isSaving$.pipe(
|
|
rxjs.filter((loading) => !loading),
|
|
rxjs.switchMapTo(ajax({
|
|
url: "/admin/api/config",
|
|
method: "GET",
|
|
responseType: "json"
|
|
})),
|
|
rxjs.map((res) => res.responseJSON.result),
|
|
rxjs.shareReplay(1),
|
|
)
|
|
|
|
export function isSaving() {
|
|
return isSaving$.asObservable();
|
|
}
|
|
|
|
export function get() {
|
|
return config$;
|
|
}
|
|
|
|
export function save() {
|
|
return rxjs.pipe(
|
|
rxjs.tap(() => isSaving$.next(true)),
|
|
rxjs.debounceTime(2000),
|
|
rxjs.mergeMap((formData) => ajax({
|
|
url: "/admin/api/config",
|
|
method: "POST",
|
|
responseType: "json",
|
|
body: formData,
|
|
}).pipe(rxjs.tap(() => isSaving$.next(false)))),
|
|
);
|
|
}
|