nephele
Version:
Highly customizable and extensible WebDAV server for Node.js and Express.
130 lines • 3.76 kB
JavaScript
import { HTTPStatusMessages } from './HTTPStatusMessages.js';
export class PropStatStatus {
constructor(statusCode, statusMessage) {
this.body = undefined;
this.prop = undefined;
this.description = undefined;
this.statusCode = statusCode;
if (statusMessage) {
this.statusMessage = statusMessage;
}
else if (statusCode in HTTPStatusMessages) {
this.statusMessage =
HTTPStatusMessages[statusCode];
}
else {
this.statusMessage = '';
}
}
toString() {
return `PropStatStatus: ${this.statusCode} ${this.statusMessage}${this.description ? ` (${this.description})` : ''}`;
}
setBody(body) {
this.body = body;
}
setProp(prop) {
this.prop = prop;
}
render() {
let response = {
status: [`HTTP/1.1 ${this.statusCode} ${this.statusMessage}`],
};
if (this.description != null) {
response.responsedescription = [this.description];
}
if (this.prop) {
response.prop = this.prop;
}
if (this.body) {
response = { ...response, ...this.body };
}
return response;
}
}
export class Status {
constructor(href, statusCode, statusMessage, element = 'response') {
this.body = undefined;
this.propStatStatuses = [];
this.description = undefined;
this.href = href;
this.statusCode = statusCode;
this.element = element;
if (statusMessage) {
this.statusMessage = statusMessage;
}
else if (statusCode in HTTPStatusMessages) {
this.statusMessage =
HTTPStatusMessages[statusCode];
}
else {
this.statusMessage = '';
}
}
toString() {
return `Status: ${this.statusCode} ${this.statusMessage}${this.description ? ` (${this.description})` : ''}`;
}
setDescription(description) {
this.description = description;
}
setBody(body) {
this.body = body;
}
addPropStatStatus(propStatStatus) {
this.propStatStatuses.push(propStatStatus);
}
render() {
let response = {
href: { _: this.href.toString() },
};
if (this.description != null) {
response.responsedescription = [this.description];
}
if (this.propStatStatuses.length > 0) {
response.propstat = [];
for (let propStatStatus of this.propStatStatuses) {
response.propstat.push(propStatStatus.render());
}
}
else {
response.status = [`HTTP/1.1 ${this.statusCode} ${this.statusMessage}`];
}
if (this.body) {
response = { ...response, ...this.body };
}
return response;
}
}
export class MultiStatus {
constructor() {
this.statuses = [];
this.description = undefined;
}
addStatus(status) {
this.statuses.push(status);
}
setDescription(description) {
this.description = description;
}
render() {
const responses = [];
const xml = {
multistatus: {
$: {
xmlns: 'DAV:',
},
},
};
if (this.description != null) {
xml.responsedescription = [this.description];
}
if (this.statuses.length < 1) {
return xml;
}
xml.multistatus.response = responses;
for (let status of this.statuses) {
responses.push(status.render());
}
return xml;
}
}
//# sourceMappingURL=MultiStatus.js.map