diff options
Diffstat (limited to 'apps/comments/src/utils')
-rw-r--r-- | apps/comments/src/utils/cancelableRequest.js | 36 | ||||
-rw-r--r-- | apps/comments/src/utils/davUtils.js | 12 | ||||
-rw-r--r-- | apps/comments/src/utils/decodeHtmlEntities.js | 17 |
3 files changed, 65 insertions, 0 deletions
diff --git a/apps/comments/src/utils/cancelableRequest.js b/apps/comments/src/utils/cancelableRequest.js new file mode 100644 index 00000000000..c2d380c80f9 --- /dev/null +++ b/apps/comments/src/utils/cancelableRequest.js @@ -0,0 +1,36 @@ +/** + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/** + * Creates a cancelable axios 'request object'. + * + * @param {Function} request the axios promise request + * @return {object} + */ +const cancelableRequest = function(request) { + const controller = new AbortController() + const signal = controller.signal + + /** + * Execute the request + * + * @param {string} url the url to send the request to + * @param {object} [options] optional config for the request + */ + const fetch = async function(url, options) { + const response = await request( + url, + Object.assign({ signal }, options), + ) + return response + } + + return { + request: fetch, + abort: () => controller.abort(), + } +} + +export default cancelableRequest diff --git a/apps/comments/src/utils/davUtils.js b/apps/comments/src/utils/davUtils.js new file mode 100644 index 00000000000..33efc8e7d10 --- /dev/null +++ b/apps/comments/src/utils/davUtils.js @@ -0,0 +1,12 @@ +/** + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { generateRemoteUrl } from '@nextcloud/router' + +const getRootPath = function() { + return generateRemoteUrl('dav/comments') +} + +export { getRootPath } diff --git a/apps/comments/src/utils/decodeHtmlEntities.js b/apps/comments/src/utils/decodeHtmlEntities.js new file mode 100644 index 00000000000..4c492954256 --- /dev/null +++ b/apps/comments/src/utils/decodeHtmlEntities.js @@ -0,0 +1,17 @@ +/** + * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/** + * @param {any} value - + * @param {any} passes - + */ +export function decodeHtmlEntities(value, passes = 1) { + const parser = new DOMParser() + let decoded = value + for (let i = 0; i < passes; i++) { + decoded = parser.parseFromString(decoded, 'text/html').documentElement.textContent + } + return decoded +} |