snappymail/plugins/nextcloud/js/composer.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-10-21 18:17:49 +08:00
(rl => {
// if (rl.settings.get('Nextcloud'))
addEventListener('rl-view-model.create', e => {
if ('PopupsCompose' === e.detail.viewModelTemplateID) {
let view = e.detail;
view.nextcloudAttach = () => {
2022-10-25 22:08:28 +08:00
rl.nextcloud.selectFiles().then(files => {
files && files.forEach(file => {
let attachment = view.addAttachmentHelper(
Jua?.randomId(),
2022-10-21 18:17:49 +08:00
file.name.replace(/^.*\/([^/]+)$/, '$1'),
file.size
);
attachment
.waiting(false)
.uploading(true)
.complete(false);
rl.pluginRemoteRequest(
(iError, data) => {
attachment
.uploading(false)
.complete(true);
if (iError) {
attachment.error(data?.Result?.error || 'failed');
} else {
attachment.tempName(data.Result.tempName);
}
},
'NextcloudAttachFile',
{
'file': file.name
}
);
});
});
};
}
});
let template = document.getElementById('PopupsCompose');
const uploadBtn = template.content.querySelector('#composeUploadButton');
if (uploadBtn) {
2022-10-28 15:58:04 +08:00
uploadBtn.after(Element.fromHTML(`<a class="btn fontastic" data-bind="click: nextcloudAttach"
data-i18n="[title]NEXTCLOUD/ATTACH_FILES"></a>`));
2022-10-21 18:17:49 +08:00
}
2022-10-28 07:44:04 +08:00
/**
https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html
POST /ocs/v2.php/apps/files_sharing/api/v1/shares
JSON {
"path":"/Nextcloud intro.mp4",
"shareType":3, // public link
"shareWith":"user@example.com",
// "publicUpload":false,
// "password":null,
// "permissions":1, // default
// "expireDate":"YYYY-MM-DD",
// "note":"Especially for you"
}
*/
2022-10-21 18:17:49 +08:00
})(window.rl);