mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Share public/internal file link #569
This commit is contained in:
parent
7fafb6ee9c
commit
31aaf80f00
3 changed files with 49 additions and 67 deletions
|
|
@ -4,8 +4,8 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
{
|
{
|
||||||
const
|
const
|
||||||
NAME = 'Nextcloud',
|
NAME = 'Nextcloud',
|
||||||
VERSION = '2.10',
|
VERSION = '2.11',
|
||||||
RELEASE = '2022-11-04',
|
RELEASE = '2022-11-14',
|
||||||
CATEGORY = 'Integrations',
|
CATEGORY = 'Integrations',
|
||||||
DESCRIPTION = 'Integrate with Nextcloud v20+',
|
DESCRIPTION = 'Integrate with Nextcloud v20+',
|
||||||
REQUIRED = '2.19.0';
|
REQUIRED = '2.19.0';
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else if (file.url) {
|
} else if (file.url) {
|
||||||
|
// TODO: other editors and text/plain
|
||||||
view.oEditor.editor.squire.makeLink(file.url);
|
view.oEditor.editor.squire.makeLink(file.url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ const
|
||||||
OC = () => parent.OC,
|
OC = () => parent.OC,
|
||||||
|
|
||||||
// Nextcloud 19 deprecated generateUrl, but screw `import { generateUrl } from "@nextcloud/router"`
|
// Nextcloud 19 deprecated generateUrl, but screw `import { generateUrl } from "@nextcloud/router"`
|
||||||
|
shareUrl = () => OC().webroot + '/ocs/v2.php/apps/files_sharing/api/v1/shares',
|
||||||
generateUrl = path => OC().webroot + (OC().config.modRewriteWorking ? '' : '/index.php') + path,
|
generateUrl = path => OC().webroot + (OC().config.modRewriteWorking ? '' : '/index.php') + path,
|
||||||
generateRemoteUrl = path => location.protocol + '//' + location.host + generateUrl(path),
|
generateRemoteUrl = path => location.protocol + '//' + location.host + generateUrl(path),
|
||||||
|
|
||||||
|
|
@ -22,36 +23,10 @@ const
|
||||||
<oc:size/>
|
<oc:size/>
|
||||||
<resourcetype/>
|
<resourcetype/>
|
||||||
<getcontentlength/>
|
<getcontentlength/>
|
||||||
|
|
||||||
<getcontenttype/>
|
|
||||||
<oc:permissions/>
|
|
||||||
<ocs:share-permissions/>
|
<ocs:share-permissions/>
|
||||||
<nc:share-attributes/>
|
|
||||||
<oc:share-types/>
|
<oc:share-types/>
|
||||||
<nc:is-encrypted/>
|
|
||||||
</prop>
|
</prop>
|
||||||
</propfind>`,
|
</propfind>`,
|
||||||
/*
|
|
||||||
<d:propstat>
|
|
||||||
<d:prop>
|
|
||||||
<d:getcontenttype>video/mp4</d:getcontenttype>
|
|
||||||
<oc:permissions>RGDNVW</oc:permissions>
|
|
||||||
<d:getcontentlength>3963036</d:getcontentlength>
|
|
||||||
<ocs:share-permissions>19</ocs:share-permissions>
|
|
||||||
<nc:share-attributes>[]</nc:share-attributes>
|
|
||||||
<oc:share-types>
|
|
||||||
<oc:share-type>3</oc:share-type>
|
|
||||||
</oc:share-types>
|
|
||||||
</d:prop>
|
|
||||||
<d:status>HTTP/1.1 200 OK</d:status>
|
|
||||||
</d:propstat>
|
|
||||||
<d:propstat>
|
|
||||||
<d:prop>
|
|
||||||
<nc:is-encrypted/>
|
|
||||||
</d:prop>
|
|
||||||
<d:status>HTTP/1.1 404 Not Found</d:status>
|
|
||||||
</d:propstat>
|
|
||||||
*/
|
|
||||||
|
|
||||||
propfindCal = `<?xml version="1.0"?>
|
propfindCal = `<?xml version="1.0"?>
|
||||||
<propfind xmlns="DAV:">
|
<propfind xmlns="DAV:">
|
||||||
|
|
@ -70,11 +45,10 @@ const
|
||||||
getDavElementByTagName = (parent, localName) => getDavElementsByTagName(parent, localName)?.item(0),
|
getDavElementByTagName = (parent, localName) => getDavElementsByTagName(parent, localName)?.item(0),
|
||||||
getElementByTagName = (parent, localName) => +parent.getElementsByTagName(localName)?.item(0),
|
getElementByTagName = (parent, localName) => +parent.getElementsByTagName(localName)?.item(0),
|
||||||
|
|
||||||
davFetch = (mode, path, options) => {
|
ncFetch = (path, options) => {
|
||||||
if (!OC().requestToken) {
|
if (!OC().requestToken) {
|
||||||
return Promise.reject(new Error('OC.requestToken missing'));
|
return Promise.reject(new Error('OC.requestToken missing'));
|
||||||
}
|
}
|
||||||
let cfg = rl.settings.get('Nextcloud');
|
|
||||||
options = Object.assign({
|
options = Object.assign({
|
||||||
mode: 'same-origin',
|
mode: 'same-origin',
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
|
|
@ -83,8 +57,13 @@ const
|
||||||
headers: {}
|
headers: {}
|
||||||
}, options);
|
}, options);
|
||||||
options.headers.requesttoken = OC().requestToken;
|
options.headers.requesttoken = OC().requestToken;
|
||||||
|
return fetch(path, options);
|
||||||
|
},
|
||||||
|
|
||||||
|
davFetch = (mode, path, options) => {
|
||||||
|
let cfg = rl.settings.get('Nextcloud');
|
||||||
// cfg.UID = document.head.dataset.user
|
// cfg.UID = document.head.dataset.user
|
||||||
return fetch(cfg.WebDAV + '/' + mode + '/' + cfg.UID + path, options);
|
return ncFetch(cfg.WebDAV + '/' + mode + '/' + cfg.UID + path, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
davFetchFiles = (path, options) => davFetch('files', path, options),
|
davFetchFiles = (path, options) => davFetch('files', path, options),
|
||||||
|
|
@ -129,6 +108,7 @@ const
|
||||||
elem.id = e.getElementsByTagNameNS(nsOC, 'fileid')?.item(0)?.textContent;
|
elem.id = e.getElementsByTagNameNS(nsOC, 'fileid')?.item(0)?.textContent;
|
||||||
elem.size = getDavElementByTagName(e, 'getcontentlength')?.textContent
|
elem.size = getDavElementByTagName(e, 'getcontentlength')?.textContent
|
||||||
|| getElementByTagName(e, 'oc:size')?.textContent;
|
|| getElementByTagName(e, 'oc:size')?.textContent;
|
||||||
|
elem.shared = [...e.getElementsByTagNameNS(nsOC, 'share-type')].some(node => '3' == node.textContent);
|
||||||
}
|
}
|
||||||
elemList.push(elem);
|
elemList.push(elem);
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +156,7 @@ const
|
||||||
li.dataset.icon = '🗎';
|
li.dataset.icon = '🗎';
|
||||||
|
|
||||||
btn.name = 'select';
|
btn.name = 'select';
|
||||||
btn.textContent = 'select';
|
btn.textContent = '📎 attach';
|
||||||
btn.className = 'button-vue';
|
btn.className = 'button-vue';
|
||||||
li.append(btn);
|
li.append(btn);
|
||||||
|
|
||||||
|
|
@ -185,13 +165,13 @@ const
|
||||||
btn.textContent = '🔗 internal';
|
btn.textContent = '🔗 internal';
|
||||||
btn.className = 'button-vue';
|
btn.className = 'button-vue';
|
||||||
li.append(btn);
|
li.append(btn);
|
||||||
/*
|
|
||||||
btn = document.createElement('button');
|
btn = document.createElement('button');
|
||||||
btn.name = 'share-public';
|
btn.name = 'share-public';
|
||||||
btn.textContent = '🔗 public';
|
btn.textContent = '🔗 public';
|
||||||
btn.className = 'button-vue';
|
btn.className = 'button-vue';
|
||||||
li.append(btn);
|
li.append(btn);
|
||||||
*/
|
|
||||||
parent.append(li);
|
parent.append(li);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -225,46 +205,47 @@ class NextcloudFilesPopupView extends rl.pluginPopupView {
|
||||||
this.tree.addEventListener('click', event => {
|
this.tree.addEventListener('click', event => {
|
||||||
let el = event.target;
|
let el = event.target;
|
||||||
if (el.matches('button')) {
|
if (el.matches('button')) {
|
||||||
let parent = el.parentNode;
|
let parent = el.parentNode,
|
||||||
|
item = parent.item;
|
||||||
if ('select' == el.name) {
|
if ('select' == el.name) {
|
||||||
this.select = this.files() ? [parent.item] : parent.item_name;
|
this.select = this.files() ? [item] : parent.item_name;
|
||||||
this.close();
|
this.close();
|
||||||
} else if ('share-internal' == el.name) {
|
} else if ('share-internal' == el.name) {
|
||||||
this.select = [{url:generateRemoteUrl(`/f/${parent.item.id}`)}];
|
this.select = [{url:generateRemoteUrl(`/f/${item.id}`)}];
|
||||||
this.close();
|
this.close();
|
||||||
} else if ('share-public' == el.name) {
|
} else if ('share-public' == el.name) {
|
||||||
/*
|
if (item.shared) {
|
||||||
if (3 == share-type) {
|
ncFetch(
|
||||||
GET generateUrl(`/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json&path=${encodeURIComponent(parent.item.name)}&reshares=true`);
|
shareUrl() + `?format=json&path=${encodeURIComponent(item.name)}&reshares=true`
|
||||||
|
)
|
||||||
|
.then(response => (response.status < 400) ? response.json() : Promise.reject(new Error({ response })))
|
||||||
|
.then(json => {
|
||||||
|
this.select = [{url:json.ocs.data[0].url}];
|
||||||
|
this.close();
|
||||||
|
// json.data[0].password
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
POST generateUrl(`/ocs/v2.php/apps/files_sharing/api/v1/shares`)
|
ncFetch(
|
||||||
> {"path":"/Nextcloud intro.mp4","shareType":3,"attributes":"[]"}
|
shareUrl(),
|
||||||
< {"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK"},
|
{
|
||||||
"data":{
|
method:'POST',
|
||||||
"id":"2",
|
headers: {
|
||||||
"share_type":3,
|
Accept: 'application/json',
|
||||||
"permissions":17,
|
'Content-Type': 'application/json'
|
||||||
"token":"7GK9mL9LCTseSgK",
|
},
|
||||||
"path":"\/Nextcloud intro.mp4",
|
body: JSON.stringify({
|
||||||
"item_type":"file",
|
path:item.name,
|
||||||
"mimetype":"video\/mp4",
|
shareType:3,
|
||||||
"storage":1,
|
attributes:"[]"
|
||||||
"item_source":20,
|
})
|
||||||
"file_source":20,
|
}
|
||||||
"file_parent":2,
|
)
|
||||||
"file_target":"\/Nextcloud intro.mp4",
|
.then(response => (response.status < 400) ? response.json() : Promise.reject(new Error({ response })))
|
||||||
"password":null,
|
.then(json => {
|
||||||
"url":"https:\/\/example.com\/index.php\/s\/7GK9mL9LCTseSgK",
|
this.select = [{url:json.ocs.data.url}];
|
||||||
"mail_send":1,
|
this.close();
|
||||||
"hide_download":0,
|
});
|
||||||
"attributes":null
|
|
||||||
}}}
|
|
||||||
GET /index.php/s/7GK9mL9LCTseSgK
|
|
||||||
PUT /ocs/v2.php/apps/files_sharing/api/v1/shares/2
|
|
||||||
> {"expireDate":"\"2022-11-29T23:00:00.000Z\""}
|
|
||||||
> {"password":"ABC09"}
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
} else if ('create' == el.name) {
|
} else if ('create' == el.name) {
|
||||||
let name = el.input.value.replace(/[|\\?*<":>+[]\/&\s]/g, '');
|
let name = el.input.value.replace(/[|\\?*<":>+[]\/&\s]/g, '');
|
||||||
if (name.length) {
|
if (name.length) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue