File
Blob: src/worker/objects/file-dav-object.ts
| 1 | import { DurableObject } from "cloudflare:workers"; |
| 2 | |
| 3 | import { createFileDavDoDb, type FileDavDoDb } from "@/worker/db/file-dav-do/client"; |
| 4 | import { |
| 5 | abortWrite as abortWriteOp, |
| 6 | beginWrite, |
| 7 | commitWrite, |
| 8 | copyNode, |
| 9 | deleteNode, |
| 10 | moveNodeEntry, |
| 11 | } from "@/worker/objects/file-dav/writes"; |
| 12 | import { lock as lockOp, unlock as unlockOp } from "@/worker/objects/file-dav/locks"; |
| 13 | import { |
| 14 | cleanupExpiredLocks as cleanupExpiredLocksOp, |
| 15 | cleanupExpiredPendingUploads as cleanupExpiredPendingUploadsOp, |
| 16 | repairFileDav, |
| 17 | verifyBlobUnreferenced as verifyBlobUnreferencedOp, |
| 18 | } from "@/worker/objects/file-dav/maintenance"; |
| 19 | import { |
| 20 | ensureInitialized as ensureInitializedOp, |
| 21 | mkcol as mkcolOp, |
| 22 | propfind as propfindOp, |
| 23 | proppatch as proppatchOp, |
| 24 | resolveFile as resolveFileOp, |
| 25 | } from "@/worker/objects/file-dav/properties"; |
| 26 | import type { |
| 27 | AbortWriteInput, |
| 28 | BeginWriteInput, |
| 29 | CleanupExpiredLocksInput, |
| 30 | CleanupExpiredPendingUploadsInput, |
| 31 | CommitWriteInput, |
| 32 | CopyInput, |
| 33 | DeleteInput, |
| 34 | EnsureInitializedInput, |
| 35 | FileDavRepairInput, |
| 36 | LockInput, |
| 37 | MkcolInput, |
| 38 | MoveInput, |
| 39 | PropfindInput, |
| 40 | ProppatchInput, |
| 41 | ResolveFileInput, |
| 42 | UnlockInput, |
| 43 | VerifyBlobUnreferencedInput, |
| 44 | } from "@/worker/objects/file-dav/types"; |
| 45 | import { migrateFileDavObject } from "@/worker/objects/common/migrations"; |
| 46 | |
| 47 | export type { |
| 48 | AbortWriteInput, |
| 49 | BeginWriteInput, |
| 50 | BeginWriteResult, |
| 51 | BlobGcCandidate, |
| 52 | CleanupExpiredLocksInput, |
| 53 | CleanupExpiredPendingUploadsInput, |
| 54 | CommitWriteInput, |
| 55 | CommitWriteResult, |
| 56 | CopyInput, |
| 57 | DeleteInput, |
| 58 | EnsureInitializedInput, |
| 59 | FileDavRepairInput, |
| 60 | FileDavError, |
| 61 | FileDavErrorCode, |
| 62 | FileDavNodeView, |
| 63 | LockInput, |
| 64 | MkcolInput, |
| 65 | MoveInput, |
| 66 | PropfindInput, |
| 67 | ProppatchInput, |
| 68 | ResolveFileInput, |
| 69 | ResolveFileResult, |
| 70 | SubjectInput, |
| 71 | UnlockInput, |
| 72 | VerifyBlobUnreferencedInput, |
| 73 | } from "@/worker/objects/file-dav/types"; |
| 74 | |
| 75 | export class FileDavObject extends DurableObject<Env> { |
| 76 | readonly db: FileDavDoDb; |
| 77 | |
| 78 | constructor(ctx: DurableObjectState, env: Env) { |
| 79 | super(ctx, env); |
| 80 | this.db = createFileDavDoDb(ctx.storage); |
| 81 | |
| 82 | ctx.blockConcurrencyWhile(async () => { |
| 83 | await migrateFileDavObject(this.db); |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | async ping(): Promise<{ ok: true; object: "file-dav" }> { |
| 88 | return { ok: true, object: "file-dav" }; |
| 89 | } |
| 90 | |
| 91 | async ensureInitialized(input: EnsureInitializedInput) { |
| 92 | return ensureInitializedOp(this.db, input); |
| 93 | } |
| 94 | |
| 95 | async propfind(input: PropfindInput) { |
| 96 | return propfindOp(this.db, input); |
| 97 | } |
| 98 | |
| 99 | async mkcol(input: MkcolInput) { |
| 100 | return mkcolOp(this.db, input); |
| 101 | } |
| 102 | |
| 103 | async proppatch(input: ProppatchInput) { |
| 104 | return proppatchOp(this.db, input); |
| 105 | } |
| 106 | |
| 107 | async beginWrite(input: BeginWriteInput) { |
| 108 | return beginWrite(this.db, input); |
| 109 | } |
| 110 | |
| 111 | async commitWrite(input: CommitWriteInput) { |
| 112 | return commitWrite(this.db, input); |
| 113 | } |
| 114 | |
| 115 | async abortWrite(input: AbortWriteInput) { |
| 116 | return abortWriteOp(this.db, input); |
| 117 | } |
| 118 | |
| 119 | async resolveFile(input: ResolveFileInput) { |
| 120 | return resolveFileOp(this.db, input); |
| 121 | } |
| 122 | |
| 123 | async delete(input: DeleteInput) { |
| 124 | return deleteNode(this.db, input); |
| 125 | } |
| 126 | |
| 127 | async copy(input: CopyInput) { |
| 128 | return copyNode(this.db, input); |
| 129 | } |
| 130 | |
| 131 | async move(input: MoveInput) { |
| 132 | return moveNodeEntry(this.db, input); |
| 133 | } |
| 134 | |
| 135 | async lock(input: LockInput) { |
| 136 | return lockOp(this.db, input); |
| 137 | } |
| 138 | |
| 139 | async unlock(input: UnlockInput) { |
| 140 | return unlockOp(this.db, input); |
| 141 | } |
| 142 | |
| 143 | async verifyBlobUnreferenced(input: VerifyBlobUnreferencedInput) { |
| 144 | return verifyBlobUnreferencedOp(this.db, input); |
| 145 | } |
| 146 | |
| 147 | async cleanupExpiredPendingUploads(input: CleanupExpiredPendingUploadsInput) { |
| 148 | return cleanupExpiredPendingUploadsOp(this.db, input); |
| 149 | } |
| 150 | |
| 151 | async cleanupExpiredLocks(input: CleanupExpiredLocksInput) { |
| 152 | return cleanupExpiredLocksOp(this.db, input); |
| 153 | } |
| 154 | |
| 155 | async repair(input: FileDavRepairInput) { |
| 156 | return repairFileDav(this.db, input); |
| 157 | } |
| 158 | } |