Skip to content

Templates for customization [v2]

Adrien Castex edited this page Nov 17, 2019 · 1 revision

Description

This page contains the templates to copy/paste to ease customization. For instance, when creating a new file system, the common thing done is to copy/paste an example then to edit it in order to achieve the desired behaviour. This page will allow to copy/paste a template already ready for customization.

Custom File System

Go to documentation page.

Javascript

const webdav = require('webdav-server').v2;

// Serializer
function MyFileSystemSerializer()
{
    return {
        uid()
        {
            return "MyFileSystemSerializer_1.0.0";
        },
        serialize(fs, callback)
        {
            callback(null, {
                arg1: fs.arg1,
                arg2: fs.arg2,
                resources: fs.resources
            });
        },
        unserialize(serializedData, callback)
        {
            const fs = new MyFileSystem(serializedData.arg1, serializedData.arg2);
            fs.resources = serializedData.resources;
            for(const path in fs.resources)
            {
                fs.resources[path] = new MyFileSystemResource(fs.resources[path]);
            }

            callback(null, fs);
        },
        constructor: MyFileSystemSerializer
    }
}

// Internal resource
function MyFileSystemResource(data /* ?: any */)
{
    this.constructor = MyFileSystemResource;
    this.props = new webdav.LocalPropertyManager(data ? data.props : undefined);
    this.locks = new webdav.LocalPropertyManager();
}

// File system
function MyFileSystem(arg1, arg2)
{
    const r = new webdav.FileSystem(new MyFileSystemSerializer());
    r.constructor = MyFileSystem;
    r.resources = {};

    r.arg1 = arg1;
    r.arg2 = arg2;

    // r._fastExistCheck = function(ctx /* : RequestContext*/, path /* : Path*/, callback /* : (exists : boolean*/) => void) {}
    // r._create = function(path /* : Path*/, ctx /* : CreateInfo*/, callback /* : SimpleCallback*/) {}
    // r._etag = function(path /* : Path*/, ctx /* : ETagInfo*/, callback /* : ReturnCallback<string>*/) {}
    // r._delete = function(path /* : Path*/, ctx /* : DeleteInfo*/, callback /* : SimpleCallback*/) {}
    // r._openWriteStream = function(path /* : Path*/, ctx /* : OpenWriteStreamInfo*/, callback /* : ReturnCallback<Writable>*/) {}
    // r._openReadStream = function(path /* : Path*/, ctx /* : OpenReadStreamInfo*/, callback /* : ReturnCallback<Readable>*/) {}
    // r._move = function(pathFrom /* : Path*/, pathTo /* : Path*/, ctx /* : MoveInfo*/, callback /* : ReturnCallback<boolean>*/) {}
    // r._copy = function(pathFrom /* : Path*/, pathTo /* : Path*/, ctx /* : CopyInfo*/, callback /* : ReturnCallback<boolean>*/) {}
    // r._rename = function(pathFrom /* : Path*/, newName /* : string*/, ctx /* : RenameInfo*/, callback /* : ReturnCallback<boolean>*/) {}
    // r._mimeType = function(path /* : Path*/, ctx /* : MimeTypeInfo*/, callback /* : ReturnCallback<string>*/) {}
    // r._size = function(path /* : Path*/, ctx /* : SizeInfo*/, callback /* : ReturnCallback<number>*/) {}
    // r._availableLocks = function(path /* : Path*/, ctx /* : AvailableLocksInfo*/, callback /* : ReturnCallback<LockKind[]>*/) {}
    r._lockManager = function(path /* : Path*/, ctx /* : LockManagerInfo*/, callback /* : ReturnCallback<ILockManager>*/) {
        // TODO
    }
    r._propertyManager = function(path /* : Path*/, ctx /* : PropertyManagerInfo*/, callback /* : ReturnCallback<IPropertyManager>*/) {
        // TODO
    }
    // r._readDir = function(path /* : Path*/, ctx /* : ReadDirInfo*/, callback /* : ReturnCallback<string[] | Path[]>*/) {}
    // r._creationDate = function(path /* : Path*/, ctx /* : CreationDateInfo*/, callback /* : ReturnCallback<number>*/) {}
    // r._lastModifiedDate = function(path /* : Path*/, ctx /* : LastModifiedDateInfo*/, callback /* : ReturnCallback<number>*/) {}
    // r._displayName = function(path /* : Path*/, ctx /* : DisplayNameInfo*/, callback /* : ReturnCallback<string>*/) {}
    r._type = function(path /* : Path*/, ctx /* : TypeInfo*/, callback /* : ReturnCallback<ResourceType>*/) {
        // TODO
    }
    // r._privilegeManager = function(path /* : Path*/, info /* : PrivilegeManagerInfo*/, callback /* : ReturnCallback<PrivilegeManager>*/) {}

    return r;
}

module.exports.MyFileSystemSerializer = MyFileSystemSerializer;
module.exports.MyFileSystem = MyFileSystem;
Clone this wiki locally