This commit is contained in:
2025-04-15 00:52:23 +08:00
parent b76a685988
commit c7763227d0
24 changed files with 748 additions and 384 deletions

View File

@ -1,6 +1,4 @@
/* eslint-disable max-classes-per-file */
/* eslint-disable import/prefer-default-export */
import { WebDAVClient } from "webdav/web";
import { WebDAVClient } from "webdav";
import { FileReader, FileWriter } from "../filesystem";
export class WebDAVFileReader implements FileReader {
@ -42,10 +40,7 @@ export class WebDAVFileWriter implements FileWriter {
async write(content: string | Blob): Promise<void> {
let resp;
if (content instanceof Blob) {
resp = await this.client.putFileContents(
this.path,
await content.arrayBuffer()
);
resp = await this.client.putFileContents(this.path, await content.arrayBuffer());
} else {
resp = await this.client.putFileContents(this.path, content);
}

View File

@ -1,4 +1,4 @@
import { AuthType, createClient, FileStat, WebDAVClient } from "webdav/web";
import { AuthType, createClient, FileStat, WebDAVClient } from "webdav";
import FileSystem, { File, FileReader, FileWriter } from "../filesystem";
import { joinPath } from "../utils";
import { WebDAVFileReader, WebDAVFileWriter } from "./rw";
@ -11,12 +11,7 @@ export default class WebDAVFileSystem implements FileSystem {
basePath: string = "/";
constructor(
authType: AuthType | WebDAVClient,
url?: string,
username?: string,
password?: string
) {
constructor(authType: AuthType | WebDAVClient, url?: string, username?: string, password?: string) {
if (typeof authType === "object") {
this.client = authType;
this.basePath = joinPath(url || "");
@ -44,28 +39,20 @@ export default class WebDAVFileSystem implements FileSystem {
}
open(file: File): Promise<FileReader> {
return Promise.resolve(
new WebDAVFileReader(this.client, joinPath(file.path, file.name))
);
return Promise.resolve(new WebDAVFileReader(this.client, joinPath(file.path, file.name)));
}
openDir(path: string): Promise<FileSystem> {
return Promise.resolve(
new WebDAVFileSystem(this.client, joinPath(this.basePath, path), this.url)
);
return Promise.resolve(new WebDAVFileSystem(this.client, joinPath(this.basePath, path), this.url));
}
create(path: string): Promise<FileWriter> {
return Promise.resolve(
new WebDAVFileWriter(this.client, joinPath(this.basePath, path))
);
return Promise.resolve(new WebDAVFileWriter(this.client, joinPath(this.basePath, path)));
}
async createDir(path: string): Promise<void> {
try {
return Promise.resolve(
await this.client.createDirectory(joinPath(this.basePath, path))
);
return Promise.resolve(await this.client.createDirectory(joinPath(this.basePath, path)));
} catch (e: any) {
// 如果是405错误,则忽略
if (e.message.includes("405")) {
@ -80,9 +67,7 @@ export default class WebDAVFileSystem implements FileSystem {
}
async list(): Promise<File[]> {
const dir = (await this.client.getDirectoryContents(
this.basePath
)) as FileStat[];
const dir = (await this.client.getDirectoryContents(this.basePath)) as FileStat[];
const ret: File[] = [];
dir.forEach((item: FileStat) => {
if (item.type !== "file") {