import { escapeXml } from "@/worker/dav/multistatus"; import type { FileLockRow } from "@/worker/db/file-dav-do/schema"; export function lockXml(lock: FileLockRow): string { const timeoutSeconds = Math.max(0, Math.floor((lock.expiresAtMs - Date.now()) / 1000)); return `${ lock.depth === "infinity" ? "Infinity" : "0" }${lock.ownerXml}Second-${timeoutSeconds}${escapeXml( lock.token, )}${escapeXml(lock.rootPath)}`; } export function parseTimeout(header: string | null): number { if (!header) return 600; const first = header.split(",")[0]?.trim() ?? ""; const match = /^Second-(\d+)$/i.exec(first); if (!match) return 600; return Number.parseInt(match[1]!, 10); }