Archived
Private
Public Access
1
0
This repository has been archived on 2026-02-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
BetterIServ/BetterIServ.Mobile/src/app/api/webdav.service.ts
2023-04-16 14:28:34 +02:00

53 lines
2.0 KiB
TypeScript

import {Injectable} from '@angular/core';
import {IServService} from "./iserv.service";
import {HttpClient, HttpEvent} from "@angular/common/http";
import {DirectoryContent} from "../entities/directoryContent";
import {firstValueFrom, Observable} from "rxjs";
@Injectable({
providedIn: 'root'
})
export class WebdavService {
constructor(private iserv: IServService, private client: HttpClient) {}
public async getDirectory(path: string): Promise<DirectoryContent[]> {
const contents = await firstValueFrom(this.client.post<DirectoryContent[]>(this.iserv.backend + "/webdav/content?dir=" + path, this.iserv.userdata));
for (let content of contents) {
content.name = decodeURIComponent(content.name);
content.url = decodeURI(content.url);
content.lastModified = new Date(content.lastModified);
}
return contents;
}
public downloadFile(url: string): Observable<HttpEvent<Blob>> {
return this.client.post(this.iserv.backend + "/webdav/download?url=" + url, this.iserv.userdata, {responseType: "blob", reportProgress: true, observe: "events"});
}
public async delete(url: string) {
await firstValueFrom(this.client.post(this.iserv.backend + "/webdav/delete?url=" + url, this.iserv.userdata));
}
public uploadFile(url: string, file: File): Observable<HttpEvent<any>> {
const form = new FormData();
form.append('username', this.iserv.userdata.username);
form.append('password', this.iserv.userdata.password);
form.append('domain', this.iserv.userdata.domain);
form.append('file', file);
return this.client.post(this.iserv.backend + "/webdav/upload?url=" + url, form, {reportProgress: true, observe: "events"});
}
public async createFolder(url: string) {
await firstValueFrom(this.client.post(this.iserv.backend + "/webdav/create/?url=" + url, this.iserv.userdata));
}
public async moveElement(url: string, newUrl: string) {
await firstValueFrom(this.client.post(this.iserv.backend + `/webdav/move/?url=${url}&newUrl=${newUrl}`, this.iserv.userdata));
}
}