@filebox/webdav-server 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +621 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.mjs +591 -0
- package/package.json +17 -9
- package/context.js +0 -37
- package/index.js +0 -88
- package/operations/commands.js +0 -31
- package/operations/copy.js +0 -37
- package/operations/delete.js +0 -12
- package/operations/get.js +0 -34
- package/operations/head.js +0 -23
- package/operations/lock.js +0 -1
- package/operations/mkcol.js +0 -14
- package/operations/move.js +0 -46
- package/operations/not-implemented.js +0 -10
- package/operations/options.js +0 -17
- package/operations/post.js +0 -10
- package/operations/propfind.js +0 -323
- package/operations/proppatch.js +0 -5
- package/operations/put.js +0 -66
- package/operations/shared.js +0 -26
- package/operations/unlock.js +0 -1
package/operations/put.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const { basename, dirname } = require("pathe");
|
|
2
|
-
const fs = require("node:fs");
|
|
3
|
-
const path = require("node:path");
|
|
4
|
-
|
|
5
|
-
module.exports = async (ctx) => {
|
|
6
|
-
try {
|
|
7
|
-
const rawPath = decodeURIComponent(ctx.path);
|
|
8
|
-
const name = basename(rawPath);
|
|
9
|
-
const upath = dirname(rawPath);
|
|
10
|
-
|
|
11
|
-
const contentLength = parseInt(ctx.req.headers["content-length"] || 0);
|
|
12
|
-
const mimeType =
|
|
13
|
-
ctx.req.headers["content-type"] || "application/octet-stream";
|
|
14
|
-
|
|
15
|
-
const tempDir = ctx.config?.temp;
|
|
16
|
-
if (!tempDir) {
|
|
17
|
-
return { status: "500", body: "temp dir not configured" };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const tempFile = path.join(tempDir, `webdav-upload-${Date.now()}-${name}`);
|
|
21
|
-
const uploadStream =
|
|
22
|
-
ctx.req._webdavStream ||
|
|
23
|
-
(ctx.req.readable && !ctx.req.readableEnded ? ctx.req : null);
|
|
24
|
-
|
|
25
|
-
if (uploadStream && contentLength > 0) {
|
|
26
|
-
await new Promise((resolve, reject) => {
|
|
27
|
-
const ws = fs.createWriteStream(tempFile);
|
|
28
|
-
uploadStream.pipe(ws);
|
|
29
|
-
ws.on("finish", resolve);
|
|
30
|
-
ws.on("error", reject);
|
|
31
|
-
uploadStream.on("error", reject);
|
|
32
|
-
});
|
|
33
|
-
} else {
|
|
34
|
-
fs.writeFileSync(tempFile, "");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const tempStat = fs.statSync(tempFile);
|
|
38
|
-
|
|
39
|
-
if (tempStat.size === 0 && contentLength > 0) {
|
|
40
|
-
return { status: "502", body: "upload failed: empty file" };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const result = await ctx.driver.upload(upath, {
|
|
45
|
-
name,
|
|
46
|
-
size: tempStat.size,
|
|
47
|
-
absolutePath: tempFile,
|
|
48
|
-
mimeType,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
if (result && typeof result.upload === "function") {
|
|
52
|
-
await result.upload();
|
|
53
|
-
}
|
|
54
|
-
} catch (error) {
|
|
55
|
-
return { status: "502", body: String(error) };
|
|
56
|
-
} finally {
|
|
57
|
-
try {
|
|
58
|
-
fs.unlinkSync(tempFile);
|
|
59
|
-
} catch (_) {}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return { status: "200" };
|
|
63
|
-
} catch (err) {
|
|
64
|
-
return { status: "502", body: String(err?.message || err) };
|
|
65
|
-
}
|
|
66
|
-
};
|
package/operations/shared.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const { parseStringPromise, processors } = require("xml2js");
|
|
2
|
-
|
|
3
|
-
const parseBody = (req, charset) => {
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
const data = [];
|
|
6
|
-
const stream = req._webdavStream || req;
|
|
7
|
-
stream
|
|
8
|
-
.on("data", (chunk) => {
|
|
9
|
-
data.push(chunk);
|
|
10
|
-
})
|
|
11
|
-
.on("error", reject)
|
|
12
|
-
.on("end", () => resolve(Buffer.concat(data).toString(charset)));
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const parseXML = async (req) => {
|
|
17
|
-
const txt = await parseBody(req);
|
|
18
|
-
if (!txt.trim()) return null;
|
|
19
|
-
return await parseStringPromise(txt, {
|
|
20
|
-
// explicitChildren: true,
|
|
21
|
-
explicitArray: false,
|
|
22
|
-
tagNameProcessors: [processors.stripPrefix],
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
module.exports = parseXML;
|
package/operations/unlock.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|