summaryrefslogtreecommitdiffstats
path: root/core/src/utils/xhr-request.js
blob: 5eaeb7e64d7228f40d4a99c7f94d89272cf888b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
 * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import { getRootUrl } from '@nextcloud/router'

/**
 *
 * @param {string} url the URL to check
 * @return {boolean}
 */
const isRelativeUrl = (url) => {
	return !url.startsWith('https://') && !url.startsWith('http://')
}

/**
 * @param {string} url The URL to check
 * @return {boolean} true if the URL points to this nextcloud instance
 */
const isNextcloudUrl = (url) => {
	const nextcloudBaseUrl = window.location.protocol + '//' + window.location.host + getRootUrl()
	// if the URL is absolute and starts with the baseUrl+rootUrl
	// OR if the URL is relative and starts with rootUrl
	return url.startsWith(nextcloudBaseUrl)
		|| (isRelativeUrl(url) && url.startsWith(getRootUrl()))
}

/**
 * Intercept XMLHttpRequest and fetch API calls to add X-Requested-With header
 *
 * This is also done in @nextcloud/axios but not all requests pass through that
 */
export const interceptRequests = () => {
	XMLHttpRequest.prototype.open = (function(open) {
		return function(method, url, async) {
			open.apply(this, arguments)
			if (isNextcloudUrl(url) && !this.getResponseHeader('X-Requested-With')) {
				this.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
			}
		}
	})(XMLHttpRequest.prototype.open)

	window.fetch = (function(fetch) {
		return (resource, options) => {
			// fetch allows the `input` to be either a Request object or any stringifyable value
			if (!isNextcloudUrl(resource.url ?? resource.toString())) {
				return fetch(resource, options)
			}
			if (!options) {
				options = {}
			}
			if (!options.headers) {
				options.headers = new Headers()
			}

			if (options.headers instanceof Headers && !options.headers.has('X-Requested-With')) {
				options.headers.append('X-Requested-With', 'XMLHttpRequest')
			} else if (options.headers instanceof Object && !options.headers['X-Requested-With']) {
				options.headers['X-Requested-With'] = 'XMLHttpRequest'
			}

			return fetch(resource, options)
		}
	})(window.fetch)
}
span> "" #: js/fileactions.js:110 templates/index.php:66 msgid "Delete" msgstr "삭제" #: js/fileactions.js:178 msgid "Rename" msgstr "" #: js/filelist.js:194 js/filelist.js:196 msgid "{new_name} already exists" msgstr "" #: js/filelist.js:194 js/filelist.js:196 msgid "replace" msgstr "대체" #: js/filelist.js:194 msgid "suggest name" msgstr "" #: js/filelist.js:194 js/filelist.js:196 msgid "cancel" msgstr "취소" #: js/filelist.js:243 msgid "replaced {new_name}" msgstr "" #: js/filelist.js:243 js/filelist.js:245 js/filelist.js:277 js/filelist.js:279 msgid "undo" msgstr "복구" #: js/filelist.js:245 msgid "replaced {new_name} with {old_name}" msgstr "" #: js/filelist.js:277 msgid "unshared {files}" msgstr "" #: js/filelist.js:279 msgid "deleted {files}" msgstr "" #: js/files.js:171 msgid "generating ZIP-file, it may take some time." msgstr "ZIP파일 생성에 시간이 걸릴 수 있습니다." #: js/files.js:206 msgid "Unable to upload your file as it is a directory or has 0 bytes" msgstr "이 파일은 디렉토리이거나 0 바이트이기 때문에 업로드 할 수 없습니다." #: js/files.js:206 msgid "Upload Error" msgstr "업로드 에러" #: js/files.js:234 js/files.js:339 js/files.js:369 msgid "Pending" msgstr "보류 중" #: js/files.js:254 msgid "1 file uploading" msgstr "" #: js/files.js:257 js/files.js:302 js/files.js:317 msgid "{count} files uploading" msgstr "" #: js/files.js:320 js/files.js:353 msgid "Upload cancelled." msgstr "업로드 취소." #: js/files.js:422 msgid "" "File upload is in progress. Leaving the page now will cancel the upload." msgstr "" #: js/files.js:492 msgid "Invalid name, '/' is not allowed." msgstr "잘못된 이름, '/' 은 허용이 되지 않습니다." #: js/files.js:673 msgid "{count} files scanned" msgstr "" #: js/files.js:681 msgid "error while scanning" msgstr "" #: js/files.js:754 templates/index.php:50 msgid "Name" msgstr "이름" #: js/files.js:755 templates/index.php:58 msgid "Size" msgstr "크기" #: js/files.js:756 templates/index.php:60 msgid "Modified" msgstr "수정됨" #: js/files.js:783 msgid "1 folder" msgstr "" #: js/files.js:785 msgid "{count} folders" msgstr "" #: js/files.js:793 msgid "1 file" msgstr "" #: js/files.js:795 msgid "{count} files" msgstr "" #: js/files.js:838 msgid "seconds ago" msgstr "" #: js/files.js:839 msgid "1 minute ago" msgstr "" #: js/files.js:840 msgid "{minutes} minutes ago" msgstr "" #: js/files.js:843 msgid "today" msgstr "" #: js/files.js:844 msgid "yesterday" msgstr "" #: js/files.js:845 msgid "{days} days ago" msgstr "" #: js/files.js:846 msgid "last month" msgstr "" #: js/files.js:848 msgid "months ago" msgstr "" #: js/files.js:849 msgid "last year" msgstr "" #: js/files.js:850 msgid "years ago" msgstr "" #: templates/admin.php:5 msgid "File handling" msgstr "파일 처리" #: templates/admin.php:7 msgid "Maximum upload size" msgstr "최대 업로드 크기" #: templates/admin.php:7 msgid "max. possible: " msgstr "최대. 가능한:" #: templates/admin.php:9 msgid "Needed for multi-file and folder downloads." msgstr "멀티 파일 및 폴더 다운로드에 필요." #: templates/admin.php:9 msgid "Enable ZIP-download" msgstr "ZIP- 다운로드 허용" #: templates/admin.php:11 msgid "0 is unlimited" msgstr "0은 무제한 입니다" #: templates/admin.php:12 msgid "Maximum input size for ZIP files" msgstr "ZIP 파일에 대한 최대 입력 크기" #: templates/admin.php:14 msgid "Save" msgstr "" #: templates/index.php:7 msgid "New" msgstr "새로 만들기" #: templates/index.php:9 msgid "Text file" msgstr "텍스트 파일" #: templates/index.php:10 msgid "Folder" msgstr "폴더" #: templates/index.php:11 msgid "From link" msgstr "" #: templates/index.php:22 msgid "Upload" msgstr "업로드" #: templates/index.php:29 msgid "Cancel upload" msgstr "업로드 취소" #: templates/index.php:42 msgid "Nothing in here. Upload something!" msgstr "내용이 없습니다. 업로드할 수 있습니다!" #: templates/index.php:52 msgid "Share" msgstr "공유" #: templates/index.php:54 msgid "Download" msgstr "다운로드" #: templates/index.php:77 msgid "Upload too large" msgstr "업로드 용량 초과" #: templates/index.php:79 msgid "" "The files you are trying to upload exceed the maximum size for file uploads " "on this server." msgstr "이 파일이 서버에서 허용하는 최대 업로드 가능 용량보다 큽니다." #: templates/index.php:84 msgid "Files are being scanned, please wait." msgstr "파일을 검색중입니다, 기다려 주십시오." #: templates/index.php:87 msgid "Current scanning" msgstr "커런트 스캐닝"