Skip to content

Commit

Permalink
整理结构
Browse files Browse the repository at this point in the history
  • Loading branch information
masx200 committed Jun 7, 2021
1 parent 5fad2d6 commit 34e728b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
3 changes: 1 addition & 2 deletions dist/webdav-cli.cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ const config = {
};
const run = async () => {
const webdavCli = new webdav_cli_server_1.WebdavCli(config);
const webdavCliServer = await webdavCli.start();
console.log(webdavCliServer.config);
await webdavCli.start();
};
run();
process_1.default.on("unhandledRejection", (e) => {
Expand Down
7 changes: 5 additions & 2 deletions dist/webdav-cli.server.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { WebdavCliServer, WebdavCliConfig } from "./webdav-cli.interfaces";
import { v2 as webdav } from "webdav-server";
import { WebdavCliConfig } from "./webdav-cli.interfaces";
export declare class WebdavCli {
config: WebdavCliConfig;
server: webdav.WebDAVServer;
constructor(config: Partial<WebdavCliConfig>);
getConfig(config: Partial<WebdavCliConfig>): WebdavCliConfig;
start(): Promise<WebdavCliServer>;
init(): webdav.WebDAVServer;
start(): Promise<void>;
}
12 changes: 9 additions & 3 deletions dist/webdav-cli.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ const webdav_cli_utils_1 = require("./webdav-cli.utils");
const webdav_cli_constants_1 = require("./webdav-cli.constants");
class WebdavCli {
config;
server;
constructor(config) {
this.config = this.getConfig(config);
this.server = this.init();
}
getConfig(config) {
const selfSignedKey = path_1.join(
Expand Down Expand Up @@ -107,7 +109,7 @@ class WebdavCli {
directory,
};
}
async start() {
init() {
const config = this.config;
const userManager = new webdav_server_1.v2.SimpleUserManager();
const user = userManager.addUser(
Expand Down Expand Up @@ -147,7 +149,6 @@ class WebdavCli {
port: config.port,
hostname: config.host,
});
server.config = config;
server.beforeRequest(async (ctx, next) => {
const { url, headers, method } = ctx.request;
console.log(">> ", { method, url }, headers);
Expand All @@ -168,6 +169,12 @@ class WebdavCli {
console.log(log);
next();
});
return server;
}
async start() {
const config = this.config;
const { server } = this;
console.log(config);
await server.setFileSystemAsync(
"/",
new webdav_server_1.v2.PhysicalFileSystem(config.path),
Expand All @@ -183,7 +190,6 @@ class WebdavCli {
"Run with --help to print help",
];
console.log(logs.join("\n"));
return server;
}
}
exports.WebdavCli = WebdavCli;
5 changes: 2 additions & 3 deletions src/webdav-cli.cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ const config = {
const run = async () => {
const webdavCli = new WebdavCli(config);

const webdavCliServer = await webdavCli.start();
// webdavCliServer.on('log', (ctx, fs, path, log) => console.log(log));
console.log(webdavCliServer.config);
// console.log(webdavCli.config);
await webdavCli.start();
};

run();
Expand Down
17 changes: 11 additions & 6 deletions src/webdav-cli.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {

export class WebdavCli {
config: WebdavCliConfig;

server: webdav.WebDAVServer;
constructor(config: Partial<WebdavCliConfig>) {
this.config = this.getConfig(config);
this.server = this.init();
}

getConfig(config: Partial<WebdavCliConfig>): WebdavCliConfig {
Expand Down Expand Up @@ -70,7 +71,7 @@ export class WebdavCli {
};
}

async start(): Promise<WebdavCliServer> {
init(): webdav.WebDAVServer {
const config = this.config;

const userManager = new webdav.SimpleUserManager();
Expand Down Expand Up @@ -110,9 +111,9 @@ export class WebdavCli {
: undefined,
port: config.port,
hostname: config.host,
}) as WebdavCliServer;
});

server.config = config;
// server.config = config;

server.beforeRequest(async (ctx, next) => {
/* if (config.directory) {
Expand Down Expand Up @@ -154,6 +155,12 @@ export class WebdavCli {
next();
});

return server;
}
async start() {
const config = this.config;
const { server } = this;
console.log(config);
await server.setFileSystemAsync(
"/",
new webdav.PhysicalFileSystem(config.path),
Expand All @@ -171,7 +178,5 @@ export class WebdavCli {
];

console.log(logs.join("\n"));

return server;
}
}

0 comments on commit 34e728b

Please sign in to comment.