From 0648a0ae121e381aeebd0ba766d59375ba3edfec Mon Sep 17 00:00:00 2001 From: masx200 Date: Sat, 21 Sep 2024 23:18:32 +0800 Subject: [PATCH] import swc from "rollup-plugin-swc"; --- dist/index.js | 84 ++++++++++++------------- dist/index.js.map | 2 +- dist/webdav-cli.cli.js | 120 ++++++++++++++++++------------------ dist/webdav-cli.cli.js.map | 2 +- package.json | 2 + rollup.config.mjs | 16 ++++- src/create-http-auth.ts | 6 +- src/createhttpauthmiddle.ts | 4 +- src/index.ts | 10 +-- src/main.ts | 8 +-- src/webdav-cli.cli.ts | 2 +- src/webdav-cli.server.ts | 21 ++++--- tsconfig.json | 3 +- 13 files changed, 147 insertions(+), 133 deletions(-) diff --git a/dist/index.js b/dist/index.js index 458e72b..0315750 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,42 +1,42 @@ #!/usr/bin/env node -import e from "fs"; +import { dirname as e, join as t } from "path"; -import { dirname as t, join as s } from "path"; +import s from "http-auth"; -import { fileURLToPath as n } from "url"; +import n from "http-auth/src/auth/utils.js"; -import { v2 as o } from "webdav-server"; +import { fileURLToPath as o } from "url"; -import i from "http-auth"; +import i from "fs"; -import r from "http-auth/src/auth/utils.js"; +import r from "koa"; -import a from "koa"; +import a from "koa-logger"; -import c from "koa-logger"; +import { loadcoremiddles as c } from "@masx200/serve-cli"; -import { loadcoremiddles as h } from "@masx200/serve-cli"; +import { v2 as h } from "webdav-server"; import l from "process"; const u = [ "all", "canCreate", "canDelete", "canMove", "canRename", "canAppend", "canWrite", "canRead", "canSource", "canGetMimeType", "canGetSize", "canListLocks", "canSetLock", "canRemoveLock", "canGetAvailableLocks", "canGetLock", "canAddChild", "canRemoveChild", "canGetChildren", "canSetProperty", "canGetProperty", "canGetProperties", "canRemoveProperty", "canGetCreationDate", "canGetLastModifiedDate", "canGetWebName", "canGetType" ]; function d(e) { - const t = "Default realm", s = "HTTPBasicAuthentication" === e.authentication ? function(e, t, s) { - return i.basic({ + const t = "Default realm", o = "HTTPBasicAuthentication" === e.authentication ? function(e, t, n) { + return s.basic({ realm: e - }, ((e, n, o) => { - o(e === t && n === s); + }, ((e, s, o) => { + o(e === t && s === n); })); - }(t, e.user, e.pass) : function(e, t, s) { - return i.digest({ + }(t, e.user, e.pass) : function(e, t, o) { + return s.digest({ realm: e - }, ((n, o) => { - n === t ? o(r.md5(`${n}:${e}:${s}`)) : o(); + }, ((s, i) => { + s === t ? i(n.md5(`${s}:${e}:${o}`)) : i(); })); }(t, e.user, e.pass); return (e, t) => { - s.check(((e, s) => { + o.check(((e, s) => { t(); }))(e.request, e.response); }; @@ -46,7 +46,7 @@ function p(e) { return [ ...Array(Math.ceil(e / 8)) ].map((() => Math.random().toString(36).slice(-8))).join("").slice(-e); } -const m = t(n(import.meta.url)); +const m = e(o(import.meta.url)); class A { config; @@ -63,16 +63,16 @@ class A { }(this.config.username, this.config.password, t); this.#e = s, this.server = this.#n(); } - #t(t) { - const n = s(m, "/../certs/self-signed.key.pem"), o = s(m, "/../certs/self-signed.cert.pem"), i = t.path || process.cwd(), r = t.host || "0.0.0.0", a = t.port || 1900, c = Boolean(t.digest); - let h = (t.username || p(16)).toString(), l = (t.password || p(16)).toString(); - const d = Boolean(t.ssl), A = d ? e.readFileSync(t.sslKey || n).toString() : "", g = d ? e.readFileSync(t.sslCert || o).toString() : "", f = Boolean(t.disableAuthentication); - f && (t.rights = t.rights || [ "canRead" ], h = "", l = ""); - const _ = (t.rights || [ "all" ]).filter((e => u.includes(e))), S = `${d ? "https" : "http"}://${r}:${a}`; + #t(e) { + const s = t(m, "/../certs/self-signed.key.pem"), n = t(m, "/../certs/self-signed.cert.pem"), o = e.path || process.cwd(), r = e.host || "0.0.0.0", a = e.port || 1900, c = Boolean(e.digest); + let h = (e.username || p(16)).toString(), l = (e.password || p(16)).toString(); + const d = Boolean(e.ssl), A = d ? i.readFileSync(e.sslKey || s).toString() : "", g = d ? i.readFileSync(e.sslCert || n).toString() : "", f = Boolean(e.disableAuthentication); + f && (e.rights = e.rights || [ "canRead" ], h = "", l = ""); + const _ = (e.rights || [ "all" ]).filter((e => u.includes(e))), S = `${d ? "https" : "http"}://${r}:${a}`; return { - ...t, + ...e, host: r, - path: i, + path: o, port: a, username: h, digest: c, @@ -86,9 +86,9 @@ class A { }; } #n() { - const e = this.config, t = new o.SimpleUserManager, s = t.addUser(e.username, e.password, !1), n = new o.SimplePathPrivilegeManager; + const e = this.config, t = new h.SimpleUserManager, s = t.addUser(e.username, e.password, !1), n = new h.SimplePathPrivilegeManager; n.setRights(s, "/", e.rights); - const i = { + const o = { requireAuthentification: !1, httpAuthentication: { askForAuthentication: () => ({}), @@ -101,39 +101,39 @@ class A { port: e.port, hostname: e.host }; - e.ssl && Reflect.set(i, "https", { + e.ssl && Reflect.set(o, "https", { cert: e.sslCert, key: e.sslKey }); - const r = new o.WebDAVServer(i); - if (r.beforeRequest((async (e, t) => { + const i = new h.WebDAVServer(o); + if (i.beforeRequest((async (e, t) => { const {url: s, headers: n, method: o} = e.request; console.log(">> ", o, s, n), t(); - })), e.disableAuthentication) r.beforeRequest(((e, t) => { + })), e.disableAuthentication) i.beforeRequest(((e, t) => { e.request.method && [ "GET", "HEAD", "PROPFIND", "OPTIONS" ].includes(e.request.method) ? t() : (e.setCode(405), e.exit()); })); else { const e = this.#e; - Array.isArray(this.config.methodsWithoutAuthentication) && this.config.methodsWithoutAuthentication.length ? r.beforeRequest(((t, s) => { + Array.isArray(this.config.methodsWithoutAuthentication) && this.config.methodsWithoutAuthentication.length ? i.beforeRequest(((t, s) => { t.request.method && this.config.methodsWithoutAuthentication?.includes(t.request.method) ? s() : e(t, s); - })) : r.beforeRequest(e); + })) : i.beforeRequest(e); } - return r.beforeRequest(((e, t) => { + return i.beforeRequest(((e, t) => { const {headers: s, method: n} = e.request, {depth: o} = s; "PROPFIND" === n && "0" !== o && "1" !== o ? (e.setCode(403), e.exit()) : t(); - })), r.beforeRequest(function(e) { - const t = new a; - t.use(c()), h(t, e, !1); + })), i.beforeRequest(function(e) { + const t = new r; + t.use(a()), c(t, e, !1); const s = t.callback(); return function(e, t) { const {request: n, response: o} = e, [i, r] = [ n, o ]; if (e.request.method && ![ "GET", "HEAD" ].includes(e.request.method)) return t(); s(i, r); }; - }(e.path)), r.afterRequest(((e, t) => { + }(e.path)), i.afterRequest(((e, t) => { const s = `>> ${e.request.method} ${e.requested.uri} > ${e.response.statusCode} `; console.log(s), t(); - })), r; + })), i; } #s(e) { return e.digest ? "HTTPDigestAuthentication" : "HTTPBasicAuthentication"; @@ -141,7 +141,7 @@ class A { async start() { const e = this.config, {server: t} = this; console.log(Object.fromEntries(Object.entries(e).filter((([e]) => ![ "sslKey", "sslCert" ].includes(e))))), - await t.setFileSystemAsync("/", new o.PhysicalFileSystem(e.path)); + await t.setFileSystemAsync("/", new h.PhysicalFileSystem(e.path)); const s = [ `Server running at ${e.url}`, "Hit CTRL-C to stop the server", "Run with --help to print help" ]; let n; console.log(s.join("\n")), Object.defineProperty(t, "server", { diff --git a/dist/index.js.map b/dist/index.js.map index 1720b68..d224a78 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../src/webdav-cli.constants.ts","../src/create-http-auth.ts","../src/createbasicauth.ts","../src/createdigestauth.ts","../src/webdav-cli.utils.ts","../src/webdav-cli.server.ts","../src/createhttpauthmiddle.ts","../src/beforelogger.ts","../src/propfindchecker.ts","../src/koa-static-server.ts","../src/afterlogger.ts","../src/main.ts","../src/showhelp.ts"],"sourcesContent":["import { WebdavCliRights } from \"./webdav-cli.interfaces\";\n\n// export const HOMEPAGE = 'https://github.com/svtslv/webdav-cli';\n\nexport const RIGHTS: WebdavCliRights = [\n \"all\",\n \"canCreate\",\n \"canDelete\",\n \"canMove\",\n \"canRename\",\n \"canAppend\",\n \"canWrite\",\n \"canRead\",\n \"canSource\",\n \"canGetMimeType\",\n \"canGetSize\",\n \"canListLocks\",\n \"canSetLock\",\n \"canRemoveLock\",\n \"canGetAvailableLocks\",\n \"canGetLock\",\n \"canAddChild\",\n \"canRemoveChild\",\n \"canGetChildren\",\n \"canSetProperty\",\n \"canGetProperty\",\n \"canGetProperties\",\n \"canRemoveProperty\",\n \"canGetCreationDate\",\n \"canGetLastModifiedDate\",\n \"canGetWebName\",\n \"canGetType\",\n];\n","import { v2 as webdav } from \"webdav-server\";\n//@ts-ignore\nimport { createbasicauth } from \"./createbasicauth.js\";\nimport { createdigestauth } from \"./createdigestauth.js\";\n\nexport function createhttpauth(options: {\n user: string;\n pass: string;\n authentication: \"HTTPDigestAuthentication\" | \"HTTPBasicAuthentication\";\n}) {\n const realm = \"Default realm\";\n const auth =\n options.authentication === \"HTTPBasicAuthentication\"\n ? createbasicauth(realm, options.user, options.pass)\n : createdigestauth(realm, options.user, options.pass);\n return (ctx: webdav.HTTPRequestContext, next: () => void) => {\n auth.check((req, res) => {\n next();\n })(ctx.request, ctx.response);\n };\n}\n","import httpauth from \"http-auth\";\n\nexport function createbasicauth(\n realm: string,\n user: string,\n pass: string,\n): ReturnType {\n return httpauth.basic(\n {\n realm,\n },\n (username, password, callback) => {\n // Custom authentication method.\n callback(username === user && password === pass);\n },\n );\n}\n","import httpauth from \"http-auth\";\n//@ts-ignore\nimport utils from \"http-auth/src/auth/utils.js\";\n\nexport function createdigestauth(\n realm: string,\n user: string,\n pass: string,\n): ReturnType {\n return httpauth.digest(\n {\n realm,\n },\n // Expecting md5(username:realm:password) in callback.\n (username, callback) => {\n if (username === user) {\n callback(utils.md5(`${username}:${realm}:${pass}`));\n } else {\n callback();\n }\n },\n );\n}\n","export function getRandomString(length: number) {\n return [...Array(Math.ceil(length / 8))]\n .map(() => Math.random().toString(36).slice(-8))\n .join(\"\")\n .slice(-length);\n}\n","import fs from \"fs\";\nimport http from \"http\";\nimport https from \"https\";\nimport { dirname, join } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { v2 as webdav } from \"webdav-server\";\nimport { afterlogger } from \"./afterlogger.js\";\nimport { beforelogger } from \"./beforelogger.js\";\nimport { createhttpauthmiddle } from \"./createhttpauthmiddle.js\";\nimport { koa_static_server } from \"./koa-static-server.js\";\nimport { propfindchecker } from \"./propfindchecker.js\";\nimport { RIGHTS } from \"./webdav-cli.constants.js\";\nimport { WebdavCliConfig, WebdavCliRights } from \"./webdav-cli.interfaces.js\";\nimport { getRandomString } from \"./webdav-cli.utils.js\";\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nexport class WebdavCli {\n config: WebdavCliConfig;\n server: webdav.WebDAVServer;\n #auth_middle: (ctx: webdav.HTTPRequestContext, next: () => void) => void;\n constructor(config: Partial) {\n this.config = this.#getConfig(config);\n const authentication = this.#get_authentication(this.config);\n const auth_middle = createhttpauthmiddle(\n this.config.username,\n this.config.password,\n authentication,\n );\n this.#auth_middle = auth_middle;\n this.server = this.#init();\n }\n\n #getConfig(config: Partial): WebdavCliConfig {\n const selfSignedKey = join(__dirname, \"/../certs/self-signed.key.pem\");\n const selfSignedCert = join(\n __dirname,\n \"/../certs/self-signed.cert.pem\",\n );\n\n const path = config.path || process.cwd();\n const host = config.host || \"0.0.0.0\";\n const port = config.port || 1900;\n\n const digest = Boolean(config.digest);\n let username = (config.username || getRandomString(16)).toString();\n let password = (config.password || getRandomString(16)).toString();\n\n const ssl = Boolean(config.ssl);\n const sslKey = ssl\n ? fs.readFileSync(config.sslKey || selfSignedKey).toString()\n : \"\";\n const sslCert = ssl\n ? fs.readFileSync(config.sslCert || selfSignedCert).toString()\n : \"\";\n\n const disableAuthentication = Boolean(config.disableAuthentication);\n\n if (disableAuthentication) {\n config.rights = config.rights || [\"canRead\"];\n username = \"\";\n password = \"\";\n }\n\n const rights = (config.rights || [\"all\"]).filter(\n (item: WebdavCliRights[number]) => RIGHTS.includes(item),\n );\n const url = `${ssl ? \"https\" : \"http\"}://${host}:${port}`;\n\n return {\n ...config,\n host,\n path,\n port,\n username,\n digest,\n password,\n ssl,\n sslCert,\n sslKey,\n rights,\n url,\n disableAuthentication,\n };\n }\n\n #init(): webdav.WebDAVServer {\n const config = this.config;\n\n const userManager = new webdav.SimpleUserManager();\n const user = userManager.addUser(\n config.username,\n config.password,\n false,\n );\n\n const privilegeManager = new webdav.SimplePathPrivilegeManager();\n privilegeManager.setRights(user, \"/\", config.rights);\n\n const options = {\n requireAuthentification: false,\n httpAuthentication:\n // config.disableAuthentication\n // ?\n {\n askForAuthentication: () => ({}),\n getUser: (\n ctx: any,\n gotUserCallback: (\n arg0: Error,\n arg1: webdav.IUser,\n ) => void,\n ) => {\n userManager.getDefaultUser((defaultUser) => {\n privilegeManager.setRights(\n defaultUser,\n \"/\",\n config.rights,\n );\n //@ts-ignore\n gotUserCallback(null, defaultUser);\n });\n },\n },\n // :\n // new webdav[authentication](userManager, \"Default realm\"),\n // privilegeManager: privilegeManager,\n // https: config.ssl\n // ? { cert: config.sslCert, key: config.sslKey }\n // : undefined,\n port: config.port,\n hostname: config.host,\n };\n config.ssl &&\n Reflect.set(options, \"https\", {\n cert: config.sslCert,\n key: config.sslKey,\n });\n const server = new webdav.WebDAVServer(options);\n\n server.beforeRequest(beforelogger());\n if (!config.disableAuthentication) {\n const auth_middle = this.#auth_middle;\n if (\n Array.isArray(this.config.methodsWithoutAuthentication) &&\n this.config.methodsWithoutAuthentication.length\n ) {\n server.beforeRequest((ctx, next): void => {\n if (\n ctx.request.method &&\n this.config.methodsWithoutAuthentication?.includes(\n ctx.request.method,\n )\n ) {\n next();\n } else {\n auth_middle(ctx, next);\n }\n });\n } else {\n server.beforeRequest(auth_middle);\n }\n } else {\n server.beforeRequest((ctx, next) => {\n const readonly_methods = [\"GET\", \"HEAD\", \"PROPFIND\", \"OPTIONS\"];\n if (\n ctx.request.method &&\n readonly_methods.includes(ctx.request.method)\n ) {\n next();\n } else {\n ctx.setCode(405);\n ctx.exit();\n }\n });\n }\n server.beforeRequest(propfindchecker());\n server.beforeRequest(koa_static_server(config.path));\n server.afterRequest(afterlogger());\n\n return server;\n }\n #get_authentication(config: WebdavCliConfig) {\n return config.digest\n ? \"HTTPDigestAuthentication\"\n : \"HTTPBasicAuthentication\";\n }\n\n async start() {\n const config = this.config;\n const { server } = this;\n console.log(\n Object.fromEntries(\n Object.entries(config).filter(([key]) => {\n return ![\"sslKey\", \"sslCert\"].includes(key);\n }),\n ),\n );\n await server.setFileSystemAsync(\n \"/\",\n new webdav.PhysicalFileSystem(config.path),\n );\n const logs = [\n `Server running at ${config.url}`,\n\n \"Hit CTRL-C to stop the server\",\n \"Run with --help to print help\",\n ];\n\n console.log(logs.join(\"\\n\"));\n let rawhttpserver: http.Server | https.Server | undefined = undefined;\n\n Object.defineProperty(server, \"server\", {\n get() {\n return rawhttpserver;\n },\n set(v) {\n rawhttpserver = v;\n if (!rawhttpserver) {\n return;\n }\n rawhttpserver.on(\"error\", (err) => {\n if (Reflect.get(err, \"code\") === \"EADDRINUSE\") {\n console.error(err);\n rawhttpserver?.listen(\n Math.round(Math.random() * 65535),\n config.host,\n );\n return;\n } else {\n throw err;\n }\n });\n rawhttpserver.on(\"listening\", () => {\n console.log(\n `Server listening on ` +\n JSON.stringify(rawhttpserver?.address()),\n );\n });\n\n return;\n },\n enumerable: true,\n configurable: true,\n });\n\n await server.startAsync(config.port);\n }\n}\nexport type HTTPRequestContext = webdav.HTTPRequestContext;\n","import { HTTPRequestContext } from \"./index\";\nimport { createhttpauth } from \"./create-http-auth.js\";\n\nexport function createhttpauthmiddle(\n username: string,\n password: string,\n authentication: \"HTTPDigestAuthentication\" | \"HTTPBasicAuthentication\",\n): (ctx: HTTPRequestContext, next: () => void) => void {\n return createhttpauth({\n user: username,\n pass: password,\n authentication,\n });\n}\n","import { HTTPRequestContext } from \"./webdav-cli.server.js\";\n\nexport function beforelogger() {\n return async (ctx: HTTPRequestContext, next: () => void) => {\n const { url, headers, method } = ctx.request;\n console.log(\">> \", method, url, headers);\n next();\n };\n}\n","import { HTTPRequestContext } from \"./webdav-cli.server.js\";\n\nexport function propfindchecker() {\n return (arg: HTTPRequestContext, next: () => void) => {\n const { headers, method } = arg.request;\n const { depth } = headers;\n if (method === \"PROPFIND\" && depth !== \"0\" && depth !== \"1\") {\n arg.setCode(403);\n arg.exit();\n } else {\n next();\n }\n };\n}\n","//@ts-ignore\nimport Koa from \"koa\";\nimport logger from \"koa-logger\";\nimport { v2 as webdav } from \"webdav-server\";\n//@ts-ignore\nimport { loadcoremiddles } from \"@masx200/serve-cli\";\nexport function koa_static_server(publicpath: string) {\n const app = new Koa();\n // app.use(async (ctx, next) => {\n // ctx.response.set(\"Access-Control-Allow-Origin\", \"*\");\n // return next();\n // });\n\n // app.use(async (ctx, next) => {\n // await next();\n // if (ctx.method === \"HEAD\") {\n // ctx.res.end();\n // }\n // return;\n // });\n // app.use(range);\n // app.use(cors({}));\n app.use(logger());\n // app.use(conditional());\n\n // app.use(compress({}));\n // app.use(streametag({}));\n // app.use(koaetag({}));\n // app.use(serveIndex(publicpath, { hidden: true }));\n // app.use(servestatic(publicpath, { hidden: true }));\n loadcoremiddles(app, publicpath, false);\n const serverHandler = app.callback();\n return function middleware(\n ctx: webdav.HTTPRequestContext,\n next: () => void,\n ) {\n const { request, response } = ctx;\n const [req, res] = [request, response];\n if (\n ctx.request.method &&\n ![\"GET\", \"HEAD\"].includes(ctx.request.method)\n ) {\n return next();\n }\n serverHandler(req, res);\n\n return;\n };\n}\n","import { HTTPRequestContext } from \"./webdav-cli.server.js\";\n\nexport function afterlogger() {\n return (arg: HTTPRequestContext, next: () => void) => {\n const log = `>> ${arg.request.method} ${arg.requested.uri} > ${arg.response.statusCode} `;\n // server.emit('log', null, null, '/', log);\n console.log(log);\n next();\n };\n}\n","import process from \"process\";\nimport minimist from \"minimist\";\nimport { WebdavCli } from \"./webdav-cli.server.js\";\nimport { showhelp } from \"./showhelp.js\";\nimport { WebdavCliConfig } from \"./webdav-cli.interfaces.js\";\n\nexport async function main(\n argv: Partial,\n) {\n console.log(\"webdav-cli\", \"\\n\");\n if (argv.help || argv.h) {\n showhelp();\n }\n // if (argv.version || argv.v) {\n // console.log(\"Version: \" + require(\"../package.json\").version, \"\\n\");\n // process.exit();\n // }\n const rights = argv.rights || argv.r;\n const argvRights =\n rights && typeof rights === \"string\" ? rights.split(\",\") : undefined;\n const envRights = process.env.WEBDAV_CLI_RIGHTS\n ? process.env.WEBDAV_CLI_RIGHTS.split(\",\")\n : undefined;\n const config = {\n path: argv.path || process.env.WEBDAV_CLI_PATH || argv.pa,\n host: argv.host || process.env.WEBDAV_CLI_HOST || argv.ho,\n port:\n Number(argv.port || argv.po) ||\n parseInt(String(process.env.WEBDAV_CLI_PORT)),\n digest:\n argv.digest || argv.dg || Boolean(process.env.WEBDAV_CLI_DIGEST),\n username: argv.username || process.env.WEBDAV_CLI_USERNAME || argv.u,\n password: argv.password || process.env.WEBDAV_CLI_PASSWORD || argv.ps,\n ssl: argv.ssl || argv.s || Boolean(process.env.WEBDAV_CLI_SSL),\n sslKey: argv.sslKey || process.env.WEBDAV_CLI_SSL_KEY,\n sslCert: argv.sslCert || process.env.WEBDAV_CLI_SSL_CERT,\n disableAuthentication:\n argv.disableAuthentication ||\n process.env.WEBDAV_CLI_DISABLE_AUTHENTICATION ||\n argv.da,\n rights: argvRights || envRights,\n methodsWithoutAuthentication:\n \"string\" === typeof argv.methodsWithoutAuthentication\n ? String(argv.methodsWithoutAuthentication).split(\",\")\n : Array.isArray(argv.methodsWithoutAuthentication)\n ? argv.methodsWithoutAuthentication\n : undefined,\n };\n process.on(\"unhandledRejection\", (e) => {\n console.error(e);\n throw e;\n });\n const run = async () => {\n //@ts-ignore\n const webdavCli = new WebdavCli(config);\n await webdavCli.start();\n return webdavCli;\n };\n return await run();\n}\n","import process from \"process\";\nexport function showhelp() {\n console.log(\n [\n \"usage: webdav-cli [options]\",\n \"\",\n \"options:\",\n \" --path,-pa Path to folder [process.cwd()]\",\n \" --host,-ho Host to use [0.0.0.0]\",\n \" --port,-po Port to use [1900]\",\n \" --digest,-dg Enable digest authentication [basic]\",\n \" --username,-u Username for basic/digest authentication [random]\",\n \" --password,-ps Password for basic/digest authentication [random]\",\n \" --disableAuthentication,-da The server file becomes read-only without Authentication.[false]\",\n \" --ssl,-s Enable https [false]\",\n \" --methodsWithoutAuthentication methods Without Authentication[undefined]\",\n \" --sslKey Path to ssl key file [self-signed]\",\n \" --sslCert Path to ssl cert file [self-signed]\",\n \" --help,-h Print this list and exit\",\n // \" --version,-v Print the version and exit.\",\n \" --rights,-r Comma separated values without spaces [all]\",\n `\n 'all', 'canCreate', 'canDelete', 'canMove', 'canRename', \n 'canAppend', 'canWrite', 'canRead', 'canSource', \n 'canGetMimeType', 'canGetSize', 'canListLocks', \n 'canSetLock', 'canRemoveLock', 'canGetAvailableLocks', \n 'canGetLock', 'canAddChild', 'canRemoveChild', \n 'canGetChildren', 'canSetProperty', 'canGetProperty', \n 'canGetProperties', 'canRemoveProperty', 'canGetCreationDate', \n 'canGetLastModifiedDate', 'canGetWebName', 'canGetType'`,\n \"\",\n \"env:\",\n \" WEBDAV_CLI_PATH, WEBDAV_CLI_HOST, WEBDAV_CLI_PORT,\",\n \" WEBDAV_CLI_USERNAME, WEBDAV_CLI_PASSWORD, WEBDAV_CLI_DIGEST,\",\n \" WEBDAV_CLI_SSL, WEBDAV_CLI_SSL_KEY, WEBDAV_CLI_SSL_CERT,\",\n \" WEBDAV_CLI_AUTO_INDEX, WEBDAV_CLI_RIGHTS\",\n \" WEBDAV_CLI_DISABLE_AUTHENTICATION\",\n \"\",\n ].join(\"\\n\"),\n );\n process.exit();\n}\n"],"names":["RIGHTS","createhttpauth","options","realm","auth","authentication","user","pass","httpauth","basic","username","password","callback","createbasicauth","digest","utils","md5","createdigestauth","ctx","next","check","req","res","request","response","getRandomString","length","Array","Math","ceil","map","random","toString","slice","join","__dirname","dirname","fileURLToPath","import","meta","url","WebdavCli","config","server","auth_middle","constructor","this","getConfig","get_authentication","createhttpauthmiddle","init","selfSignedKey","selfSignedCert","path","process","cwd","host","port","Boolean","ssl","sslKey","fs","readFileSync","sslCert","disableAuthentication","rights","filter","item","includes","userManager","webdav","SimpleUserManager","addUser","privilegeManager","SimplePathPrivilegeManager","setRights","requireAuthentification","httpAuthentication","askForAuthentication","getUser","gotUserCallback","getDefaultUser","defaultUser","hostname","Reflect","set","cert","key","WebDAVServer","beforeRequest","async","headers","method","console","log","setCode","exit","isArray","methodsWithoutAuthentication","arg","depth","publicpath","app","Koa","use","logger","loadcoremiddles","serverHandler","koa_static_server","afterRequest","requested","uri","statusCode","Object","fromEntries","entries","setFileSystemAsync","PhysicalFileSystem","logs","rawhttpserver","defineProperty","get","v","on","err","error","listen","round","JSON","stringify","address","enumerable","configurable","startAsync","main","argv","help","h","r","argvRights","split","undefined","envRights","env","WEBDAV_CLI_RIGHTS","WEBDAV_CLI_PATH","pa","WEBDAV_CLI_HOST","ho","Number","po","parseInt","String","WEBDAV_CLI_PORT","dg","WEBDAV_CLI_DIGEST","WEBDAV_CLI_USERNAME","u","WEBDAV_CLI_PASSWORD","ps","s","WEBDAV_CLI_SSL","WEBDAV_CLI_SSL_KEY","WEBDAV_CLI_SSL_CERT","WEBDAV_CLI_DISABLE_AUTHENTICATION","da","e","webdavCli","start","run"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIa,MAAAA,IAA0B,EACnC,OACA,aACA,aACA,WACA,aACA,aACA,YACA,WACA,aACA,kBACA,cACA,gBACA,cACA,iBACA,wBACA,cACA,eACA,kBACA,kBACA,kBACA,kBACA,oBACA,qBACA,sBACA,0BACA,iBACA;;AC1BE,SAAUC,EAAeC;IAK3B,MAAMC,IAAQ,iBACRC,IACyB,8BAA3BF,EAAQG,0BCTZF,GACAG,GACAC;QAEA,OAAOC,EAASC,MACZ;YACIN;YAEJ,CAACO,GAAUC,GAAUC;YAEjBA,EAASF,MAAaJ,KAAQK,MAAaJ;AAAK;AAG5D,KDHcM,CAAgBV,GAAOD,EAAQI,MAAMJ,EAAQK,iBERvDJ,GACAG,GACAC;QAEA,OAAOC,EAASM,OACZ;YACIX;YAGJ,CAACO,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/webdav-cli.cli.js b/dist/webdav-cli.cli.js index daa7ee5..87b2ace 100644 --- a/dist/webdav-cli.cli.js +++ b/dist/webdav-cli.cli.js @@ -1,54 +1,54 @@ #!/usr/bin/env node -import e from "process"; +import { dirname as e, join as t } from "path"; -import t from "fs"; +import s from "http-auth"; -import { dirname as s, join as n } from "path"; +import n from "http-auth/src/auth/utils.js"; import { fileURLToPath as o } from "url"; -import { v2 as i } from "webdav-server"; +import i from "fs"; -import r from "http-auth"; +import r from "koa"; -import a from "http-auth/src/auth/utils.js"; +import a from "koa-logger"; -import c from "koa"; +import { loadcoremiddles as c } from "@masx200/serve-cli"; -import h from "koa-logger"; +import { v2 as h } from "webdav-server"; -import { loadcoremiddles as l } from "@masx200/serve-cli"; +import l from "process"; import u from "minimist"; -function d(e) { - const t = "Default realm", s = "HTTPBasicAuthentication" === e.authentication ? function(e, t, s) { - return r.basic({ +const d = [ "all", "canCreate", "canDelete", "canMove", "canRename", "canAppend", "canWrite", "canRead", "canSource", "canGetMimeType", "canGetSize", "canListLocks", "canSetLock", "canRemoveLock", "canGetAvailableLocks", "canGetLock", "canAddChild", "canRemoveChild", "canGetChildren", "canSetProperty", "canGetProperty", "canGetProperties", "canRemoveProperty", "canGetCreationDate", "canGetLastModifiedDate", "canGetWebName", "canGetType" ]; + +function p(e) { + const t = "Default realm", o = "HTTPBasicAuthentication" === e.authentication ? function(e, t, n) { + return s.basic({ realm: e - }, ((e, n, o) => { - o(e === t && n === s); + }, ((e, s, o) => { + o(e === t && s === n); })); - }(t, e.user, e.pass) : function(e, t, s) { - return r.digest({ + }(t, e.user, e.pass) : function(e, t, o) { + return s.digest({ realm: e - }, ((n, o) => { - n === t ? o(a.md5(`${n}:${e}:${s}`)) : o(); + }, ((s, i) => { + s === t ? i(n.md5(`${s}:${e}:${o}`)) : i(); })); }(t, e.user, e.pass); return (e, t) => { - s.check(((e, s) => { + o.check(((e, s) => { t(); }))(e.request, e.response); }; } -const p = [ "all", "canCreate", "canDelete", "canMove", "canRename", "canAppend", "canWrite", "canRead", "canSource", "canGetMimeType", "canGetSize", "canListLocks", "canSetLock", "canRemoveLock", "canGetAvailableLocks", "canGetLock", "canAddChild", "canRemoveChild", "canGetChildren", "canSetProperty", "canGetProperty", "canGetProperties", "canRemoveProperty", "canGetCreationDate", "canGetLastModifiedDate", "canGetWebName", "canGetType" ]; - function m(e) { return [ ...Array(Math.ceil(e / 8)) ].map((() => Math.random().toString(36).slice(-8))).join("").slice(-e); } -const g = s(o(import.meta.url)); +const g = e(o(import.meta.url)); class A { config; @@ -57,7 +57,7 @@ class A { constructor(e) { this.config = this.#t(e); const t = this.#s(this.config), s = function(e, t, s) { - return d({ + return p({ user: e, pass: t, authentication: s @@ -66,29 +66,29 @@ class A { this.#e = s, this.server = this.#n(); } #t(e) { - const s = n(g, "/../certs/self-signed.key.pem"), o = n(g, "/../certs/self-signed.cert.pem"), i = e.path || process.cwd(), r = e.host || "0.0.0.0", a = e.port || 1900, c = Boolean(e.digest); + const s = t(g, "/../certs/self-signed.key.pem"), n = t(g, "/../certs/self-signed.cert.pem"), o = e.path || process.cwd(), r = e.host || "0.0.0.0", a = e.port || 1900, c = Boolean(e.digest); let h = (e.username || m(16)).toString(), l = (e.password || m(16)).toString(); - const u = Boolean(e.ssl), d = u ? t.readFileSync(e.sslKey || s).toString() : "", A = u ? t.readFileSync(e.sslCert || o).toString() : "", f = Boolean(e.disableAuthentication); + const u = Boolean(e.ssl), p = u ? i.readFileSync(e.sslKey || s).toString() : "", A = u ? i.readFileSync(e.sslCert || n).toString() : "", f = Boolean(e.disableAuthentication); f && (e.rights = e.rights || [ "canRead" ], h = "", l = ""); - const _ = (e.rights || [ "all" ]).filter((e => p.includes(e))), S = `${u ? "https" : "http"}://${r}:${a}`; + const _ = (e.rights || [ "all" ]).filter((e => d.includes(e))), S = `${u ? "https" : "http"}://${r}:${a}`; return { ...e, host: r, - path: i, + path: o, port: a, username: h, digest: c, password: l, ssl: u, sslCert: A, - sslKey: d, + sslKey: p, rights: _, url: S, disableAuthentication: f }; } #n() { - const e = this.config, t = new i.SimpleUserManager, s = t.addUser(e.username, e.password, !1), n = new i.SimplePathPrivilegeManager; + const e = this.config, t = new h.SimpleUserManager, s = t.addUser(e.username, e.password, !1), n = new h.SimplePathPrivilegeManager; n.setRights(s, "/", e.rights); const o = { requireAuthentification: !1, @@ -107,35 +107,35 @@ class A { cert: e.sslCert, key: e.sslKey }); - const r = new i.WebDAVServer(o); - if (r.beforeRequest((async (e, t) => { + const i = new h.WebDAVServer(o); + if (i.beforeRequest((async (e, t) => { const {url: s, headers: n, method: o} = e.request; console.log(">> ", o, s, n), t(); - })), e.disableAuthentication) r.beforeRequest(((e, t) => { + })), e.disableAuthentication) i.beforeRequest(((e, t) => { e.request.method && [ "GET", "HEAD", "PROPFIND", "OPTIONS" ].includes(e.request.method) ? t() : (e.setCode(405), e.exit()); })); else { const e = this.#e; - Array.isArray(this.config.methodsWithoutAuthentication) && this.config.methodsWithoutAuthentication.length ? r.beforeRequest(((t, s) => { + Array.isArray(this.config.methodsWithoutAuthentication) && this.config.methodsWithoutAuthentication.length ? i.beforeRequest(((t, s) => { t.request.method && this.config.methodsWithoutAuthentication?.includes(t.request.method) ? s() : e(t, s); - })) : r.beforeRequest(e); + })) : i.beforeRequest(e); } - return r.beforeRequest(((e, t) => { + return i.beforeRequest(((e, t) => { const {headers: s, method: n} = e.request, {depth: o} = s; "PROPFIND" === n && "0" !== o && "1" !== o ? (e.setCode(403), e.exit()) : t(); - })), r.beforeRequest(function(e) { - const t = new c; - t.use(h()), l(t, e, !1); + })), i.beforeRequest(function(e) { + const t = new r; + t.use(a()), c(t, e, !1); const s = t.callback(); return function(e, t) { const {request: n, response: o} = e, [i, r] = [ n, o ]; if (e.request.method && ![ "GET", "HEAD" ].includes(e.request.method)) return t(); s(i, r); }; - }(e.path)), r.afterRequest(((e, t) => { + }(e.path)), i.afterRequest(((e, t) => { const s = `>> ${e.request.method} ${e.requested.uri} > ${e.response.statusCode} `; console.log(s), t(); - })), r; + })), i; } #s(e) { return e.digest ? "HTTPDigestAuthentication" : "HTTPBasicAuthentication"; @@ -143,7 +143,7 @@ class A { async start() { const e = this.config, {server: t} = this; console.log(Object.fromEntries(Object.entries(e).filter((([e]) => ![ "sslKey", "sslCert" ].includes(e))))), - await t.setFileSystemAsync("/", new i.PhysicalFileSystem(e.path)); + await t.setFileSystemAsync("/", new h.PhysicalFileSystem(e.path)); const s = [ `Server running at ${e.url}`, "Hit CTRL-C to stop the server", "Run with --help to print help" ]; let n; console.log(s.join("\n")), Object.defineProperty(t, "server", { @@ -162,30 +162,30 @@ class A { } } -(async function(t) { - console.log("webdav-cli", "\n"), (t.help || t.h) && (console.log([ "usage: webdav-cli [options]", "", "options:", " --path,-pa Path to folder [process.cwd()]", " --host,-ho Host to use [0.0.0.0]", " --port,-po Port to use [1900]", " --digest,-dg Enable digest authentication [basic]", " --username,-u Username for basic/digest authentication [random]", " --password,-ps Password for basic/digest authentication [random]", " --disableAuthentication,-da The server file becomes read-only without Authentication.[false]", " --ssl,-s Enable https [false]", " --methodsWithoutAuthentication methods Without Authentication[undefined]", " --sslKey Path to ssl key file [self-signed]", " --sslCert Path to ssl cert file [self-signed]", " --help,-h Print this list and exit", " --rights,-r Comma separated values without spaces [all]", "\n 'all', 'canCreate', 'canDelete', 'canMove', 'canRename', \n 'canAppend', 'canWrite', 'canRead', 'canSource', \n 'canGetMimeType', 'canGetSize', 'canListLocks', \n 'canSetLock', 'canRemoveLock', 'canGetAvailableLocks', \n 'canGetLock', 'canAddChild', 'canRemoveChild', \n 'canGetChildren', 'canSetProperty', 'canGetProperty', \n 'canGetProperties', 'canRemoveProperty', 'canGetCreationDate', \n 'canGetLastModifiedDate', 'canGetWebName', 'canGetType'", "", "env:", " WEBDAV_CLI_PATH, WEBDAV_CLI_HOST, WEBDAV_CLI_PORT,", " WEBDAV_CLI_USERNAME, WEBDAV_CLI_PASSWORD, WEBDAV_CLI_DIGEST,", " WEBDAV_CLI_SSL, WEBDAV_CLI_SSL_KEY, WEBDAV_CLI_SSL_CERT,", " WEBDAV_CLI_AUTO_INDEX, WEBDAV_CLI_RIGHTS", " WEBDAV_CLI_DISABLE_AUTHENTICATION", "" ].join("\n")), - e.exit()); - const s = t.rights || t.r, n = s && "string" == typeof s ? s.split(",") : void 0, o = e.env.WEBDAV_CLI_RIGHTS ? e.env.WEBDAV_CLI_RIGHTS.split(",") : void 0, i = { - path: t.path || e.env.WEBDAV_CLI_PATH || t.pa, - host: t.host || e.env.WEBDAV_CLI_HOST || t.ho, - port: Number(t.port || t.po) || parseInt(String(e.env.WEBDAV_CLI_PORT)), - digest: t.digest || t.dg || Boolean(e.env.WEBDAV_CLI_DIGEST), - username: t.username || e.env.WEBDAV_CLI_USERNAME || t.u, - password: t.password || e.env.WEBDAV_CLI_PASSWORD || t.ps, - ssl: t.ssl || t.s || Boolean(e.env.WEBDAV_CLI_SSL), - sslKey: t.sslKey || e.env.WEBDAV_CLI_SSL_KEY, - sslCert: t.sslCert || e.env.WEBDAV_CLI_SSL_CERT, - disableAuthentication: t.disableAuthentication || e.env.WEBDAV_CLI_DISABLE_AUTHENTICATION || t.da, - rights: n || o, - methodsWithoutAuthentication: "string" == typeof t.methodsWithoutAuthentication ? String(t.methodsWithoutAuthentication).split(",") : Array.isArray(t.methodsWithoutAuthentication) ? t.methodsWithoutAuthentication : void 0 +(async function(e) { + console.log("webdav-cli", "\n"), (e.help || e.h) && (console.log([ "usage: webdav-cli [options]", "", "options:", " --path,-pa Path to folder [process.cwd()]", " --host,-ho Host to use [0.0.0.0]", " --port,-po Port to use [1900]", " --digest,-dg Enable digest authentication [basic]", " --username,-u Username for basic/digest authentication [random]", " --password,-ps Password for basic/digest authentication [random]", " --disableAuthentication,-da The server file becomes read-only without Authentication.[false]", " --ssl,-s Enable https [false]", " --methodsWithoutAuthentication methods Without Authentication[undefined]", " --sslKey Path to ssl key file [self-signed]", " --sslCert Path to ssl cert file [self-signed]", " --help,-h Print this list and exit", " --rights,-r Comma separated values without spaces [all]", "\n 'all', 'canCreate', 'canDelete', 'canMove', 'canRename', \n 'canAppend', 'canWrite', 'canRead', 'canSource', \n 'canGetMimeType', 'canGetSize', 'canListLocks', \n 'canSetLock', 'canRemoveLock', 'canGetAvailableLocks', \n 'canGetLock', 'canAddChild', 'canRemoveChild', \n 'canGetChildren', 'canSetProperty', 'canGetProperty', \n 'canGetProperties', 'canRemoveProperty', 'canGetCreationDate', \n 'canGetLastModifiedDate', 'canGetWebName', 'canGetType'", "", "env:", " WEBDAV_CLI_PATH, WEBDAV_CLI_HOST, WEBDAV_CLI_PORT,", " WEBDAV_CLI_USERNAME, WEBDAV_CLI_PASSWORD, WEBDAV_CLI_DIGEST,", " WEBDAV_CLI_SSL, WEBDAV_CLI_SSL_KEY, WEBDAV_CLI_SSL_CERT,", " WEBDAV_CLI_AUTO_INDEX, WEBDAV_CLI_RIGHTS", " WEBDAV_CLI_DISABLE_AUTHENTICATION", "" ].join("\n")), + l.exit()); + const t = e.rights || e.r, s = t && "string" == typeof t ? t.split(",") : void 0, n = l.env.WEBDAV_CLI_RIGHTS ? l.env.WEBDAV_CLI_RIGHTS.split(",") : void 0, o = { + path: e.path || l.env.WEBDAV_CLI_PATH || e.pa, + host: e.host || l.env.WEBDAV_CLI_HOST || e.ho, + port: Number(e.port || e.po) || parseInt(String(l.env.WEBDAV_CLI_PORT)), + digest: e.digest || e.dg || Boolean(l.env.WEBDAV_CLI_DIGEST), + username: e.username || l.env.WEBDAV_CLI_USERNAME || e.u, + password: e.password || l.env.WEBDAV_CLI_PASSWORD || e.ps, + ssl: e.ssl || e.s || Boolean(l.env.WEBDAV_CLI_SSL), + sslKey: e.sslKey || l.env.WEBDAV_CLI_SSL_KEY, + sslCert: e.sslCert || l.env.WEBDAV_CLI_SSL_CERT, + disableAuthentication: e.disableAuthentication || l.env.WEBDAV_CLI_DISABLE_AUTHENTICATION || e.da, + rights: s || n, + methodsWithoutAuthentication: "string" == typeof e.methodsWithoutAuthentication ? String(e.methodsWithoutAuthentication).split(",") : Array.isArray(e.methodsWithoutAuthentication) ? e.methodsWithoutAuthentication : void 0 }; - return e.on("unhandledRejection", (e => { + return l.on("unhandledRejection", (e => { throw console.error(e), e; })), await (async () => { - const e = new A(i); + const e = new A(o); return await e.start(), e; })(); -})(u(e.argv.slice(2), { +})(u(l.argv.slice(2), { string: [ "username", "password" ] })).catch(console.error); //# sourceMappingURL=webdav-cli.cli.js.map diff --git a/dist/webdav-cli.cli.js.map b/dist/webdav-cli.cli.js.map index 39b662e..a08a019 100644 --- a/dist/webdav-cli.cli.js.map +++ b/dist/webdav-cli.cli.js.map @@ -1 +1 @@ -{"version":3,"file":"webdav-cli.cli.js","sources":["../src/create-http-auth.ts","../src/createbasicauth.ts","../src/createdigestauth.ts","../src/webdav-cli.constants.ts","../src/webdav-cli.utils.ts","../src/webdav-cli.server.ts","../src/createhttpauthmiddle.ts","../src/beforelogger.ts","../src/propfindchecker.ts","../src/koa-static-server.ts","../src/afterlogger.ts","../src/main.ts","../src/showhelp.ts","../src/webdav-cli.cli.ts"],"sourcesContent":["import { v2 as webdav } from \"webdav-server\";\n//@ts-ignore\nimport { createbasicauth } from \"./createbasicauth.js\";\nimport { createdigestauth } from \"./createdigestauth.js\";\n\nexport function createhttpauth(options: {\n user: string;\n pass: string;\n authentication: \"HTTPDigestAuthentication\" | \"HTTPBasicAuthentication\";\n}) {\n const realm = \"Default realm\";\n const auth =\n options.authentication === \"HTTPBasicAuthentication\"\n ? createbasicauth(realm, options.user, options.pass)\n : createdigestauth(realm, options.user, options.pass);\n return (ctx: webdav.HTTPRequestContext, next: () => void) => {\n auth.check((req, res) => {\n next();\n })(ctx.request, ctx.response);\n };\n}\n","import httpauth from \"http-auth\";\n\nexport function createbasicauth(\n realm: string,\n user: string,\n pass: string,\n): ReturnType {\n return httpauth.basic(\n {\n realm,\n },\n (username, password, callback) => {\n // Custom authentication method.\n callback(username === user && password === pass);\n },\n );\n}\n","import httpauth from \"http-auth\";\n//@ts-ignore\nimport utils from \"http-auth/src/auth/utils.js\";\n\nexport function createdigestauth(\n realm: string,\n user: string,\n pass: string,\n): ReturnType {\n return httpauth.digest(\n {\n realm,\n },\n // Expecting md5(username:realm:password) in callback.\n (username, callback) => {\n if (username === user) {\n callback(utils.md5(`${username}:${realm}:${pass}`));\n } else {\n callback();\n }\n },\n );\n}\n","import { WebdavCliRights } from \"./webdav-cli.interfaces\";\n\n// export const HOMEPAGE = 'https://github.com/svtslv/webdav-cli';\n\nexport const RIGHTS: WebdavCliRights = [\n \"all\",\n \"canCreate\",\n \"canDelete\",\n \"canMove\",\n \"canRename\",\n \"canAppend\",\n \"canWrite\",\n \"canRead\",\n \"canSource\",\n \"canGetMimeType\",\n \"canGetSize\",\n \"canListLocks\",\n \"canSetLock\",\n \"canRemoveLock\",\n \"canGetAvailableLocks\",\n \"canGetLock\",\n \"canAddChild\",\n \"canRemoveChild\",\n \"canGetChildren\",\n \"canSetProperty\",\n \"canGetProperty\",\n \"canGetProperties\",\n \"canRemoveProperty\",\n \"canGetCreationDate\",\n \"canGetLastModifiedDate\",\n \"canGetWebName\",\n \"canGetType\",\n];\n","export function getRandomString(length: number) {\n return [...Array(Math.ceil(length / 8))]\n .map(() => Math.random().toString(36).slice(-8))\n .join(\"\")\n .slice(-length);\n}\n","import fs from \"fs\";\nimport http from \"http\";\nimport https from \"https\";\nimport { dirname, join } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { v2 as webdav } from \"webdav-server\";\nimport { afterlogger } from \"./afterlogger.js\";\nimport { beforelogger } from \"./beforelogger.js\";\nimport { createhttpauthmiddle } from \"./createhttpauthmiddle.js\";\nimport { koa_static_server } from \"./koa-static-server.js\";\nimport { propfindchecker } from \"./propfindchecker.js\";\nimport { RIGHTS } from \"./webdav-cli.constants.js\";\nimport { WebdavCliConfig, WebdavCliRights } from \"./webdav-cli.interfaces.js\";\nimport { getRandomString } from \"./webdav-cli.utils.js\";\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nexport class WebdavCli {\n config: WebdavCliConfig;\n server: webdav.WebDAVServer;\n #auth_middle: (ctx: webdav.HTTPRequestContext, next: () => void) => void;\n constructor(config: Partial) {\n this.config = this.#getConfig(config);\n const authentication = this.#get_authentication(this.config);\n const auth_middle = createhttpauthmiddle(\n this.config.username,\n this.config.password,\n authentication,\n );\n this.#auth_middle = auth_middle;\n this.server = this.#init();\n }\n\n #getConfig(config: Partial): WebdavCliConfig {\n const selfSignedKey = join(__dirname, \"/../certs/self-signed.key.pem\");\n const selfSignedCert = join(\n __dirname,\n \"/../certs/self-signed.cert.pem\",\n );\n\n const path = config.path || process.cwd();\n const host = config.host || \"0.0.0.0\";\n const port = config.port || 1900;\n\n const digest = Boolean(config.digest);\n let username = (config.username || getRandomString(16)).toString();\n let password = (config.password || getRandomString(16)).toString();\n\n const ssl = Boolean(config.ssl);\n const sslKey = ssl\n ? fs.readFileSync(config.sslKey || selfSignedKey).toString()\n : \"\";\n const sslCert = ssl\n ? fs.readFileSync(config.sslCert || selfSignedCert).toString()\n : \"\";\n\n const disableAuthentication = Boolean(config.disableAuthentication);\n\n if (disableAuthentication) {\n config.rights = config.rights || [\"canRead\"];\n username = \"\";\n password = \"\";\n }\n\n const rights = (config.rights || [\"all\"]).filter(\n (item: WebdavCliRights[number]) => RIGHTS.includes(item),\n );\n const url = `${ssl ? \"https\" : \"http\"}://${host}:${port}`;\n\n return {\n ...config,\n host,\n path,\n port,\n username,\n digest,\n password,\n ssl,\n sslCert,\n sslKey,\n rights,\n url,\n disableAuthentication,\n };\n }\n\n #init(): webdav.WebDAVServer {\n const config = this.config;\n\n const userManager = new webdav.SimpleUserManager();\n const user = userManager.addUser(\n config.username,\n config.password,\n false,\n );\n\n const privilegeManager = new webdav.SimplePathPrivilegeManager();\n privilegeManager.setRights(user, \"/\", config.rights);\n\n const options = {\n requireAuthentification: false,\n httpAuthentication:\n // config.disableAuthentication\n // ?\n {\n askForAuthentication: () => ({}),\n getUser: (\n ctx: any,\n gotUserCallback: (\n arg0: Error,\n arg1: webdav.IUser,\n ) => void,\n ) => {\n userManager.getDefaultUser((defaultUser) => {\n privilegeManager.setRights(\n defaultUser,\n \"/\",\n config.rights,\n );\n //@ts-ignore\n gotUserCallback(null, defaultUser);\n });\n },\n },\n // :\n // new webdav[authentication](userManager, \"Default realm\"),\n // privilegeManager: privilegeManager,\n // https: config.ssl\n // ? { cert: config.sslCert, key: config.sslKey }\n // : undefined,\n port: config.port,\n hostname: config.host,\n };\n config.ssl &&\n Reflect.set(options, \"https\", {\n cert: config.sslCert,\n key: config.sslKey,\n });\n const server = new webdav.WebDAVServer(options);\n\n server.beforeRequest(beforelogger());\n if (!config.disableAuthentication) {\n const auth_middle = this.#auth_middle;\n if (\n Array.isArray(this.config.methodsWithoutAuthentication) &&\n this.config.methodsWithoutAuthentication.length\n ) {\n server.beforeRequest((ctx, next): void => {\n if (\n ctx.request.method &&\n this.config.methodsWithoutAuthentication?.includes(\n ctx.request.method,\n )\n ) {\n next();\n } else {\n auth_middle(ctx, next);\n }\n });\n } else {\n server.beforeRequest(auth_middle);\n }\n } else {\n server.beforeRequest((ctx, next) => {\n const readonly_methods = [\"GET\", \"HEAD\", \"PROPFIND\", \"OPTIONS\"];\n if (\n ctx.request.method &&\n readonly_methods.includes(ctx.request.method)\n ) {\n next();\n } else {\n ctx.setCode(405);\n ctx.exit();\n }\n });\n }\n server.beforeRequest(propfindchecker());\n server.beforeRequest(koa_static_server(config.path));\n server.afterRequest(afterlogger());\n\n return server;\n }\n #get_authentication(config: WebdavCliConfig) {\n return config.digest\n ? \"HTTPDigestAuthentication\"\n : \"HTTPBasicAuthentication\";\n }\n\n async start() {\n const config = this.config;\n const { server } = this;\n console.log(\n Object.fromEntries(\n Object.entries(config).filter(([key]) => {\n return ![\"sslKey\", \"sslCert\"].includes(key);\n }),\n ),\n );\n await server.setFileSystemAsync(\n \"/\",\n new webdav.PhysicalFileSystem(config.path),\n );\n const logs = [\n `Server running at ${config.url}`,\n\n \"Hit CTRL-C to stop the server\",\n \"Run with --help to print help\",\n ];\n\n console.log(logs.join(\"\\n\"));\n let rawhttpserver: http.Server | https.Server | undefined = undefined;\n\n Object.defineProperty(server, \"server\", {\n get() {\n return rawhttpserver;\n },\n set(v) {\n rawhttpserver = v;\n if (!rawhttpserver) {\n return;\n }\n rawhttpserver.on(\"error\", (err) => {\n if (Reflect.get(err, \"code\") === \"EADDRINUSE\") {\n console.error(err);\n rawhttpserver?.listen(\n Math.round(Math.random() * 65535),\n config.host,\n );\n return;\n } else {\n throw err;\n }\n });\n rawhttpserver.on(\"listening\", () => {\n console.log(\n `Server listening on ` +\n JSON.stringify(rawhttpserver?.address()),\n );\n });\n\n return;\n },\n enumerable: true,\n configurable: true,\n });\n\n await server.startAsync(config.port);\n }\n}\nexport type HTTPRequestContext = webdav.HTTPRequestContext;\n","import { HTTPRequestContext } from \"./index\";\nimport { createhttpauth } from \"./create-http-auth.js\";\n\nexport function createhttpauthmiddle(\n username: string,\n password: string,\n authentication: \"HTTPDigestAuthentication\" | \"HTTPBasicAuthentication\",\n): (ctx: HTTPRequestContext, next: () => void) => void {\n return createhttpauth({\n user: username,\n pass: password,\n authentication,\n });\n}\n","import { HTTPRequestContext } from \"./webdav-cli.server.js\";\n\nexport function beforelogger() {\n return async (ctx: HTTPRequestContext, next: () => void) => {\n const { url, headers, method } = ctx.request;\n console.log(\">> \", method, url, headers);\n next();\n };\n}\n","import { HTTPRequestContext } from \"./webdav-cli.server.js\";\n\nexport function propfindchecker() {\n return (arg: HTTPRequestContext, next: () => void) => {\n const { headers, method } = arg.request;\n const { depth } = headers;\n if (method === \"PROPFIND\" && depth !== \"0\" && depth !== \"1\") {\n arg.setCode(403);\n arg.exit();\n } else {\n next();\n }\n };\n}\n","//@ts-ignore\nimport Koa from \"koa\";\nimport logger from \"koa-logger\";\nimport { v2 as webdav } from \"webdav-server\";\n//@ts-ignore\nimport { loadcoremiddles } from \"@masx200/serve-cli\";\nexport function koa_static_server(publicpath: string) {\n const app = new Koa();\n // app.use(async (ctx, next) => {\n // ctx.response.set(\"Access-Control-Allow-Origin\", \"*\");\n // return next();\n // });\n\n // app.use(async (ctx, next) => {\n // await next();\n // if (ctx.method === \"HEAD\") {\n // ctx.res.end();\n // }\n // return;\n // });\n // app.use(range);\n // app.use(cors({}));\n app.use(logger());\n // app.use(conditional());\n\n // app.use(compress({}));\n // app.use(streametag({}));\n // app.use(koaetag({}));\n // app.use(serveIndex(publicpath, { hidden: true }));\n // app.use(servestatic(publicpath, { hidden: true }));\n loadcoremiddles(app, publicpath, false);\n const serverHandler = app.callback();\n return function middleware(\n ctx: webdav.HTTPRequestContext,\n next: () => void,\n ) {\n const { request, response } = ctx;\n const [req, res] = [request, response];\n if (\n ctx.request.method &&\n ![\"GET\", \"HEAD\"].includes(ctx.request.method)\n ) {\n return next();\n }\n serverHandler(req, res);\n\n return;\n };\n}\n","import { HTTPRequestContext } from \"./webdav-cli.server.js\";\n\nexport function afterlogger() {\n return (arg: HTTPRequestContext, next: () => void) => {\n const log = `>> ${arg.request.method} ${arg.requested.uri} > ${arg.response.statusCode} `;\n // server.emit('log', null, null, '/', log);\n console.log(log);\n next();\n };\n}\n","import process from \"process\";\nimport minimist from \"minimist\";\nimport { WebdavCli } from \"./webdav-cli.server.js\";\nimport { showhelp } from \"./showhelp.js\";\nimport { WebdavCliConfig } from \"./webdav-cli.interfaces.js\";\n\nexport async function main(\n argv: Partial,\n) {\n console.log(\"webdav-cli\", \"\\n\");\n if (argv.help || argv.h) {\n showhelp();\n }\n // if (argv.version || argv.v) {\n // console.log(\"Version: \" + require(\"../package.json\").version, \"\\n\");\n // process.exit();\n // }\n const rights = argv.rights || argv.r;\n const argvRights =\n rights && typeof rights === \"string\" ? rights.split(\",\") : undefined;\n const envRights = process.env.WEBDAV_CLI_RIGHTS\n ? process.env.WEBDAV_CLI_RIGHTS.split(\",\")\n : undefined;\n const config = {\n path: argv.path || process.env.WEBDAV_CLI_PATH || argv.pa,\n host: argv.host || process.env.WEBDAV_CLI_HOST || argv.ho,\n port:\n Number(argv.port || argv.po) ||\n parseInt(String(process.env.WEBDAV_CLI_PORT)),\n digest:\n argv.digest || argv.dg || Boolean(process.env.WEBDAV_CLI_DIGEST),\n username: argv.username || process.env.WEBDAV_CLI_USERNAME || argv.u,\n password: argv.password || process.env.WEBDAV_CLI_PASSWORD || argv.ps,\n ssl: argv.ssl || argv.s || Boolean(process.env.WEBDAV_CLI_SSL),\n sslKey: argv.sslKey || process.env.WEBDAV_CLI_SSL_KEY,\n sslCert: argv.sslCert || process.env.WEBDAV_CLI_SSL_CERT,\n disableAuthentication:\n argv.disableAuthentication ||\n process.env.WEBDAV_CLI_DISABLE_AUTHENTICATION ||\n argv.da,\n rights: argvRights || envRights,\n methodsWithoutAuthentication:\n \"string\" === typeof argv.methodsWithoutAuthentication\n ? String(argv.methodsWithoutAuthentication).split(\",\")\n : Array.isArray(argv.methodsWithoutAuthentication)\n ? argv.methodsWithoutAuthentication\n : undefined,\n };\n process.on(\"unhandledRejection\", (e) => {\n console.error(e);\n throw e;\n });\n const run = async () => {\n //@ts-ignore\n const webdavCli = new WebdavCli(config);\n await webdavCli.start();\n return webdavCli;\n };\n return await run();\n}\n","import process from \"process\";\nexport function showhelp() {\n console.log(\n [\n \"usage: webdav-cli [options]\",\n \"\",\n \"options:\",\n \" --path,-pa Path to folder [process.cwd()]\",\n \" --host,-ho Host to use [0.0.0.0]\",\n \" --port,-po Port to use [1900]\",\n \" --digest,-dg Enable digest authentication [basic]\",\n \" --username,-u Username for basic/digest authentication [random]\",\n \" --password,-ps Password for basic/digest authentication [random]\",\n \" --disableAuthentication,-da The server file becomes read-only without Authentication.[false]\",\n \" --ssl,-s Enable https [false]\",\n \" --methodsWithoutAuthentication methods Without Authentication[undefined]\",\n \" --sslKey Path to ssl key file [self-signed]\",\n \" --sslCert Path to ssl cert file [self-signed]\",\n \" --help,-h Print this list and exit\",\n // \" --version,-v Print the version and exit.\",\n \" --rights,-r Comma separated values without spaces [all]\",\n `\n 'all', 'canCreate', 'canDelete', 'canMove', 'canRename', \n 'canAppend', 'canWrite', 'canRead', 'canSource', \n 'canGetMimeType', 'canGetSize', 'canListLocks', \n 'canSetLock', 'canRemoveLock', 'canGetAvailableLocks', \n 'canGetLock', 'canAddChild', 'canRemoveChild', \n 'canGetChildren', 'canSetProperty', 'canGetProperty', \n 'canGetProperties', 'canRemoveProperty', 'canGetCreationDate', \n 'canGetLastModifiedDate', 'canGetWebName', 'canGetType'`,\n \"\",\n \"env:\",\n \" WEBDAV_CLI_PATH, WEBDAV_CLI_HOST, WEBDAV_CLI_PORT,\",\n \" WEBDAV_CLI_USERNAME, WEBDAV_CLI_PASSWORD, WEBDAV_CLI_DIGEST,\",\n \" WEBDAV_CLI_SSL, WEBDAV_CLI_SSL_KEY, WEBDAV_CLI_SSL_CERT,\",\n \" WEBDAV_CLI_AUTO_INDEX, WEBDAV_CLI_RIGHTS\",\n \" WEBDAV_CLI_DISABLE_AUTHENTICATION\",\n \"\",\n ].join(\"\\n\"),\n );\n process.exit();\n}\n","import { main } from \"./main\";\nimport minimist from \"minimist\";\n// #!/usr/bin/env node\nimport process from \"process\";\nconst argv = minimist(process.argv.slice(2),{string:[\"username\",\"password\"]});\nmain(argv).catch(console.error);\n"],"names":["createhttpauth","options","realm","auth","authentication","user","pass","httpauth","basic","username","password","callback","createbasicauth","digest","utils","md5","createdigestauth","ctx","next","check","req","res","request","response","RIGHTS","getRandomString","length","Array","Math","ceil","map","random","toString","slice","join","__dirname","dirname","fileURLToPath","url","WebdavCli","config","server","auth_middle","constructor","this","getConfig","get_authentication","createhttpauthmiddle","init","selfSignedKey","selfSignedCert","path","process","cwd","host","port","Boolean","ssl","sslKey","fs","readFileSync","sslCert","disableAuthentication","rights","filter","item","includes","userManager","webdav","SimpleUserManager","addUser","privilegeManager","SimplePathPrivilegeManager","setRights","requireAuthentification","httpAuthentication","askForAuthentication","getUser","gotUserCallback","getDefaultUser","defaultUser","hostname","Reflect","set","cert","key","WebDAVServer","beforeRequest","async","headers","method","console","log","setCode","exit","isArray","methodsWithoutAuthentication","arg","depth","publicpath","app","Koa","use","logger","loadcoremiddles","serverHandler","koa_static_server","afterRequest","requested","uri","statusCode","start","Object","fromEntries","entries","setFileSystemAsync","PhysicalFileSystem","logs","rawhttpserver","defineProperty","get","v","on","err","error","listen","round","JSON","stringify","address","enumerable","configurable","startAsync","argv","help","h","r","argvRights","split","undefined","envRights","env","WEBDAV_CLI_RIGHTS","WEBDAV_CLI_PATH","pa","WEBDAV_CLI_HOST","ho","Number","po","parseInt","String","WEBDAV_CLI_PORT","dg","WEBDAV_CLI_DIGEST","WEBDAV_CLI_USERNAME","u","WEBDAV_CLI_PASSWORD","ps","s","WEBDAV_CLI_SSL","WEBDAV_CLI_SSL_KEY","WEBDAV_CLI_SSL_CERT","WEBDAV_CLI_DISABLE_AUTHENTICATION","da","e","webdavCli","run","main","minimist","string","catch"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAKM,SAAUA,EAAeC;IAK3B,MAAMC,IAAQ,iBACRC,IACyB,8BAA3BF,EAAQG,0BCTZF,GACAG,GACAC;QAEA,OAAOC,EAASC,MACZ;YACIN;YAEJ,CAACO,GAAUC,GAAUC;YAEjBA,EAASF,MAAaJ,KAAQK,MAAaJ;AAAK;AAG5D,KDHcM,CAAgBV,GAAOD,EAAQI,MAAMJ,EAAQK,iBERvDJ,GACAG,GACAC;QAEA,OAAOC,EAASM,OACZ;YACIX;YAGJ,CAACO,GAAUE;YACHF,MAAaJ,IACbM,EAASG,EAAMC,IAAI,GAAGN,KAAYP,KAASI,QAE3CK;AACH;AAGb,K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C,CADaC,EAASpH,EAAQiF,KAAKpG,MAAM,IAAG;IAACwI,QAAO,EAAC,YAAW;IACrDC,MAAM/E,QAAQiC"} \ No newline at end of file +{"version":3,"file":"webdav-cli.cli.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/package.json b/package.json index 86c0b68..b94ff1a 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@rollup/plugin-commonjs": "^26.0.1", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", + "@swc/core": "^1.7.26", "@types/etag": "^1.8.0", "@types/fresh": "^0.5.0", "@types/http-auth": "^4.1.0", @@ -56,6 +57,7 @@ "rollup": "^3.29.5", "rollup-external-modules": "^2.0.0", "rollup-plugin-node-externals": "^7.0.0", + "rollup-plugin-swc": "^0.2.1", "rollup-plugin-terser": "^7.0.2", "rollup-plugin-ts": "^3.4.5", "terser": "^5.14.2", diff --git a/rollup.config.mjs b/rollup.config.mjs index f1a1b62..83386e4 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -3,8 +3,8 @@ import { defineConfig } from "rollup"; import json from "@rollup/plugin-json"; import resolve from "@rollup/plugin-node-resolve"; import rollupExternalModules from "rollup-external-modules"; +import swc from "rollup-plugin-swc"; import { terser } from "rollup-plugin-terser"; -import ts from "rollup-plugin-ts"; const banner = `#!/usr/bin/env node`; const terserplugin = terser({ @@ -32,7 +32,7 @@ export default defineConfig([ format: "esm", }, ], - plugins: [ts(), resolve(), commonjs(), terserplugin, json()], + plugins: [swcplugin(), resolve(), commonjs(), terserplugin, json()], }, { external: rollupExternalModules, @@ -46,6 +46,16 @@ export default defineConfig([ format: "esm", }, ], - plugins: [ts(), resolve(), commonjs(), terserplugin, json()], + plugins: [swcplugin(), resolve(), commonjs(), terserplugin, json()], }, ]); +function swcplugin() { + return swc.default({ + jsc: { + parser: { + syntax: "typescript", + }, + target: "esnext", + }, + }); +} diff --git a/src/create-http-auth.ts b/src/create-http-auth.ts index c9bb94c..63a1698 100644 --- a/src/create-http-auth.ts +++ b/src/create-http-auth.ts @@ -1,7 +1,7 @@ -import { v2 as webdav } from "webdav-server"; //@ts-ignore -import { createbasicauth } from "./createbasicauth.js"; -import { createdigestauth } from "./createdigestauth.js"; +import { createbasicauth } from "./createbasicauth.ts"; +import { createdigestauth } from "./createdigestauth.ts"; +import { v2 as webdav } from "webdav-server"; export function createhttpauth(options: { user: string; diff --git a/src/createhttpauthmiddle.ts b/src/createhttpauthmiddle.ts index c8a7390..3963997 100644 --- a/src/createhttpauthmiddle.ts +++ b/src/createhttpauthmiddle.ts @@ -1,5 +1,5 @@ -import { HTTPRequestContext } from "./index"; -import { createhttpauth } from "./create-http-auth.js"; +import { HTTPRequestContext } from "./index.ts"; +import { createhttpauth } from "./create-http-auth.ts"; export function createhttpauthmiddle( username: string, diff --git a/src/index.ts b/src/index.ts index fd08cce..ceeb9e2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ -export * from "./webdav-cli.constants.js"; -export * from "./webdav-cli.interfaces.js"; -export * from "./webdav-cli.server.js"; -export * from "./webdav-cli.utils.js"; -export { main } from "./main"; +export * from "./webdav-cli.constants.ts"; +export * from "./webdav-cli.interfaces.ts"; +export * from "./webdav-cli.server.ts"; +export * from "./webdav-cli.utils.ts"; +export { main } from "./main.ts"; diff --git a/src/main.ts b/src/main.ts index 42b5825..68185ef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,8 @@ -import process from "process"; +import { WebdavCli } from "./webdav-cli.server.ts"; +import { WebdavCliConfig } from "./webdav-cli.interfaces.ts"; import minimist from "minimist"; -import { WebdavCli } from "./webdav-cli.server.js"; -import { showhelp } from "./showhelp.js"; -import { WebdavCliConfig } from "./webdav-cli.interfaces.js"; +import process from "process"; +import { showhelp } from "./showhelp.ts"; export async function main( argv: Partial, diff --git a/src/webdav-cli.cli.ts b/src/webdav-cli.cli.ts index 44904cd..2eacd05 100644 --- a/src/webdav-cli.cli.ts +++ b/src/webdav-cli.cli.ts @@ -1,4 +1,4 @@ -import { main } from "./main"; +import { main } from "./main.ts"; import minimist from "minimist"; // #!/usr/bin/env node import process from "process"; diff --git a/src/webdav-cli.server.ts b/src/webdav-cli.server.ts index 6f74cfc..54949ef 100644 --- a/src/webdav-cli.server.ts +++ b/src/webdav-cli.server.ts @@ -1,17 +1,18 @@ +import { WebdavCliConfig, WebdavCliRights } from "./webdav-cli.interfaces.ts"; +import { dirname, join } from "path"; + +import { RIGHTS } from "./webdav-cli.constants.ts"; +import { afterlogger } from "./afterlogger.ts"; +import { beforelogger } from "./beforelogger.ts"; +import { createhttpauthmiddle } from "./createhttpauthmiddle.ts"; +import { fileURLToPath } from "url"; import fs from "fs"; +import { getRandomString } from "./webdav-cli.utils.ts"; import http from "http"; import https from "https"; -import { dirname, join } from "path"; -import { fileURLToPath } from "url"; +import { koa_static_server } from "./koa-static-server.ts"; +import { propfindchecker } from "./propfindchecker.ts"; import { v2 as webdav } from "webdav-server"; -import { afterlogger } from "./afterlogger.js"; -import { beforelogger } from "./beforelogger.js"; -import { createhttpauthmiddle } from "./createhttpauthmiddle.js"; -import { koa_static_server } from "./koa-static-server.js"; -import { propfindchecker } from "./propfindchecker.js"; -import { RIGHTS } from "./webdav-cli.constants.js"; -import { WebdavCliConfig, WebdavCliRights } from "./webdav-cli.interfaces.js"; -import { getRandomString } from "./webdav-cli.utils.js"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); export class WebdavCli { diff --git a/tsconfig.json b/tsconfig.json index 2aa3f56..3fa02bc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,8 @@ "sourceMap": false, "outDir": "./dist", "baseUrl": "./", - "skipLibCheck": true + "skipLibCheck": true, + "allowImportingTsExtensions": true }, "include": ["src/**/*", "test/**/*"], "exclude": ["node_modules", "dist", "test", "**/*spec.ts"]