nextcloud-server/dist/federatedfilesharing-init-f...

1 line
11 KiB
Plaintext

{"version":3,"file":"federatedfilesharing-init-files.mjs","sources":["../build/frontend/apps/federatedfilesharing/src/components/RemoteShareDialog.vue","../build/frontend/apps/federatedfilesharing/src/services/dialogService.ts","../build/frontend/apps/federatedfilesharing/src/init-files.js"],"sourcesContent":["<!--\n - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors\n - SPDX-License-Identifier: AGPL-3.0-or-later\n-->\n<script setup lang=\"ts\">\nimport { t } from '@nextcloud/l10n'\nimport { computed, ref } from 'vue'\nimport NcDialog from '@nextcloud/vue/components/NcDialog'\nimport NcPasswordField from '@nextcloud/vue/components/NcPasswordField'\n\nconst props = defineProps<{\n\t/** Name of the share */\n\tname: string\n\t/** Display name of the owner */\n\towner: string\n\t/** The remote instance name */\n\tremote: string\n\t/** True if the user should enter a password */\n\tpasswordRequired: boolean\n}>()\n\nconst emit = defineEmits<{\n\tclose: [state: boolean, password?: string]\n}>()\n\nconst password = ref('')\n\ntype INcDialogButtons = InstanceType<typeof NcDialog>['$props']['buttons']\n\n/**\n * The dialog buttons\n */\nconst buttons = computed<INcDialogButtons>(() => [\n\t{\n\t\tlabel: t('federatedfilesharing', 'Cancel'),\n\t\tcallback: () => emit('close', false),\n\t},\n\t{\n\t\tlabel: t('federatedfilesharing', 'Add remote share'),\n\t\ttype: props.passwordRequired ? 'submit' : undefined,\n\t\tvariant: 'primary',\n\t\tcallback: () => emit('close', true, password.value),\n\t},\n])\n</script>\n\n<template>\n\t<NcDialog\n\t\t:buttons=\"buttons\"\n\t\t:is-form=\"passwordRequired\"\n\t\t:name=\"t('federatedfilesharing', 'Remote share')\"\n\t\t@submit=\"emit('close', true, password)\">\n\t\t<p>\n\t\t\t{{ t('federatedfilesharing', 'Do you want to add the remote share {name} from {owner}@{remote}?', { name, owner, remote }) }}\n\t\t</p>\n\t\t<NcPasswordField\n\t\t\tv-if=\"passwordRequired\"\n\t\t\tv-model=\"password\"\n\t\t\t:class=\"$style.remoteShareDialog__password\"\n\t\t\t:label=\"t('federatedfilesharing', 'Remote share password')\" />\n\t</NcDialog>\n</template>\n\n<style module>\n.remoteShareDialog__password {\n\tmargin-block: 1em .5em;\n}\n</style>\n","/**\n * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport { spawnDialog } from '@nextcloud/vue/functions/dialog'\nimport RemoteShareDialog from '../components/RemoteShareDialog.vue'\n\n/**\n * Open a dialog to ask the user whether to add a remote share.\n *\n * @param name The name of the share\n * @param owner The owner of the share\n * @param remote The remote address\n * @param passwordRequired True if the share is password protected\n */\nexport async function showRemoteShareDialog(\n\tname: string,\n\towner: string,\n\tremote: string,\n\tpasswordRequired = false,\n): Promise<string | void> {\n\tconst [status, password] = await spawnDialog(RemoteShareDialog, {\n\t\tname,\n\t\towner,\n\t\tremote,\n\t\tpasswordRequired,\n\t})\n\n\tif (passwordRequired && status) {\n\t\treturn password as string\n\t} else if (status) {\n\t\treturn\n\t} else {\n\t\tthrow new Error('Dialog was cancelled')\n\t}\n}\n","/**\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 */\n\nimport axios, { isAxiosError } from '@nextcloud/axios'\nimport { showError, showInfo } from '@nextcloud/dialogs'\nimport { subscribe } from '@nextcloud/event-bus'\nimport { loadState } from '@nextcloud/initial-state'\nimport { t } from '@nextcloud/l10n'\nimport { generateUrl } from '@nextcloud/router'\nimport { showRemoteShareDialog } from './services/dialogService.ts'\nimport logger from './services/logger.ts'\n\nwindow.addEventListener('DOMContentLoaded', () => {\n\tprocessIncomingShareFromUrl()\n\n\tif (loadState('federatedfilesharing', 'notificationsEnabled', true) !== true) {\n\t\t// No notification app, display the modal\n\t\tprocessSharesToConfirm()\n\t}\n\n\tsubscribe('notifications:action:executed', ({ action, notification }) => {\n\t\tif (notification.app === 'files_sharing' && notification.object_type === 'remote_share' && action.type === 'POST') {\n\t\t\t// User accepted a remote share reload\n\t\t\treloadFilesList()\n\t\t}\n\t})\n})\n\n/**\n * Reload the files list to show accepted shares\n */\nfunction reloadFilesList() {\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 */\nfunction processIncomingShareFromUrl() {\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\t\tconst callbackAddShare = (result, share) => {\n\t\t\tif (result === false) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\taxios.post(\n\t\t\t\tgenerateUrl('apps/federatedfilesharing/askForFederatedShare'),\n\t\t\t\t{\n\t\t\t\t\tremote: share.remote,\n\t\t\t\t\ttoken: share.token,\n\t\t\t\t\towner: share.owner,\n\t\t\t\t\townerDisplayName: share.ownerDisplayName || share.owner,\n\t\t\t\t\tname: share.name,\n\t\t\t\t\tpassword: share.password || '',\n\t\t\t\t},\n\t\t\t).then(({ data }) => {\n\t\t\t\tif (Object.hasOwn(data, 'legacyMount')) {\n\t\t\t\t\treloadFilesList()\n\t\t\t\t} else {\n\t\t\t\t\tshowInfo(data.message)\n\t\t\t\t}\n\t\t\t}).catch((error) => {\n\t\t\t\tlogger.error('Error while processing incoming share', { error })\n\n\t\t\t\tif (isAxiosError(error) && error.response.data.message) {\n\t\t\t\t\tshowError(error.response.data.message)\n\t\t\t\t} else {\n\t\t\t\t\tshowError(t('federatedfilesharing', 'Incoming share could not be processed'))\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\tshowAddExternalDialog(\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 */\nasync function processSharesToConfirm() {\n\t// check for new server-to-server shares which need to be approved\n\tconst { data: shares } = await axios.get(generateUrl('/apps/files_sharing/api/externalShares'))\n\tfor (let index = 0; index < shares.length; ++index) {\n\t\tshowAddExternalDialog(\n\t\t\tshares[index],\n\t\t\tfalse,\n\t\t\tfunction(result, share) {\n\t\t\t\tif (result === false) {\n\t\t\t\t\t// Delete\n\t\t\t\t\taxios.delete(generateUrl('/apps/files_sharing/api/externalShares/' + share.id))\n\t\t\t\t} else {\n\t\t\t\t\t// Accept\n\t\t\t\t\taxios.post(generateUrl('/apps/files_sharing/api/externalShares'), { id: share.id })\n\t\t\t\t\t\t.then(() => reloadFilesList())\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t}\n}\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 */\nfunction showAddExternalDialog(share, passwordProtected, callback) {\n\tconst owner = share.ownerDisplayName || share.owner\n\tconst name = share.name\n\n\t// Clean up the remote URL for display\n\tconst remote = share.remote\n\t\t.replace(/^https?:\\/\\//, '') // remove http:// or https://\n\t\t.replace(/\\/$/, '') // remove trailing slash\n\n\tshowRemoteShareDialog(name, owner, remote, passwordProtected)\n\t\t.then((password) => callback(true, { ...share, password }))\n\t\t.catch(() => callback(false, share))\n}\n"],"names":["props","__props","emit","__emit","password","ref","buttons","computed","t","_createBlock","_unref","NcDialog","_cache","$event","_createElementVNode","NcPasswordField","_normalizeClass","$style","showRemoteShareDialog","name","owner","remote","passwordRequired","status","spawnDialog","RemoteShareDialog","processIncomingShareFromUrl","loadState","processSharesToConfirm","subscribe","action","notification","reloadFilesList","params","callbackAddShare","result","share","axios","generateUrl","data","showInfo","error","logger","isAxiosError","showError","showAddExternalDialog","shares","index","passwordProtected","callback"],"mappings":"ogBAUA,MAAMA,EAAQC,EAWRC,EAAOC,EAIPC,EAAWC,EAAI,EAAE,EAOjBC,EAAUC,EAA2B,IAAM,CAChD,CACC,MAAOC,EAAE,uBAAwB,QAAQ,EACzC,SAAU,IAAMN,EAAK,QAAS,EAAK,CAAA,EAEpC,CACC,MAAOM,EAAE,uBAAwB,kBAAkB,EACnD,KAAMR,EAAM,iBAAmB,SAAW,OAC1C,QAAS,UACT,SAAU,IAAME,EAAK,QAAS,GAAME,EAAS,KAAK,CAAA,CACnD,CACA,oBAIAK,EAaWC,EAAAC,CAAA,EAAA,CAZT,QAASL,EAAA,MACT,UAASL,EAAA,iBACT,KAAMS,EAAAF,CAAA,EAAC,uBAAA,cAAA,EACP,SAAMI,EAAA,CAAA,IAAAA,EAAA,CAAA,EAAAC,GAAEX,EAAI,QAAA,GAAgBE,EAAA,KAAQ,EAAA,aACrC,IAEI,CAFJU,EAEI,WADAJ,EAAAF,CAAA,EAAC,uBAAA,oEAAA,CAAA,KAAgGP,OAAI,MAAEA,EAAA,aAAOA,EAAA,MAAA,CAAM,CAAA,EAAA,CAAA,EAGjHA,EAAA,sBADPQ,EAI+DC,EAAAK,CAAA,EAAA,kBAFrDX,EAAA,2CAAAA,EAAQ,MAAAS,GAChB,MAAKG,EAAEC,EAAAA,OAAO,2BAA2B,EACzC,MAAOP,EAAAF,CAAA,EAAC,uBAAA,uBAAA,CAAA,kNC3CZ,eAAsBU,EACrBC,EACAC,EACAC,EACAC,EAAmB,GACM,CACzB,KAAM,CAACC,EAAQnB,CAAQ,EAAI,MAAMoB,EAAYC,EAAmB,CAC/D,KAAA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