npm-WebDAV-Server

WebDAV Server for npm
授权协议 Unlicense License
开发语言 JavaScript
所属分类 Web应用开发、 常用JavaScript包
软件类型 开源软件
地区 不详
投 递 者 司马飞
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

WebDAV Server for npm

Code Climate Rate

Description

This server can use physical resources (files and folders on a hard drive, for instance), virtual resources (in-memory files and folders), processed/computed resources (for instance a file which provide the content of a remote web page), customized resources (whatever you created, whatever you can imagine), and use all of them on the same server instance. And it's easy to integrate in your JavaScript code!

You can use it to provide human readable content, easily manageable thanks to the WebDAV clients, or use a temporary and virtual file system to share information between running programs, or store crypted documents while still being able to use them as if they were not crypted (take a look at cwdav), etc...

This is a fully configurable server. You can use you own user manager, your own resources, your own HTTP methods, your own way to save the state of the server, etc... Find more in the documentation.

Project information

Here are some project related links :

You can find a list of file systems here :

This project rely upon the RFC4918.

This is an active project. Do not hesitate to post an issue if you have an idea or if you encounter a problem.

The project comes with two versions : the obselete version 1 and the version 2. Prefer using the version 2. At the moment, for compatibility issues, to access the version you must use the v2 namespace.

Install

npm install webdav-server

Quick usage

Very simple usage :

// TypeScript
import { v2 as webdav } from 'webdav-server'
// JavaScript
const webdav = require('webdav-server').v2;

const server = new webdav.WebDAVServer({
    port: 1900
});

server.start(() => console.log('READY'));

With some logs :

// TypeScript
import { v2 as webdav } from 'webdav-server'
// JavaScript
const webdav = require('webdav-server').v2;

const server = new webdav.WebDAVServer({
    port: 1900
});

server.afterRequest((arg, next) => {
    // Display the method, the URI, the returned status code and the returned message
    console.log('>>', arg.request.method, arg.requested.uri, '>', arg.response.statusCode, arg.response.statusMessage);
    // If available, display the body of the response
    console.log(arg.responseBody);
    next();
});

server.start(() => console.log('READY'));

With a user manager, privilege manager and serialization (save/load the state of the server) :

// TypeScript
import { v2 as webdav } from 'webdav-server'
// JavaScript
const webdav = require('webdav-server').v2;

// User manager (tells who are the users)
const userManager = new webdav.SimpleUserManager();
const user = userManager.addUser('username', 'password', false);

// Privilege manager (tells which users can access which files/folders)
const privilegeManager = new webdav.SimplePathPrivilegeManager();
privilegeManager.setRights(user, '/', [ 'all' ]);

const server = new webdav.WebDAVServer({
    // HTTP Digest authentication with the realm 'Default realm'
    httpAuthentication: new webdav.HTTPDigestAuthentication(userManager, 'Default realm'),
    privilegeManager: privilegeManager,
    port: 2000, // Load the server on the port 2000 (if not specified, default is 1900)
    autoSave: { // Will automatically save the changes in the 'data.json' file
        treeFilePath: 'data.json'
    }
});

// Try to load the 'data.json' file
server.autoLoad((e) => {
    if(e)
    { // Couldn't load the 'data.json' (file is not accessible or it has invalid content)
        server.rootFileSystem().addSubTree(server.createExternalContext(), {
            'folder1': {                                // /folder1
                'file1.txt': webdav.ResourceType.File,  // /folder1/file1.txt
                'file2.txt': webdav.ResourceType.File   // /folder1/file2.txt
            },
            'file0.txt': webdav.ResourceType.File       // /file0.txt
        })
    }
    
    server.start(() => console.log('READY'));
})

Within Express :

// TypeScript
import { v2 as webdav } from 'webdav-server'
import * as express from 'express'
// JavaScript
const webdav = require('webdav-server').v2;
const express = require('express');

const server = new webdav.WebDAVServer();
const app = express();

// Mount the WebDAVServer instance
app.use(webdav.extensions.express('/my/sub/path', server));
app.listen(1901); // Start the Express server

More examples at the example page of the wiki.

More information/possibilities in the documentation.

 相关资料
  • WebDAV CGI 实现了 WebDAV 服务器协议,兼容 Classes 1、2 和 3。

  • webdav-aliyundriver 实现了阿里云盘的 webdav 协议,只需要简单的配置一下,就可以让阿里云盘变身为webdav协议的文件服务器。 基于此,你可以把阿里云盘挂载为Windows、Linux、Mac系统的磁盘,可以通过NAS系统做文件管理或文件同步。 功能: 查看文件夹、查看文件 文件移动目录 文件重命名 文件下载 文件删除 文件上传(支持大文件自动分批上传) 支持超大文件上传

  • WebDAV-Sync 可以实现本地目录和 WebDAV 服务之间的同步。提供 Ant Task 和命令行工具。

  • neon 是一个 HTTP 和 WebDAV 客户端的C语言开发包,支持 Linux/Unix。提供 HTTP/1.1 和 WebDAV 方法的高级接口以及底层的 HTTP 请求/回应处理,可轻松实现新的方法。

  • sinatra-webdav 是基于 Sinatra 的 WebDAV 实现。 安装: $ git clone git@github.com:fork/sinatra-webdav.git$ cd sinatra-webdav$ bundle install

  • WebDAV-Servlet 是一个 Java 的 Servlet ,实现了对 WebDAV 协议的服务端支持。