federatedfilesharing-external.mjs.map 8.3 KB

1
  1. {"version":3,"file":"federatedfilesharing-external.mjs","sources":["../apps/federatedfilesharing/src/external.js"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors\n * SPDX-FileCopyrightText: 2014-2016 ownCloud, Inc.\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { loadState } from '@nextcloud/initial-state'\nimport { generateUrl } from '@nextcloud/router'\n\nwindow.OCA.Sharing = window.OCA.Sharing || {}\n\n/**\n * Shows \"add external share\" dialog.\n *\n * @param {object} share the share\n * @param {string} share.remote remote server URL\n * @param {string} share.owner owner name\n * @param {string} share.name name of the shared folder\n * @param {string} share.token authentication token\n * @param {boolean} passwordProtected true if the share is password protected\n * @param {Function} callback the callback\n */\nwindow.OCA.Sharing.showAddExternalDialog = function(share, passwordProtected, callback) {\n\tconst remote = share.remote\n\tconst owner = share.ownerDisplayName || share.owner\n\tconst name = share.name\n\n\t// Clean up the remote URL for display\n\tconst remoteClean = remote\n\t\t.replace(/^https?:\\/\\//, '') // remove http:// or https://\n\t\t.replace(/\\/$/, '') // remove trailing slash\n\n\tif (!passwordProtected) {\n\t\twindow.OC.dialogs.confirm(\n\t\t\tt(\n\t\t\t\t'files_sharing',\n\t\t\t\t'Do you want to add the remote share {name} from {owner}@{remote}?',\n\t\t\t\t{ name, owner, remote: remoteClean },\n\t\t\t),\n\t\t\tt('files_sharing', 'Remote share'),\n\t\t\tfunction(result) {\n\t\t\t\tcallback(result, share)\n\t\t\t},\n\t\t\ttrue,\n\t\t).then(this._adjustDialog)\n\t} else {\n\t\twindow.OC.dialogs.prompt(\n\t\t\tt(\n\t\t\t\t'files_sharing',\n\t\t\t\t'Do you want to add the remote share {name} from {owner}@{remote}?',\n\t\t\t\t{ name, owner, remote: remoteClean },\n\t\t\t),\n\t\t\tt('files_sharing', 'Remote share'),\n\t\t\tfunction(result, password) {\n\t\t\t\tshare.password = password\n\t\t\t\tcallback(result, share)\n\t\t\t},\n\t\t\ttrue,\n\t\t\tt('files_sharing', 'Remote share password'),\n\t\t\ttrue,\n\t\t).then(this._adjustDialog)\n\t}\n}\n\nwindow.OCA.Sharing._adjustDialog = function() {\n\tconst $dialog = $('.oc-dialog:visible')\n\tconst $buttons = $dialog.find('button')\n\t// hack the buttons\n\t$dialog.find('.ui-icon').remove()\n\t$buttons.eq(1).text(t('core', 'Cancel'))\n\t$buttons.eq(2).text(t('files_sharing', 'Add remote share'))\n}\n\nconst reloadFilesList = function() {\n\tif (!window?.OCP?.Files?.Router?.goToRoute) {\n\t\t// No router, just reload the page\n\t\twindow.location.reload()\n\t\treturn\n\t}\n\n\t// Let's redirect to the root as any accepted share would be there\n\twindow.OCP.Files.Router.goToRoute(\n\t\tnull,\n\t\t{ ...window.OCP.Files.Router.params, fileid: undefined },\n\t\t{ ...window.OCP.Files.Router.query, dir: '/', openfile: undefined },\n\t)\n}\n\n/**\n * Process incoming remote share that might have been passed\n * through the URL\n */\nconst processIncomingShareFromUrl = function() {\n\tconst params = window.OC.Util.History.parseUrlQuery()\n\n\t// manually add server-to-server share\n\tif (params.remote && params.token && params.name) {\n\n\t\tconst callbackAddShare = function(result, share) {\n\t\t\tconst password = share.password || ''\n\t\t\tif (result) {\n\t\t\t\t$.post(\n\t\t\t\t\tgenerateUrl('apps/federatedfilesharing/askForFederatedShare'),\n\t\t\t\t\t{\n\t\t\t\t\t\tremote: share.remote,\n\t\t\t\t\t\ttoken: share.token,\n\t\t\t\t\t\towner: share.owner,\n\t\t\t\t\t\townerDisplayName: share.ownerDisplayName || share.owner,\n\t\t\t\t\t\tname: share.name,\n\t\t\t\t\t\tpassword,\n\t\t\t\t\t},\n\t\t\t\t).done(function(data) {\n\t\t\t\t\tif (data.hasOwnProperty('legacyMount')) {\n\t\t\t\t\t\treloadFilesList()\n\t\t\t\t\t} else {\n\t\t\t\t\t\twindow.OC.Notification.showTemporary(data.message)\n\t\t\t\t\t}\n\t\t\t\t}).fail(function(data) {\n\t\t\t\t\twindow.OC.Notification.showTemporary(JSON.parse(data.responseText).message)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\t// clear hash, it is unlikely that it contain any extra parameters\n\t\tlocation.hash = ''\n\t\tparams.passwordProtected = parseInt(params.protected, 10) === 1\n\t\twindow.OCA.Sharing.showAddExternalDialog(\n\t\t\tparams,\n\t\t\tparams.passwordProtected,\n\t\t\tcallbackAddShare,\n\t\t)\n\t}\n}\n\n/**\n * Retrieve a list of remote shares that need to be approved\n */\nconst processSharesToConfirm = function() {\n\t// check for new server-to-server shares which need to be approved\n\t$.get(generateUrl('/apps/files_sharing/api/externalShares'), {}, function(shares) {\n\t\tlet index\n\t\tfor (index = 0; index < shares.length; ++index) {\n\t\t\twindow.OCA.Sharing.showAddExternalDialog(\n\t\t\t\tshares[index],\n\t\t\t\tfalse,\n\t\t\t\tfunction(result, share) {\n\t\t\t\t\tif (result) {\n\t\t\t\t\t\t// Accept\n\t\t\t\t\t\t$.post(generateUrl('/apps/files_sharing/api/externalShares'), { id: share.id })\n\t\t\t\t\t\t\t.then(function() {\n\t\t\t\t\t\t\t\treloadFilesList()\n\t\t\t\t\t\t\t})\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Delete\n\t\t\t\t\t\t$.ajax({\n\t\t\t\t\t\t\turl: generateUrl('/apps/files_sharing/api/externalShares/' + share.id),\n\t\t\t\t\t\t\ttype: 'DELETE',\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t})\n}\n\nprocessIncomingShareFromUrl()\n\nif (loadState('federatedfilesharing', 'notificationsEnabled', true) !== true) {\n\t// No notification app, display the modal\n\tprocessSharesToConfirm()\n}\n\n$('body').on('window.OCA.Notification.Action', function(e) {\n\tif (e.notification.app === 'files_sharing' && e.notification.object_type === 'remote_share' && e.action.type === 'POST') {\n\t\t// User accepted a remote share reload\n\t\treloadFilesList()\n\t}\n})\n"],"names":["share","passwordProtected","callback","remote","owner","name","remoteClean","result","password","$dialog","$buttons","reloadFilesList","_c","_b","_a","processIncomingShareFromUrl","params","callbackAddShare","generateUrl","data","processSharesToConfirm","shares","index","loadState"],"mappings":";+CAQA,OAAO,IAAI,QAAU,OAAO,IAAI,SAAW,CAAE,EAa7C,OAAO,IAAI,QAAQ,sBAAwB,SAASA,EAAOC,EAAmBC,EAAU,CACvF,MAAMC,EAASH,EAAM,OACfI,EAAQJ,EAAM,kBAAoBA,EAAM,MACxCK,EAAOL,EAAM,KAGbM,EAAcH,EAClB,QAAQ,eAAgB,EAAE,EAC1B,QAAQ,MAAO,EAAE,EAEdF,EAcJ,OAAO,GAAG,QAAQ,OACjB,EACC,gBACA,oEACA,CAAE,KAAAI,EAAM,MAAAD,EAAO,OAAQE,CAAa,CACpC,EACD,EAAE,gBAAiB,cAAc,EACjC,SAASC,EAAQC,EAAU,CAC1BR,EAAM,SAAWQ,EACjBN,EAASK,EAAQP,CAAK,CACtB,EACD,GACA,EAAE,gBAAiB,uBAAuB,EAC1C,EACH,EAAI,KAAK,KAAK,aAAa,EA3BzB,OAAO,GAAG,QAAQ,QACjB,EACC,gBACA,oEACA,CAAE,KAAAK,EAAM,MAAAD,EAAO,OAAQE,CAAa,CACpC,EACD,EAAE,gBAAiB,cAAc,EACjC,SAASC,EAAQ,CAChBL,EAASK,EAAQP,CAAK,CACtB,EACD,EACH,EAAI,KAAK,KAAK,aAAa,CAkB3B,EAEA,OAAO,IAAI,QAAQ,cAAgB,UAAW,CAC7C,MAAMS,EAAU,EAAE,oBAAoB,EAChCC,EAAWD,EAAQ,KAAK,QAAQ,EAEtCA,EAAQ,KAAK,UAAU,EAAE,OAAQ,EACjCC,EAAS,GAAG,CAAC,EAAE,KAAK,EAAE,OAAQ,QAAQ,CAAC,EACvCA,EAAS,GAAG,CAAC,EAAE,KAAK,EAAE,gBAAiB,kBAAkB,CAAC,CAC3D,EAEA,MAAMC,EAAkB,UAAW,WAClC,GAAI,GAACC,GAAAC,GAAAC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