Skip to content

Resources

Adrien Castex edited this page Jun 19, 2017 · 6 revisions

The server is composed of resources. All resources inherit the IResource interface.

Here is the IResource interface :

interface IResource
{
    parent : IResource
    fsManager : FSManager

    // ****************************** Actions ****************************** //
    create(callback : SimpleCallback)
    delete(callback : SimpleCallback)
    moveTo(parent : IResource, newName : string, overwrite : boolean, callback : SimpleCallback)
    rename(newName : string, callback : Return2Callback<string, string>)
    
    // ****************************** Content ****************************** //
    write(targetSource : boolean, callback : ReturnCallback<Writable>)
    read(targetSource : boolean, callback : ReturnCallback<Readable>)
    mimeType(targetSource : boolean, callback : ReturnCallback<string>)
    size(targetSource : boolean, callback : ReturnCallback<number>)
    
    // ****************************** Locks ****************************** //
    getLocks(callback : ReturnCallback<Lock[]>)
    setLock(lock : Lock, callback : SimpleCallback)
    removeLock(uuid : string, callback : ReturnCallback<boolean>)
    getAvailableLocks(callback : ReturnCallback<LockKind[]>)
    getLock(uuid : string, callback : ReturnCallback<Lock>)

    // ****************************** Children ****************************** //
    addChild(resource : IResource, callback : SimpleCallback)
    removeChild(resource : IResource, callback : SimpleCallback)
    getChildren(callback : ReturnCallback<IResource[]>)

    // ****************************** Properties ****************************** //
    setProperty(name : string, value : ResourcePropertyValue, callback : SimpleCallback)
    getProperty(name : string, callback : ReturnCallback<ResourcePropertyValue>)
    removeProperty(name : string, callback : SimpleCallback)
    getProperties(callback : ReturnCallback<object>)
    
    // ****************************** Std meta-data ****************************** //
    creationDate(callback : ReturnCallback<number>)
    lastModifiedDate(callback : ReturnCallback<number>)
    webName(callback : ReturnCallback<string>)
    displayName?(callback : ReturnCallback<string>)
    type(callback : ReturnCallback<ResourceType>)
    
    // ****************************** Gateway ****************************** //
    gateway?(arg : MethodCallArgs, path : FSPath, callback : (error : Error, resource ?: IResource) => void)
}

For more information about the above callbacks, look at the Common callbacks page.

For more information about each method, look at the Custom resources page.

A resource can have :

Description Needed by Related methods
Child resources Directory addChild(resource : IResource, callback : SimpleCallback)
removeChild(resource : IResource, callback : SimpleCallback)
getChildren(callback : ReturnCallback<IResource[]>)
A content File write(targetSource : boolean, callback : ReturnCallback<Writable>)
read(targetSource : boolean, callback : ReturnCallback<Readable>)
A mime-type File mimeType(targetSource : boolean, callback : ReturnCallback<string>)
A size File size(targetSource : boolean, callback : ReturnCallback<number>)
Properties All setProperty(name : string, value : ResourcePropertyValue, callback : SimpleCallback)
getProperty(name : string, callback : ReturnCallback<ResourcePropertyValue>)
removeProperty(name : string, callback : SimpleCallback)
getProperties(callback : ReturnCallback<object>)
Locks All getLocks(callback : ReturnCallback<Lock[]>)
setLock(lock : Lock, callback : SimpleCallback)
removeLock(uuid : string, callback : ReturnCallback<boolean>)
getAvailableLocks(callback : ReturnCallback<LockKind[]>)
getLock(uuid : string, callback : ReturnCallback<Lock>)
A name All webName(callback : ReturnCallback<string>)
A name to display None displayName?(callback : ReturnCallback<string>)
A creation date All creationDate(callback : ReturnCallback<number>)
A modification date All lastModifiedDate(callback : ReturnCallback<number>)
A type All type(callback : ReturnCallback<ResourceType>)

Content

Source and processed

A resource can have two kinds of content : a source content and a processed content. It is selected by the user with the source header. If the source header is omitted, the default value will be false. This header can be used with the WebDAV methods : GET, HEAD, PROPFIND and PUT. Depending on the implementation of the target resource, the header can be ignored. For instance, if a resource provides a raw text content without processing, the result of a GET request asking the source will be the same as the result of the same request asking the processed content.

GET /file HTTP/1.1
Source: T
Content-Length: 0

This request asks the source content of a resource located at /file.

GET /file HTTP/1.1
Source: F
Content-Length: 0

This request asks the processed content of a resource located at /file.

Storage

The content of the resource can be stored in memory, physicaly, remotely, etc.

Here are the current implementations' storage method :

Implementation/Class Method
PhysicalFile Store the content in the file specified in its constructor.
VirtualFile Store the content in memory. A serialization will embbed the content in its properties, making this resource fast but inappropriate for large contents.
VirtualStoredFile Store the content in a file generated for this purpose. A VirtualStoredContentManager will allocate a file for the resource and manage its content by a unique id and store the content of all related VirtualStoredFile into a folder.

Children

A resource might have children of different type. For instance, A VirtualFolder can have children of type VirtualFile, VirtualFolder, but PhysicalFile too (and others). The server makes no restriction on the children type, but the resource itself can. A custom folder resource can restrict the type of its children, for instance, to make a filtering.

Type

The type of a resource can be (class ResourceType) :

- Is a directory Is not a directory
Is a file Hibrid File
Is not a file Directory NoResource

Here are the differences between the resource types :

- Hibrid File Directory NoResource
Can have content yes yes no no
Can have child resource yes no yes no
Is standard (RFC) no yes yes no

Root resource

The root resource (class RootResource) is a resource which disallow almost everything (no copy, no move, etc), but provides a static root folder. It is instanciated by default if no option.rootResource is provided to the constructor of the server. This resource is a virtual resource. That's why, if you create a child through the WebDAV interface (HTTP), it will be a virtual resource.

Method Must be allowed? Method Must be allowed?
create no delete no
moveTo no rename no
append may write may
read may mimeType may
size may getLocks yes
setLock yes removeLock yes
canLock yes getAvailableLocks yes
canRemoveLock yes getLock yes
addChild yes removeChild yes
getChildren yes setProperty yes
getProperty yes removeProperty yes
getProperties yes creationDate yes
lastModifiedDate may webName yes
type yes

Resource creation

When a user create a resource through the WebDAV interface (HTTP), it will inherit the parent file system manager. For instance, if you create a file or a folder as a child of the path /myFolder and myFolder contains a virtual file system manager, then the file or folder created will be a virtual file or a virtual folder. The same reflection can be made with the physical resources and custom resources. The file system manager is in charge of the creation of the resource object (not to call .create(...), just the object). This way, you can have a behavior for a resource (the resource class itself) and a different behavior for its children (the file system manager).

If you create a resource through the module (for instance in JavaScript), you can add as child of a resource the kind of resource you want. You are limited only by the type of the parent resource and its implementation.

Clone this wiki locally