diff --git a/core/src/utils/xhr-request.js b/core/src/utils/xhr-request.js index 0432fc9fd3f67..66f994246e0bc 100644 --- a/core/src/utils/xhr-request.js +++ b/core/src/utils/xhr-request.js @@ -21,6 +21,10 @@ import { getRootUrl } from '@nextcloud/router' +/** + * @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() // try with relative and absolute URL @@ -43,24 +47,25 @@ export const interceptRequests = () => { })(XMLHttpRequest.prototype.open) window.fetch = (function(fetch) { - return (input, init) => { - if (!isNextcloudUrl(input.url)) { - return fetch(input, init) + 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 (!init) { - init = {} + if (!options) { + options = {} } - if (!init.headers) { - init.headers = new Headers() + if (!options.headers) { + options.headers = new Headers() } - if (init.headers instanceof Headers && !init.headers.has('X-Requested-With')) { - init.headers.append('X-Requested-With', 'XMLHttpRequest') - } else if (init.headers instanceof Object && !init.headers['X-Requested-With']) { - init.headers['X-Requested-With'] = 'XMLHttpRequest' + 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(input, init) + return fetch(resource, options) } })(window.fetch) } diff --git a/dist/core-main.js b/dist/core-main.js index b82763580f82e..7e1ef2f210dba 100644 --- a/dist/core-main.js +++ b/dist/core-main.js @@ -1,3 +1,3 @@ /*! For license information please see core-main.js.LICENSE.txt */ -!function(){var e,i,o,r={35788:function(e,i,o){"use strict";var r={};o.r(r),o.d(r,{deleteKey:function(){return k},getApps:function(){return C},getKeys:function(){return x},getValue:function(){return y},setValue:function(){return w}});var s={};o.r(s),o.d(s,{formatLinksPlain:function(){return Tn},formatLinksRich:function(){return Sn},plainToRich:function(){return Dn},richToPlain:function(){return In}});var a={};o.r(a),o.d(a,{dismiss:function(){return On},query:function(){return Pn}}),o(28594),o(35666);var c=o(69183),u=o(59050),l=o(19755),h=o.n(l),d=o(64024),p=o(25108),A={updatableNotification:null,getDefaultNotificationFunction:null,setDefault:function(t){this.getDefaultNotificationFunction=t},hide:function(t,e){u.default.isFunction(t)&&(e=t,t=void 0),t?(t.each((function(){h()(this)[0].toastify?h()(this)[0].toastify.hideToast():p.error("cannot hide toast because object is not set"),this===this.updatableNotification&&(this.updatableNotification=null)})),e&&e.call(),this.getDefaultNotificationFunction&&this.getDefaultNotificationFunction()):p.error("Missing argument $row in OC.Notification.hide() call, caller needs to be adjusted to only dismiss its own notification")},showHtml:function(t,e){(e=e||{}).isHTML=!0,e.timeout=e.timeout?e.timeout:d.Rl;var n=(0,d.PV)(t,e);return n.toastElement.toastify=n,h()(n.toastElement)},show:function(t,e){(e=e||{}).timeout=e.timeout?e.timeout:d.Rl;var n=(0,d.PV)(function(t){return t.toString().split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""").split("'").join("'")}(t),e);return n.toastElement.toastify=n,h()(n.toastElement)},showUpdate:function(t){return this.updatableNotification&&this.updatableNotification.hideToast(),this.updatableNotification=(0,d.PV)(t,{timeout:d.Rl}),this.updatableNotification.toastElement.toastify=this.updatableNotification,h()(this.updatableNotification.toastElement)},showTemporary:function(t,e){(e=e||{}).timeout=e.timeout||d.TN;var n=(0,d.PV)(t,e);return n.toastElement.toastify=n,h()(n.toastElement)},isHidden:function(){return!h()("#content").find(".toastify").length}},f=u.default.throttle((function(){A.showTemporary(t("core","Connection to server lost"))}),7e3,{trailing:!1}),g=!1,m={enableDynamicSlideToggle:function(){g=!0},showAppSidebar:function(t){(t||h()("#app-sidebar")).removeClass("disappear").show(),h()("#app-content").trigger(new(h().Event)("appresized"))},hideAppSidebar:function(t){(t||h()("#app-sidebar")).hide().addClass("disappear"),h()("#app-content").trigger(new(h().Event)("appresized"))}},v=o(79753);function b(t,e,n){"post"!==t&&"delete"!==t||!Dt.PasswordConfirmation.requiresPasswordConfirmation()?(n=n||{},h().ajax({type:t.toUpperCase(),url:(0,v.generateOcsUrl)("apps/provisioning_api/api/v1/config/apps")+e,data:n.data||{},success:n.success,error:n.error})):Dt.PasswordConfirmation.requirePasswordConfirmation(_.bind(b,this,t,e,n))}function C(t){b("get","",t)}function x(t,e){b("get","/"+t,e)}function y(t,e,n,i){(i=i||{}).data={defaultValue:n},b("get","/"+t+"/"+e,i)}function w(t,e,n,i){(i=i||{}).data={value:n},b("post","/"+t+"/"+e,i)}function k(t,e,n){b("delete","/"+t+"/"+e,n)}var B=window.oc_appconfig||{},E={getValue:function(t,e,n,i){y(t,e,n,{success:i})},setValue:function(t,e,n){w(t,e,n)},getApps:function(t){C({success:t})},getKeys:function(t,e){x(t,{success:e})},deleteKey:function(t,e){k(t,e)}},D=void 0!==window._oc_appswebroots&&window._oc_appswebroots,I=o(72316),S=o.n(I),T=o(76591),M=o(25108),P={create:"POST",update:"PROPPATCH",patch:"PROPPATCH",delete:"DELETE",read:"PROPFIND"};function O(t,e){if(u.default.isArray(t))return u.default.map(t,(function(t){return O(t,e)}));var n={href:t.href};return u.default.each(t.propStat,(function(t){if("HTTP/1.1 200 OK"===t.status)for(var i in t.properties){var o=i;i in e&&(o=e[i]),n[o]=t.properties[i]}})),n.id||(n.id=z(n.href)),n}function z(t){var e=t.indexOf("?");e>0&&(t=t.substr(0,e));var n,i=t.split("/");do{n=i[i.length-1],i.pop()}while(!n&&i.length>0);return n}function R(t){return t>=200&&t<=299}function N(t,e,n,i){return t.propPatch(e.url,function(t,e){var n,i={};for(n in t){var o=e[n],r=t[n];o||(M.warn('No matching DAV property for property "'+n),o=n),(u.default.isBoolean(r)||u.default.isNumber(r))&&(r=""+r),i[o]=r}return i}(n.changed,e.davProperties),i).then((function(t){R(t.status)?u.default.isFunction(e.success)&&e.success(n.toJSON()):u.default.isFunction(e.error)&&e.error(t)}))}var H=S().noConflict();Object.assign(H,{davCall:function(t,e){var n=new T.dav.Client({baseUrl:t.url,xmlNamespaces:u.default.extend({"DAV:":"d","http://owncloud.org/ns":"oc"},t.xmlNamespaces||{})});n.resolveUrl=function(){return t.url};var i=u.default.extend({"X-Requested-With":"XMLHttpRequest",requesttoken:OC.requestToken},t.headers);return"PROPFIND"===t.type?function(t,e,n,i){return t.propFind(e.url,u.default.values(e.davProperties)||[],e.depth,i).then((function(t){if(R(t.status)){if(u.default.isFunction(e.success)){var n=u.default.invert(e.davProperties),i=O(t.body,n);e.depth>0&&i.shift(),e.success(i)}}else u.default.isFunction(e.error)&&e.error(t)}))}(n,t,0,i):"PROPPATCH"===t.type?N(n,t,e,i):"MKCOL"===t.type?function(t,e,n,i){return t.request(e.type,e.url,i,null).then((function(o){R(o.status)?N(t,e,n,i):u.default.isFunction(e.error)&&e.error(o)}))}(n,t,e,i):function(t,e,n,i){return i["Content-Type"]="application/json",t.request(e.type,e.url,i,e.data).then((function(t){if(R(t.status)){if(u.default.isFunction(e.success)){if("PUT"===e.type||"POST"===e.type||"MKCOL"===e.type){var i=t.body||n.toJSON(),o=t.xhr.getResponseHeader("Content-Location");return"POST"===e.type&&o&&(i.id=z(o)),void e.success(i)}if(207===t.status){var r=u.default.invert(e.davProperties);e.success(O(t.body,r))}else e.success(t.body)}}else u.default.isFunction(e.error)&&e.error(t)}))}(n,t,e,i)},davSync:function(t){return function(e,n,i){var o={type:P[e]||e},r=n instanceof t.Collection;if("update"===e&&(n.hasInnerCollection?o.type="MKCOL":(n.usePUT||n.collection&&n.collection.usePUT)&&(o.type="PUT")),i.url||(o.url=u.default.result(n,"url")||function(){throw new Error('A "url" property or function must be specified')}()),null!=i.data||!n||"create"!==e&&"update"!==e&&"patch"!==e||(o.data=JSON.stringify(i.attrs||n.toJSON(i))),"PROPFIND"!==o.type&&(o.processData=!1),"PROPFIND"===o.type||"PROPPATCH"===o.type){var s=n.davProperties;!s&&n.model&&(s=n.model.prototype.davProperties),s&&(u.default.isFunction(s)?o.davProperties=s.call(n):o.davProperties=s),o.davProperties=u.default.extend(o.davProperties||{},i.davProperties),u.default.isUndefined(i.depth)&&(i.depth=r?1:0)}var a=i.error;i.error=function(t,e,n){i.textStatus=e,i.errorThrown=n,a&&a.call(i.context,t,e,n)};var c=i.xhr=t.davCall(u.default.extend(o,i),n);return n.trigger("request",n,c,i),c}}(H)});var j=H,L=o(65358),U=window._oc_config||{},F=document.getElementsByTagName("head")[0].getAttribute("data-user"),W=document.getElementsByTagName("head")[0].getAttribute("data-user-displayname"),Y=void 0!==F&&F,Q=o(96384),q=o(62520);function G(t){return G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},G(t)}var X={YES_NO_BUTTONS:70,OK_BUTTONS:71,FILEPICKER_TYPE_CHOOSE:1,FILEPICKER_TYPE_MOVE:2,FILEPICKER_TYPE_COPY:3,FILEPICKER_TYPE_COPY_MOVE:4,FILEPICKER_TYPE_CUSTOM:5,dialogsCounter:0,alert:function(t,e,n,i){this.message(t,e,"alert",X.OK_BUTTON,n,i)},info:function(t,e,n,i){this.message(t,e,"info",X.OK_BUTTON,n,i)},confirm:function(t,e,n,i){return this.message(t,e,"notice",X.YES_NO_BUTTONS,n,i)},confirmDestructive:function(t,e,n,i,o){return this.message(t,e,"none",n,i,void 0===o||o)},confirmHtml:function(t,e,n,i){return this.message(t,e,"notice",X.YES_NO_BUTTONS,n,i,!0)},prompt:function(e,n,i,o,r,s){return h().when(this._getMessageTemplate()).then((function(a){var c="oc-dialog-"+X.dialogsCounter+"-content",l="#"+c,d=a.octemplate({dialog_name:c,title:n,message:e,type:"notice"}),p=h()("");p.attr("type",s?"password":"text").attr("id",c+"-input").attr("placeholder",r);var A=h()("