-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for the PROPPATCH method
- Loading branch information
1 parent
87878cd
commit df2be26
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { MethodCallArgs } from '../WebDAVRequest'; | ||
export default function (arg: MethodCallArgs, callback: any): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var WebDAVRequest_1 = require("../WebDAVRequest"); | ||
var http_1 = require("http"); | ||
var XML_1 = require("../../helper/XML"); | ||
function default_1(arg, callback) { | ||
arg.getResource(function (e, r) { | ||
if (e) { | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.NotFound); | ||
callback(); | ||
return; | ||
} | ||
var multistatus = XML_1.XML.createElement('D:multistatus', { | ||
'xmlns:D': 'DAV:' | ||
}); | ||
var response = multistatus.ele('D:response'); | ||
response.ele('D:href').add(arg.fullUri()); | ||
var xml = XML_1.XML.parse(arg.data); | ||
var root = xml.find('DAV:propertyupdate'); | ||
var finalize = function () { | ||
finalize = function () { | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.MultiStatus); | ||
arg.response.write(XML_1.XML.toXML(multistatus)); | ||
callback(); | ||
}; | ||
}; | ||
function notify(el, error) { | ||
var code = error ? WebDAVRequest_1.HTTPCodes.Conflict : WebDAVRequest_1.HTTPCodes.OK; | ||
var propstat = response.ele('D:propstat'); | ||
propstat.ele('D:prop').ele(el.name); | ||
propstat.ele('D:status').add('HTTP/1.1 ' + code + ' ' + http_1.STATUS_CODES[code]); | ||
} | ||
execute('DAV:set', function (el, callback) { | ||
r.setProperty(el.name, el.elements, callback); | ||
}); | ||
execute('DAV:remove', function (el, callback) { | ||
r.removeProperty(el.name, callback); | ||
}); | ||
function execute(name, fnProp) { | ||
var list = root.findMany(name); | ||
if (list.length === 0) { | ||
finalize(); | ||
return; | ||
} | ||
list.forEach(function (el) { | ||
var els = el.find('DAV:prop').elements; | ||
if (els.length === 0) { | ||
finalize(); | ||
return; | ||
} | ||
var nb = els.length; | ||
els.forEach(function (el) { | ||
fnProp(el, function (e) { | ||
notify(el, e); | ||
--nb; | ||
if (nb === 0) | ||
finalize(); | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
exports.default = default_1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { HTTPCodes, MethodCallArgs, WebDAVRequest } from '../WebDAVRequest' | ||
import { STATUS_CODES } from 'http' | ||
import { IResource } from '../../resource/Resource' | ||
import { XML } from '../../helper/XML' | ||
|
||
export default function(arg : MethodCallArgs, callback) | ||
{ | ||
arg.getResource((e, r) => { | ||
if(e) | ||
{ | ||
arg.setCode(HTTPCodes.NotFound) | ||
callback(); | ||
return; | ||
} | ||
|
||
const multistatus = XML.createElement('D:multistatus', { | ||
'xmlns:D': 'DAV:' | ||
}); | ||
const response = multistatus.ele('D:response'); | ||
response.ele('D:href').add(arg.fullUri()); | ||
|
||
const xml = XML.parse(arg.data); | ||
const root = xml.find('DAV:propertyupdate'); | ||
|
||
let finalize = function() | ||
{ | ||
finalize = function() | ||
{ | ||
arg.setCode(HTTPCodes.MultiStatus); | ||
arg.response.write(XML.toXML(multistatus)); | ||
callback(); | ||
} | ||
} | ||
|
||
function notify(el : any, error : any) | ||
{ | ||
const code = error ? HTTPCodes.Conflict : HTTPCodes.OK; | ||
const propstat = response.ele('D:propstat'); | ||
propstat.ele('D:prop').ele(el.name); | ||
propstat.ele('D:status').add('HTTP/1.1 ' + code + ' ' + STATUS_CODES[code]); | ||
} | ||
|
||
execute('DAV:set', (el, callback) => { | ||
r.setProperty(el.name, el.elements, callback) | ||
}) | ||
execute('DAV:remove', (el, callback) => { | ||
r.removeProperty(el.name, callback) | ||
}) | ||
|
||
function execute(name, fnProp) | ||
{ | ||
const list = root.findMany(name); | ||
if(list.length === 0) | ||
{ | ||
finalize(); | ||
return; | ||
} | ||
|
||
list.forEach(function(el) { | ||
const els = el.find('DAV:prop').elements; | ||
if(els.length === 0) | ||
{ | ||
finalize(); | ||
return; | ||
} | ||
|
||
let nb = els.length; | ||
els.forEach(function(el) { | ||
fnProp(el, (e) => { | ||
notify(el, e); | ||
--nb; | ||
if(nb === 0) | ||
finalize(); | ||
}) | ||
}) | ||
}) | ||
} | ||
}) | ||
} |