|
3 | 3 | * |
4 | 4 | * Testing with server implemented by https://github.com/svtslv/webdav-cli |
5 | 5 | */ |
6 | | -import { encode } from 'js-base64' |
| 6 | +import { encode } from '@util/base64' |
7 | 7 | import { fetchDelete, fetchGet } from './http' |
8 | 8 |
|
9 | 9 | // Only support password for now |
@@ -49,12 +49,23 @@ export async function judgeDirExist(context: WebDAVContext, dirPath: string): Pr |
49 | 49 | } |
50 | 50 | } |
51 | 51 |
|
52 | | -export async function makeDir(context: WebDAVContext, dirPath: string) { |
| 52 | +export async function makeDirs(context: WebDAVContext, dirPath: string) { |
| 53 | + const normalizedPath = dirPath.startsWith('/') ? dirPath.slice(1) : dirPath |
| 54 | + const pathSegments = normalizedPath.split('/').filter(segment => segment.length > 0) |
| 55 | + |
53 | 56 | const { auth, endpoint } = context || {} |
54 | | - const url = `${endpoint}/${dirPath}` |
55 | | - const headers = authHeaders(auth) |
56 | | - const response = await fetch(url, { method: 'MKCOL', headers }) |
57 | | - handleWriteResponse(response) |
| 57 | + |
| 58 | + for (let i = 0; i < pathSegments.length; i++) { |
| 59 | + const currentPath = pathSegments.slice(0, i + 1).join('/') |
| 60 | + |
| 61 | + const exists = await judgeDirExist(context, currentPath) |
| 62 | + if (!exists) { |
| 63 | + const url = `${endpoint}/${currentPath}` |
| 64 | + const headers = authHeaders(auth) |
| 65 | + const response = await fetch(url, { method: 'MKCOL', headers }) |
| 66 | + handleWriteResponse(response) |
| 67 | + } |
| 68 | + } |
58 | 69 | } |
59 | 70 |
|
60 | 71 | export async function deleteDir(context: WebDAVContext, dirPath: string) { |
|
0 commit comments