mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Generalize and extend notification channel type behaviour
This commit is contained in:
@@ -28,3 +28,38 @@ export function sanitizeUrlPart(urlPart: string): string {
|
||||
export function isValidFileName(name: string): boolean {
|
||||
return /^[\w.-]+$/u.test(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts milliseconds to an ISO 8601 duration string.
|
||||
* The only categories used are days, hours, minutes, and seconds,
|
||||
* because months have no fixed size in milliseconds.
|
||||
* @param ms - The duration in ms to convert.
|
||||
*/
|
||||
export function msToDuration(ms: number): string {
|
||||
let totalSeconds = ms / 1000;
|
||||
const days = Math.floor(totalSeconds / (60 * 60 * 24));
|
||||
totalSeconds -= days * 60 * 60 * 24;
|
||||
const hours = Math.floor(totalSeconds / (60 * 60));
|
||||
totalSeconds -= hours * 60 * 60;
|
||||
const minutes = Math.floor(totalSeconds / 60);
|
||||
const seconds = totalSeconds - (minutes * 60);
|
||||
|
||||
const stringParts: string[] = [ 'P' ];
|
||||
if (days > 0) {
|
||||
stringParts.push(`${days}D`);
|
||||
}
|
||||
if (hours > 0 || minutes > 0 || seconds > 0) {
|
||||
stringParts.push('T');
|
||||
}
|
||||
if (hours > 0) {
|
||||
stringParts.push(`${hours}H`);
|
||||
}
|
||||
if (minutes > 0) {
|
||||
stringParts.push(`${minutes}M`);
|
||||
}
|
||||
if (seconds > 0) {
|
||||
stringParts.push(`${seconds}S`);
|
||||
}
|
||||
|
||||
return stringParts.join('');
|
||||
}
|
||||
|
||||
@@ -200,10 +200,13 @@ export const NOTIFY = createVocabulary('http://www.w3.org/ns/solid/notifications
|
||||
'startAt',
|
||||
'state',
|
||||
'subscription',
|
||||
'target',
|
||||
'topic',
|
||||
'webhookAuth',
|
||||
'webid',
|
||||
|
||||
'WebHookSubscription2021',
|
||||
'WebSocketSubscription2021',
|
||||
);
|
||||
|
||||
export const OIDC = createVocabulary('http://www.w3.org/ns/solid/oidc#',
|
||||
@@ -276,7 +279,9 @@ export const VCARD = createVocabulary('http://www.w3.org/2006/vcard/ns#',
|
||||
|
||||
export const XSD = createVocabulary('http://www.w3.org/2001/XMLSchema#',
|
||||
'dateTime',
|
||||
'duration',
|
||||
'integer',
|
||||
'string',
|
||||
);
|
||||
|
||||
// Alias for commonly used types
|
||||
|
||||
Reference in New Issue
Block a user