Skip to content

Commit

Permalink
更新到2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
masx200 committed Sep 1, 2020
1 parent 25f9114 commit 0d30d5e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ npx @masx200/webdav-cli [options]
npx @masx200/webdav-cli --help
```

```bash
```txt
usage: webdav-cli [options]
options:
Expand Down Expand Up @@ -79,7 +79,7 @@ env:

First, you need to make sure that openssl is installed correctly, and you have `key.pem` and `cert.pem` files. You can generate them using this command:

```bash
```shell
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
```

Expand Down
7 changes: 6 additions & 1 deletion dist/webdav-cli.cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ if (argv.help) {
' --digest Enable digest authentication [basic]',
' --username Username for basic/digest authentication [random]',
' --password Password for basic/digest authentication [random]',
' --directory Show directory listings [false]',
' --autoIndex Display autoIndex [false]',
' --ssl Enable https [false]',
' --sslKey Path to ssl key file [self-signed]',
' --sslCert Path to ssl cert file [self-signed]',
Expand All @@ -41,7 +43,8 @@ if (argv.help) {
' 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_RIGHTS, WEBDAV_CLI_DISABLE_AUTHENTICATION',
' WEBDAV_CLI_DIRECTORY, WEBDAV_CLI_AUTO_INDEX, WEBDAV_CLI_RIGHTS',
' WEBDAV_CLI_DISABLE_AUTHENTICATION',
'',
].join('\n'),
);
Expand All @@ -65,6 +68,8 @@ const config = {
digest: argv.digest || Boolean(process.env.WEBDAV_CLI_DIGEST),
username: argv.username || process.env.WEBDAV_CLI_USERNAME,
password: argv.password || process.env.WEBDAV_CLI_PASSWORD,
directory: argv.directory || process.env.WEBDAV_CLI_DIRECTORY,
autoIndex: argv.autoIndex || process.env.WEBDAV_CLI_AUTO_INDEX,
ssl: argv.ssl || Boolean(process.env.WEBDAV_CLI_SSL),
sslKey: argv.sslKey || process.env.WEBDAV_CLI_SSL_KEY,
sslCert: argv.sslCert || process.env.WEBDAV_CLI_SSL_CERT,
Expand Down
2 changes: 2 additions & 0 deletions dist/webdav-cli.interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface WebdavCliConfig {
rights: WebdavCliRights;
disableAuthentication?: boolean;
url?: string;
directory?: boolean;
autoIndex?: boolean;
}
export interface WebdavCliServer extends webdav.WebDAVServer {
config: WebdavCliConfig;
Expand Down
4 changes: 4 additions & 0 deletions dist/webdav-cli.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class WebdavCli {
webdav_cli_constants_1.RIGHTS.includes(item),
);
const url = `${ssl ? 'https' : 'http'}://${host}:${port}`;
const directory = Boolean(config.directory);
const autoIndex = Boolean(config.autoIndex);
return {
host,
path,
Expand All @@ -59,6 +61,8 @@ class WebdavCli {
rights,
url,
disableAuthentication,
directory,
autoIndex,
};
}
async start() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"registry": "https://registry.npmjs.com"
},
"name": "@masx200/webdav-cli",
"version": "1.0.4",
"version": "2.0.0",
"description": "A simple zero-configuration command-line webdav server",
"license": "MIT",
"keywords": [
Expand Down
7 changes: 6 additions & 1 deletion src/webdav-cli.cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ if (argv.help) {
' --digest Enable digest authentication [basic]',
' --username Username for basic/digest authentication [random]',
' --password Password for basic/digest authentication [random]',
' --directory Show directory listings [false]',
' --autoIndex Display autoIndex [false]',
' --ssl Enable https [false]',
' --sslKey Path to ssl key file [self-signed]',
' --sslCert Path to ssl cert file [self-signed]',
Expand All @@ -44,7 +46,8 @@ if (argv.help) {
' 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_RIGHTS, WEBDAV_CLI_DISABLE_AUTHENTICATION',
' WEBDAV_CLI_DIRECTORY, WEBDAV_CLI_AUTO_INDEX, WEBDAV_CLI_RIGHTS',
' WEBDAV_CLI_DISABLE_AUTHENTICATION',
'',
].join('\n'),
);
Expand All @@ -71,6 +74,8 @@ const config = {
digest: argv.digest || Boolean(process.env.WEBDAV_CLI_DIGEST),
username: argv.username || process.env.WEBDAV_CLI_USERNAME,
password: argv.password || process.env.WEBDAV_CLI_PASSWORD,
directory: argv.directory || process.env.WEBDAV_CLI_DIRECTORY,
autoIndex: argv.autoIndex || process.env.WEBDAV_CLI_AUTO_INDEX,
ssl: argv.ssl || Boolean(process.env.WEBDAV_CLI_SSL),
sslKey: argv.sslKey || process.env.WEBDAV_CLI_SSL_KEY,
sslCert: argv.sslCert || process.env.WEBDAV_CLI_SSL_CERT,
Expand Down
2 changes: 2 additions & 0 deletions src/webdav-cli.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface WebdavCliConfig {
rights: WebdavCliRights;
disableAuthentication?: boolean;
url?: string;
directory?: boolean;
autoIndex?: boolean;
}

export interface WebdavCliServer extends webdav.WebDAVServer {
Expand Down
34 changes: 22 additions & 12 deletions src/webdav-cli.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class WebdavCli {
config.rights || ['all']
).filter((item: WebdavCliRights[number]) => RIGHTS.includes(item));
const url = `${ssl ? 'https' : 'http'}://${host}:${port}`;
const directory = Boolean(config.directory);
const autoIndex = Boolean(config.autoIndex);

return {
host,
Expand All @@ -65,6 +67,8 @@ export class WebdavCli {
rights,
url,
disableAuthentication,
directory,
autoIndex,
};
}

Expand Down Expand Up @@ -113,18 +117,24 @@ export class WebdavCli {
server.config = config;

server.beforeRequest(async (ctx, next) => {
/* const isBrowser = ctx.request.headers['user-agent'].search('Mozilla/5.0') !== -1;
if(isBrowser) {
try {
const resource = await server.getResourceAsync(ctx, ctx.requested.uri);
const list = await resource.readDirAsync();
const uri = ctx.requested.uri.slice(-1) === '/' ? ctx.requested.uri : ctx.requested.uri + '/';
const up = `<a href="${ uri.split('/').slice(0, -2).join('/') || '/' }">..</a><br/>`;
const html = up + list.map(item => `<a href="${ uri + item }">${ item }</a><br/>`).join('');
ctx.response.setHeader('Content-Type', 'text/html');
ctx.response.end(html);
} catch {}
}*/
/* if (config.directory) {
if(isBrowser) { const isBrowser = ctx.request.headers['user-agent'].search('Mozilla/5.0') !== -1;
try { if(isBrowser) {
const resource = await server.getResourceAsync(ctx, ctx.requested.uri); try {
const list = await resource.readDirAsync(); const resource = await server.getResourceAsync(ctx, ctx.requested.uri);
const uri = ctx.requested.uri.slice(-1) === '/' ? ctx.requested.uri : ctx.requested.uri + '/'; const list = await resource.readDirAsync();
const up = `<a href="${ uri.split('/').slice(0, -2).join('/') || '/' }">..</a><br/>`; const uri = ctx.requested.uri.slice(-1) === '/' ? ctx.requested.uri : ctx.requested.uri + '/';
const html = up + list.map(item => `<a href="${ uri + item }">${ item }</a><br/>`).join(''); if(config.autoIndex && list.includes('index.html')) {
ctx.response.setHeader('Content-Type', 'text/html'); ctx.requested.path = `${uri}index.html` as any;
ctx.response.end(html); } else {
} catch {} const up = `<a href="${ uri.split('/').slice(0, -2).join('/') || '/' }">..</a><br/>`;
const html = up + list.map(item => `<a href="${ uri + item }">${ item }</a><br/>`).join('');
// ctx.response.setHeader('Content-Type', 'text/html;charset=UTF-8');
ctx.response.end(`<html><head><meta charset="UTF-8"></head><body>${html}</body></html>`);
}
} catch {}
}
} }*/
console.log(
ctx.request.method,
ctx.request.url,
Expand Down

0 comments on commit 0d30d5e

Please sign in to comment.