diff --git a/apps/api/src/group-files/ocis-webdav.ts b/apps/api/src/group-files/ocis-webdav.ts index 65c75ef..5d4707f 100644 --- a/apps/api/src/group-files/ocis-webdav.ts +++ b/apps/api/src/group-files/ocis-webdav.ts @@ -144,7 +144,14 @@ export class OcisWebdavClient { /** MKCOL the group folder; 405 (already exists) is fine. */ private async ensureGroupFolder(groupId: string): Promise { - const url = `${this.config.webdavUrl}/remote.php/dav/files/${encodeURIComponent(this.config.user)}/hub-groups/${encodeURIComponent(groupId)}`; + const base = `${this.config.webdavUrl}/remote.php/dav/files/${encodeURIComponent(this.config.user)}`; + // MKCOL returns 409 when the parent collection is missing — create the + // hub-groups root (405 = already exists), then the per-group folder. + const root = await this.fetcher(`${base}/hub-groups`, { method: "MKCOL", headers: this.authHeaders() }); + if (!root.ok && root.status !== 405) { + throw new Error(`oCIS folder creation failed with ${root.status}`); + } + const url = `${base}/hub-groups/${encodeURIComponent(groupId)}`; const response = await this.fetcher(url, { method: "MKCOL", headers: this.authHeaders() }); if (response.ok || response.status === 405) return; throw new Error(`oCIS folder creation failed with ${response.status}`);