chore: prepare v1.0.0 release
This commit is contained in:
+1
-32
@@ -1,11 +1,5 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// Nextcloud WebDAV client
|
||||
// Uses native fetch — no npm package needed.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const MAX_VERSIONS = 1000
|
||||
|
||||
// Lazy-cached config to avoid recomputing on every request
|
||||
let cachedConfig: { davBase: string; auth: string } | null = null
|
||||
|
||||
function getConfig() {
|
||||
@@ -19,7 +13,6 @@ function getConfig() {
|
||||
throw new Error('Nextcloud non configure (NEXTCLOUD_URL, NEXTCLOUD_SHARE_TOKEN)')
|
||||
}
|
||||
|
||||
// Public share WebDAV: https://cloud.example.com/public.php/webdav/
|
||||
const davBase = `${url.replace(/\/+$/, '')}/public.php/webdav`
|
||||
const auth = 'Basic ' + Buffer.from(`${token}:${password}`).toString('base64')
|
||||
|
||||
@@ -32,10 +25,6 @@ function davUrl(davBase: string, path: string): string {
|
||||
return `${davBase}/${clean}`
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Low-level WebDAV helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function davRequest(
|
||||
method: string,
|
||||
path: string,
|
||||
@@ -57,12 +46,7 @@ async function davRequest(
|
||||
return res
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Public API
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** Check if a folder exists on the Nextcloud instance. */
|
||||
export async function folderExists(path: string): Promise<boolean> {
|
||||
async function folderExists(path: string): Promise<boolean> {
|
||||
const res = await davRequest('PROPFIND', path + '/', null, { Depth: '0' })
|
||||
|
||||
if (res.status === 404) return false
|
||||
@@ -72,10 +56,6 @@ export async function folderExists(path: string): Promise<boolean> {
|
||||
throw new Error(`PROPFIND ${path} failed (${res.status}): ${text.slice(0, 200)}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a folder and all parent segments if they don't exist.
|
||||
* Like `mkdir -p`. Attempts MKCOL directly and handles 405 (already exists).
|
||||
*/
|
||||
export async function mkdirRecursive(path: string): Promise<void> {
|
||||
const segments = path.replace(/^\/+/, '').replace(/\/+$/, '').split('/')
|
||||
let current = ''
|
||||
@@ -84,14 +64,12 @@ export async function mkdirRecursive(path: string): Promise<void> {
|
||||
current += '/' + seg
|
||||
const res = await davRequest('MKCOL', current + '/')
|
||||
if (res.status !== 201 && res.status !== 405) {
|
||||
// 201 = created, 405 = already exists — both are fine
|
||||
const text = await res.text().catch(() => '')
|
||||
throw new Error(`MKCOL ${current} failed (${res.status}): ${text.slice(0, 200)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Upload a file (overwrite if exists). */
|
||||
export async function uploadFile(path: string, content: Buffer): Promise<void> {
|
||||
const res = await davRequest('PUT', path, content, {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
@@ -104,7 +82,6 @@ export async function uploadFile(path: string, content: Buffer): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Move (rename) a folder or file. */
|
||||
export async function moveFolder(from: string, to: string): Promise<void> {
|
||||
const { davBase } = getConfig()
|
||||
const destination = davUrl(davBase, to) + '/'
|
||||
@@ -120,14 +97,6 @@ export async function moveFolder(from: string, to: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// High-level: find next available version folder
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Find the next available Vx folder for archiving.
|
||||
* E.g. if V1/coffeetest exists but V2/coffeetest doesn't, returns "V2".
|
||||
*/
|
||||
export async function findNextVersion(
|
||||
basePath: string,
|
||||
folderName: string,
|
||||
|
||||
Reference in New Issue
Block a user