X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=inline;f=src%2Ftemplate%2Ftemplate-helper.js;h=3fd371035d0ab4989bcfbf771839f5d6431a5f11;hb=8f63eeebd08491cdc82e12f178dc500f6d19d65c;hp=bb4dad1e3f574f2332683c9e4bc990c9bc98b3a2;hpb=3c547e314b79a31fb3f15412a47707a22dc3eefd;p=websub-hub
diff --git a/src/template/template-helper.js b/src/template/template-helper.js
index bb4dad1..3fd3710 100644
--- a/src/template/template-helper.js
+++ b/src/template/template-helper.js
@@ -2,7 +2,6 @@
const { TemplateHelper } = require('@squeep/html-template-helper');
-
/**
* Render a topic as a row of details.
* @param {Object} topic
@@ -19,17 +18,17 @@ function renderTopicRow(topic, subscribers, detailsLink = true) {
return `
${detailsLink ? '' : ''}${topic.url}${detailsLink ? '' : ''} |
${subscribers.length} |
- ${TemplateHelper.dateOrNot(topic.created, 'Unknown')} |
+ ${TemplateHelper.dateFormat(topic.created, 'End of Time', 'Beginning of Time', 'Unknown')} |
${TemplateHelper.secondsToPeriod(topic.leaseSecondsPreferred)} |
${TemplateHelper.secondsToPeriod(topic.leaseSecondsMin)} |
${TemplateHelper.secondsToPeriod(topic.leaseSecondsMax)} |
${topic.publisherValidationUrl ? topic.publisherValidationUrl : 'None'} |
${topic.isActive} |
${topic.isDeleted} |
- ${TemplateHelper.dateOrNot(topic.lastPublish, 'Never')} |
- ${TemplateHelper.dateOrNot(topic.contentFetchNextAttempt, 'Next Publish')} |
+ ${TemplateHelper.dateFormat(topic.lastPublish, 'End of Time', 'Never', 'Never')} |
+ ${TemplateHelper.dateFormat(topic.contentFetchNextAttempt, 'Next Publish', 'Pending', 'Next Publish')} |
${topic.contentFetchAttemptsSinceSuccess} |
- ${TemplateHelper.dateOrNot(topic.contentUpdated, 'Never')} |
+ ${TemplateHelper.dateFormat(topic.contentUpdated, 'End of Time', 'Never', 'Never')} |
${topic.contentType} |
${topic.id} |
`;
@@ -56,7 +55,7 @@ function renderTopicRowHeader() {
Content Fetch Failures |
Content Updated |
Content Type |
- ID |
+ Internal Id |
`;
}
@@ -74,16 +73,16 @@ function renderSubscriptionRow(subscription) {
}
return `
${subscription.callback} |
- ${TemplateHelper.dateOrNot(subscription.created, 'Unknown')} |
- ${TemplateHelper.dateOrNot(subscription.verified, 'Never')} |
- ${TemplateHelper.dateOrNot(subscription.expires, 'Never')} |
+ ${TemplateHelper.dateFormat(subscription.created, 'End of Time', 'Beginning of Time', 'Unknown')} |
+ ${TemplateHelper.dateFormat(subscription.verified, 'End of Time', 'Never', 'Never')} |
+ ${TemplateHelper.dateFormat(subscription.expires, 'Never', 'Beginning of Time', 'Never')} |
${!!subscription.secret} |
${subscription.signatureAlgorithm} |
${subscription.httpRemoteAddr} |
${subscription.httpFrom} |
- ${TemplateHelper.dateOrNot(subscription.contentDelivered, 'Never')} |
+ ${TemplateHelper.dateFormat(subscription.contentDelivered, 'End of Time', 'Never', 'Never')} |
${subscription.deliveryAttemptsSinceSuccess} |
- ${TemplateHelper.dateOrNot(subscription.deliveryNextAttempt, 'Next Publish')} |
+ ${TemplateHelper.dateFormat(subscription.deliveryNextAttempt, 'End of Time', 'Next Publish', 'Next Publish')} |
${subscription.id} |
`;
}
@@ -106,13 +105,35 @@ function renderSubscriptionRowHeader() {
Content Delivered |
Content Delivery Failures |
Next Delivery |
- ID |
+ Internal Id |
`;
}
+/**
+ * Escape some xml things in strings.
+ * @param {String} string
+ */
+function xmlEscape(string) {
+ if (typeof string === 'number') {
+ return string;
+ }
+ if (typeof string !== 'string') {
+ return undefined;
+ }
+ // eslint-disable-next-line security/detect-object-injection
+ return string.replace(/[<>&'"]/, (c) => ({
+ '<': '<',
+ '>': '>',
+ '&': '&',
+ '\'': ''',
+ '"': '"',
+ }[c]));
+}
+
module.exports = Object.assign(Object.create(TemplateHelper), {
+ xmlEscape,
renderTopicRowHeader,
renderTopicRow,
renderSubscriptionRowHeader,