nextcloud-server/dist/core-files_client.js

2 lines
12 KiB
JavaScript

(()=>{"use strict";var e,t={12871:(e,t,s)=>{var n=s(21777),i=s(70580),r=s.n(i),o=s(74692),a=s.n(o),l=s(12111),u=s(35947);const c=null===(d=(0,n.HW)())?(0,u.YK)().setApp("core").build():(0,u.YK)().setApp("core").setUid(d.uid).build();var d;(0,u.YK)().setApp("unified-search").detectUser().build(),function(e,t){const s=function(t){this._root=t.root,"/"===this._root.charAt(this._root.length-1)&&(this._root=this._root.substr(0,this._root.length-1));let n=s.PROTOCOL_HTTP+"://";t.useHTTPS&&(n=s.PROTOCOL_HTTPS+"://"),n+=t.host+this._root,this._host=t.host,this._defaultHeaders=t.defaultHeaders||{"X-Requested-With":"XMLHttpRequest",requesttoken:e.requestToken},this._baseUrl=n;const i={baseUrl:this._baseUrl,xmlNamespaces:{"DAV:":"d","http://owncloud.org/ns":"oc","http://nextcloud.org/ns":"nc","http://open-collaboration-services.org/ns":"ocs"}};t.userName&&(i.userName=t.userName),t.password&&(i.password=t.password),this._client=new dav.Client(i),this._client.xhrProvider=l.default.bind(this._xhrProvider,this),this._fileInfoParsers=[]};s.NS_OWNCLOUD="http://owncloud.org/ns",s.NS_NEXTCLOUD="http://nextcloud.org/ns",s.NS_DAV="DAV:",s.NS_OCS="http://open-collaboration-services.org/ns",s.PROPERTY_GETLASTMODIFIED="{"+s.NS_DAV+"}getlastmodified",s.PROPERTY_GETETAG="{"+s.NS_DAV+"}getetag",s.PROPERTY_GETCONTENTTYPE="{"+s.NS_DAV+"}getcontenttype",s.PROPERTY_RESOURCETYPE="{"+s.NS_DAV+"}resourcetype",s.PROPERTY_INTERNAL_FILEID="{"+s.NS_OWNCLOUD+"}fileid",s.PROPERTY_PERMISSIONS="{"+s.NS_OWNCLOUD+"}permissions",s.PROPERTY_SIZE="{"+s.NS_OWNCLOUD+"}size",s.PROPERTY_GETCONTENTLENGTH="{"+s.NS_DAV+"}getcontentlength",s.PROPERTY_ISENCRYPTED="{"+s.NS_DAV+"}is-encrypted",s.PROPERTY_SHARE_PERMISSIONS="{"+s.NS_OCS+"}share-permissions",s.PROPERTY_SHARE_ATTRIBUTES="{"+s.NS_NEXTCLOUD+"}share-attributes",s.PROPERTY_QUOTA_AVAILABLE_BYTES="{"+s.NS_DAV+"}quota-available-bytes",s.PROTOCOL_HTTP="http",s.PROTOCOL_HTTPS="https",s._PROPFIND_PROPERTIES=[[s.NS_DAV,"getlastmodified"],[s.NS_DAV,"getetag"],[s.NS_DAV,"getcontenttype"],[s.NS_DAV,"resourcetype"],[s.NS_OWNCLOUD,"fileid"],[s.NS_OWNCLOUD,"permissions"],[s.NS_OWNCLOUD,"size"],[s.NS_DAV,"getcontentlength"],[s.NS_DAV,"quota-available-bytes"],[s.NS_NEXTCLOUD,"has-preview"],[s.NS_NEXTCLOUD,"mount-type"],[s.NS_NEXTCLOUD,"is-encrypted"],[s.NS_OCS,"share-permissions"],[s.NS_NEXTCLOUD,"share-attributes"]],s.prototype={_root:null,_client:null,_fileInfoParsers:[],_xhrProvider:function(){const t=this._defaultHeaders,s=new XMLHttpRequest,n=s.open;return s.open=function(){const e=n.apply(this,arguments);return l.default.each(t,function(e,t){s.setRequestHeader(t,e)}),e},e.registerXHRForErrorProcessing(s),s},_buildUrl:function(){let e=this._buildPath.apply(this,arguments);return"/"===e.charAt([e.length-1])&&(e=e.substr(0,e.length-1)),"/"===e.charAt(0)&&(e=e.substr(1)),this._baseUrl+"/"+e},_buildPath:function(){let t=e.joinPaths.apply(this,arguments);const s=t.split("/");let n;for(n=0;n<s.length;n++)s[n]=encodeURIComponent(s[n]);return t=s.join("/"),t},_parseHeaders:function(e){const t=e.split("\n"),s={};for(let e=0;e<t.length;e++){const n=t[e].indexOf(":");if(n<0)continue;const i=t[e].substr(0,n),r=t[e].substr(n+2);s[i]||(s[i]=[]),s[i].push(r)}return s},_parseEtag:function(e){return'"'===e.charAt(0)?e.split('"')[1]:e},_parseFileInfo:function(n){let i=decodeURIComponent(n.href);if(i.substr(0,this._root.length)===this._root&&(i=i.substr(this._root.length)),"/"===i.charAt(i.length-1)&&(i=i.substr(0,i.length-1)),0===n.propStat.length||"HTTP/1.1 200 OK"!==n.propStat[0].status)return null;const r=n.propStat[0].properties,o={id:r[s.PROPERTY_INTERNAL_FILEID],path:e.dirname(i)||"/",name:e.basename(i),mtime:new Date(r[s.PROPERTY_GETLASTMODIFIED]).getTime()},a=r[s.PROPERTY_GETETAG];l.default.isUndefined(a)||(o.etag=this._parseEtag(a));let u=r[s.PROPERTY_GETCONTENTLENGTH];l.default.isUndefined(u)||(o.size=parseInt(u,10)),u=r[s.PROPERTY_SIZE],l.default.isUndefined(u)||(o.size=parseInt(u,10));const d=r["{"+s.NS_NEXTCLOUD+"}has-preview"];l.default.isUndefined(d)?o.hasPreview=!0:o.hasPreview="true"===d;const p=r["{"+s.NS_NEXTCLOUD+"}is-encrypted"];l.default.isUndefined(p)?o.isEncrypted=!1:o.isEncrypted="1"===p;const f=r["{"+s.NS_OWNCLOUD+"}favorite"];l.default.isUndefined(f)?o.isFavourited=!1:o.isFavourited="1"===f;const h=r[s.PROPERTY_GETCONTENTTYPE];l.default.isUndefined(h)||(o.mimetype=h);const _=r[s.PROPERTY_RESOURCETYPE];if(!o.mimetype&&_){const e=_[0];e.namespaceURI===s.NS_DAV&&"collection"===e.nodeName.split(":")[1]&&(o.mimetype="httpd/unix-directory")}o.permissions=e.PERMISSION_NONE;const S=r[s.PROPERTY_PERMISSIONS];if(!l.default.isUndefined(S)){const t=S||"";o.mountType=null;for(let s=0;s<t.length;s++)switch(t.charAt(s)){case"C":case"K":o.permissions|=e.PERMISSION_CREATE;break;case"G":o.permissions|=e.PERMISSION_READ;break;case"W":case"N":case"V":o.permissions|=e.PERMISSION_UPDATE;break;case"D":o.permissions|=e.PERMISSION_DELETE;break;case"R":o.permissions|=e.PERMISSION_SHARE;break;case"M":o.mountType||(o.mountType="external");break;case"S":o.mountType="shared"}}const E=r[s.PROPERTY_SHARE_PERMISSIONS];l.default.isUndefined(E)||(o.sharePermissions=parseInt(E));const P=r[s.PROPERTY_SHARE_ATTRIBUTES];if(l.default.isUndefined(P))o.shareAttributes=[];else try{o.shareAttributes=JSON.parse(P)}catch{c.warn('Could not parse share attributes returned by server: "'+P+'"'),o.shareAttributes=[]}const T=r["{"+s.NS_NEXTCLOUD+"}mount-type"];l.default.isUndefined(T)||(o.mountType=T);const O=r["{"+s.NS_DAV+"}quota-available-bytes"];return l.default.isUndefined(O)||(o.quotaAvailableBytes=O),l.default.each(this._fileInfoParsers,function(e){l.default.extend(o,e(n,o)||{})}),new t(o)},_parseResult:function(e){const t=this;return l.default.map(e,function(e){return t._parseFileInfo(e)})},_isSuccessStatus:function(e){return e>=200&&e<=299},_getSabreException:function(e){const t={},s=e.xhr.responseXML;if(null===s)return t;const n=s.getElementsByTagNameNS("http://sabredav.org/ns","message"),i=s.getElementsByTagNameNS("http://sabredav.org/ns","exception");return n.length&&(t.message=n[0].textContent),i.length&&(t.exception=i[0].textContent),t},getPropfindProperties:function(){return this._propfindProperties||(this._propfindProperties=l.default.map(s._PROPFIND_PROPERTIES,function(e){return"{"+e[0]+"}"+e[1]})),this._propfindProperties},getFolderContents:function(e,t){e||(e=""),t=t||{};const s=this,n=a().Deferred(),i=n.promise();let r;return r=l.default.isUndefined(t.properties)?this.getPropfindProperties():t.properties,this._client.propFind(this._buildUrl(e),r,1).then(function(e){if(s._isSuccessStatus(e.status)){const i=s._parseResult(e.body);t&&t.includeParent||i.shift(),n.resolve(e.status,i)}else e=l.default.extend(e,s._getSabreException(e)),n.reject(e.status,e)}),i},getFilteredFiles:function(e,t){t=t||{};const s=this,n=a().Deferred(),i=n.promise();let o;if(o=l.default.isUndefined(t.properties)?this.getPropfindProperties():t.properties,!e||!e.systemTagIds&&l.default.isUndefined(e.favorite)&&!e.circlesIds)throw"Missing filter argument";let u,c="<oc:filter-files ";for(u in this._client.xmlNamespaces)c+=" xmlns:"+this._client.xmlNamespaces[u]+'="'+u+'"';return c+=">\n",c+=" <"+this._client.xmlNamespaces["DAV:"]+":prop>\n",l.default.each(o,function(e){const t=s._client.parseClarkNotation(e);c+=" <"+s._client.xmlNamespaces[t.namespace]+":"+t.name+" />\n"}),c+=" </"+this._client.xmlNamespaces["DAV:"]+":prop>\n",c+=" <oc:filter-rules>\n",l.default.each(e.systemTagIds,function(e){c+=" <oc:systemtag>"+r()(e)+"</oc:systemtag>\n"}),l.default.each(e.circlesIds,function(e){c+=" <oc:circle>"+r()(e)+"</oc:circle>\n"}),e.favorite&&(c+=" <oc:favorite>"+(e.favorite?"1":"0")+"</oc:favorite>\n"),c+=" </oc:filter-rules>\n",c+="</oc:filter-files>\n",this._client.request("REPORT",this._buildUrl(),{},c).then(function(e){if(s._isSuccessStatus(e.status)){const t=s._parseResult(e.body);n.resolve(e.status,t)}else e=l.default.extend(e,s._getSabreException(e)),n.reject(e.status,e)}),i},getFileInfo:function(e,t){e||(e=""),t=t||{};const s=this,n=a().Deferred(),i=n.promise();let r;return r=l.default.isUndefined(t.properties)?this.getPropfindProperties():t.properties,this._client.propFind(this._buildUrl(e),r,0).then(function(e){s._isSuccessStatus(e.status)?n.resolve(e.status,s._parseResult([e.body])[0]):(e=l.default.extend(e,s._getSabreException(e)),n.reject(e.status,e))}),i},getFileContents:function(e){if(!e)throw'Missing argument "path"';const t=this,s=a().Deferred(),n=s.promise();return this._client.request("GET",this._buildUrl(e)).then(function(e){t._isSuccessStatus(e.status)?s.resolve(e.status,e.body):(e=l.default.extend(e,t._getSabreException(e)),s.reject(e.status,e))}),n},putFileContents:function(e,t,s){if(!e)throw'Missing argument "path"';const n=this,i=a().Deferred(),r=i.promise(),o={};let u="text/plain;charset=utf-8";return(s=s||{}).contentType&&(u=s.contentType),o["Content-Type"]=u,(l.default.isUndefined(s.overwrite)||s.overwrite)&&(o["If-None-Match"]="*"),this._client.request("PUT",this._buildUrl(e),o,t||"").then(function(e){n._isSuccessStatus(e.status)?i.resolve(e.status):(e=l.default.extend(e,n._getSabreException(e)),i.reject(e.status,e))}),r},_simpleCall:function(e,t,s){if(!t)throw'Missing argument "path"';const n=this,i=a().Deferred(),r=i.promise();return this._client.request(e,this._buildUrl(t),s||{}).then(function(e){n._isSuccessStatus(e.status)?i.resolve(e.status):(e=l.default.extend(e,n._getSabreException(e)),i.reject(e.status,e))}),r},createDirectory:function(e,t){return this._simpleCall("MKCOL",e,t)},remove:function(e){return this._simpleCall("DELETE",e)},move:function(e,t,s,n){if(!e)throw'Missing argument "path"';if(!t)throw'Missing argument "destinationPath"';const i=this,r=a().Deferred(),o=r.promise();return n=l.default.extend({},n,{Destination:this._buildUrl(t)}),s||(n.Overwrite="F"),this._client.request("MOVE",this._buildUrl(e),n).then(function(e){i._isSuccessStatus(e.status)?r.resolve(e.status):(e=l.default.extend(e,i._getSabreException(e)),r.reject(e.status,e))}),o},copy:function(e,t,s){if(!e)throw'Missing argument "path"';if(!t)throw'Missing argument "destinationPath"';const n=this,i=a().Deferred(),r=i.promise(),o={Destination:this._buildUrl(t)};return s||(o.Overwrite="F"),this._client.request("COPY",this._buildUrl(e),o).then(function(e){n._isSuccessStatus(e.status)?i.resolve(e.status):i.reject(e.status)}),r},addFileInfoParser:function(e){this._fileInfoParsers.push(e)},getClient:function(){return this._client},getUserName:function(){return this._client.userName},getPassword:function(){return this._client.password},getBaseUrl:function(){return this._client.baseUrl},getHost:function(){return this._host}},e.Files||(e.Files={}),e.Files.getClient=function(){if(e.Files._defaultClient)return e.Files._defaultClient;const t=new e.Files.Client({host:window.location.host,port:window.location.port,root:e.linkToRemoteBase("dav")+"/files/"+(0,n.HW)().uid,useHTTPS:window.location.protocol.startsWith("https")});return e.Files._defaultClient=t,t},e.Files.Client=s}(OC,OC.Files.FileInfo)}},s={};function n(e){var i=s[e];if(void 0!==i)return i.exports;var r=s[e]={id:e,loaded:!1,exports:{}};return t[e].call(r.exports,r,r.exports,n),r.loaded=!0,r.exports}n.m=t,e=[],n.O=(t,s,i,r)=>{if(!s){var o=1/0;for(c=0;c<e.length;c++){for(var[s,i,r]=e[c],a=!0,l=0;l<s.length;l++)(!1&r||o>=r)&&Object.keys(n.O).every(e=>n.O[e](s[l]))?s.splice(l--,1):(a=!1,r<o&&(o=r));if(a){e.splice(c--,1);var u=i();void 0!==u&&(t=u)}}return t}r=r||0;for(var c=e.length;c>0&&e[c-1][2]>r;c--)e[c]=e[c-1];e[c]=[s,i,r]},n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var s in t)n.o(t,s)&&!n.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},n.e=()=>Promise.resolve(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),n.j=590,(()=>{var e={590:0};n.O.j=t=>0===e[t];var t=(t,s)=>{var i,r,[o,a,l]=s,u=0;if(o.some(t=>0!==e[t])){for(i in a)n.o(a,i)&&(n.m[i]=a[i]);if(l)var c=l(n)}for(t&&t(s);u<o.length;u++)r=o[u],n.o(e,r)&&e[r]&&e[r][0](),e[r]=0;return n.O(c)},s=globalThis.webpackChunknextcloud_ui_legacy=globalThis.webpackChunknextcloud_ui_legacy||[];s.forEach(t.bind(null,0)),s.push=t.bind(null,s.push.bind(s))})(),n.nc=void 0;var i=n.O(void 0,[4208],()=>n(12871));i=n.O(i)})();
//# sourceMappingURL=core-files_client.js.map?v=2758900530cde6e64f89