nextcloud-swarm-plugin/js/fileactions.js
retrevor 712dadb95d
25 right click options on files stored in swarm to copy hash (#37)
* First version based on trash_bin

* Draft version missing the jquery parse of the webdav response

* First working version.

* Showing right-click menu action but not disabled for non-Swarm storages

* Trying to disable/hide/unregister the menu option

* Final adjustments, menuClick and rightClick

* Clean and refactor of code

* Obsolete files removed

* lint fix

* Changes to PR

* Backward compatibility for NC 23-25

* Optimization

* Removed deprecated reference for loading scripts

---------

Co-authored-by: Ron <>
Co-authored-by: Magnus Walbeck <mw@mwalbeck.org>
2023-03-01 13:01:58 +01:00

61 lines
2.4 KiB
JavaScript

/*
* @copyright Copyright (c) 2023, MetaProvide Holding EKF
*
* @author Ron Trevor <ecoron@proton.me>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
window.addEventListener('DOMContentLoaded', () => {
OCA.Files.fileActions.registerAction({
name: 'EthswarmCopyRef',
displayName: t('files_external_ethswarm', 'Copy Swarm reference'),
altText: t('files_external_ethswarm', 'Copy Swarm reference to clipboard'),
mime: 'all',
permissions: OC.PERMISSION_READ,
type: OCA.Files.FileActions.TYPE_DROPDOWN,
iconClass: 'icon-clippy',
actionHandler: function (filename, context) {
if (context.$file && context.fileInfoModel.attributes.mountType != "external") {
return;
}
remoteurl = OC.linkToRemoteBase("dav/files/" + OC.currentUser + context.fileInfoModel.attributes['path'] + "/" + filename);
$.ajax({
type: "PROPFIND",
async: "false",
url: remoteurl,
data: '<?xml version="1.0" encoding="UTF-8"?>' +
'<d:propfind xmlns:d="DAV:" xmlns:nc="http://nextcloud.org/ns">' +
'<d:prop><nc:ethswarm-fileref/></d:prop>' +
'</d:propfind>',
success: function (element) {
swarmref = element.firstChild.firstChild.lastChild.firstChild.firstChild.textContent;
navigator.clipboard.writeText(swarmref).then(
() => {
/* clipboard successfully set */
OC.dialogs.info(t('files_external_ethswarm', 'The following Swarm reference has been copied to the clipboard: ') + swarmref, t('files_external_ethswarm', 'Swarm reference'));
},
() => {
/* clipboard write failed */
OC.dialogs.info(t('files_external_ethswarm', 'Unable to write to the clipboard, you can manually copy the Swarm reference below: ' + swarmref), t('files_external_ethswarm', 'Swarm reference'));
}
);
}
});
}
});
});