Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…hunderbird 68.*
  • Loading branch information
guillaumev authored and thosmos committed Jan 27, 2020
1 parent 0a1135f commit 0b42a7d
Show file tree
Hide file tree
Showing 39 changed files with 594 additions and 1,926 deletions.
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
cd src; zip -r ../../nextcloud-filelink-$1.xpi .
Binary file removed screenshots/addon-about.png
Binary file not shown.
Binary file added screenshots/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed screenshots/configured.png
Binary file not shown.
Binary file removed screenshots/setup.png
Binary file not shown.
38 changes: 38 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"extensionName": {
"message": "Nextcloud for Filelink",
"description": "Name of the extension"
},
"extensionDescription": {
"message": "Nextcloud provider for Thunderbird Filelink",
"description": "Description of the extension"
},
"serviceName": {
"message": "Nextcloud",
"description": "Name of the service"
},
"serverURLLabel": {
"message": "WebDAV URL"
},
"serverURLDesc": {
"message": "Your Personal WebDAV file path can be found under Settings in the lower left of the Files screen."
},
"usernameLabel": {
"message": "Username"
},
"usernameDesc": {
"message": "Your NextCloud username"
},
"tokenLabel": {
"message": "App Token / Password"
},
"tokenDesc": {
"message": "An app token (preferrable) or password. Generate an app token via User -> Settings -> Security -> App Token. WARNING: this token is stored insecurely. NOTE: this may require the OAuth2 plugin on the server."
},
"pathLabel": {
"message": "Storage Path"
},
"pathDesc": {
"message": "The path where the files are stored in OwnCloud (it must already exist on the server)"
}
}
184 changes: 184 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/**
* @copyright Copyright (c) 2020, Thomas Spellman (thos37@gmail.com)
*
* @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/>.
*
*/

var uploads = new Map();

// browser.cloudFile.onAccountAdded.addListener(async (account) => {
// //console.log("Account Added", account.id)
// })

async function getAccountInfo(accountId) {
let accountInfo = await browser.storage.local.get([accountId]);
if (!accountInfo[accountId] || !("webdavUrl" in accountInfo[accountId])) {
throw new Error("No Accounts found.");
}
return accountInfo[accountId];
}

browser.cloudFile.onFileUpload.addListener(async (account, params) => {

let { id, name, data } = params;

name = "" + Date.now() + "_" + name;

console.log("onFileUpload", id, account, name);

let accountInfo = await getAccountInfo(account.id);

//console.log("accountInfo", accountInfo);

let uploadInfo = {
id,
name,
abortController: new AbortController(),
};

uploads.set(id, uploadInfo);

let {webdavUrl, username, token, path} = accountInfo;

const authHeader = "Basic " + btoa(username + ":" + token);

let url = webdavUrl + path + encodeURIComponent(name);

let headers = {
"Content-Type": "application/octet-stream",
Authorization: authHeader
};
let fetchInfo = {
method: "PUT",
headers,
body: data,
signal: uploadInfo.abortController.signal,
};

//console.log("uploading to ", url, fetchInfo);

let response = await fetch(url, fetchInfo);

//console.log("file upload response", response);

delete uploadInfo.abortController;
if (response.status > 299) {
throw new Error("response was not ok: server status code: " + response.status + ", response message: " + response.statusText);
}

const serverUrl = webdavUrl.substr(0, webdavUrl.indexOf("remote.php"));
const shareUrl = serverUrl + "ocs/v1.php/apps/files_sharing/api/v1/shares?format=json";

uploadInfo.abortController = new AbortController();
uploads.set(id, uploadInfo);

headers = {
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
Authorization: authHeader,
"OCS-APIRequest": true
};

fetchInfo = {
method: "POST",
headers,
body: "shareType=3&path=" + encodeURIComponent(path + name),
signal: uploadInfo.abortController.signal,
};

console.log("requesting public link", shareUrl, fetchInfo);

response = await fetch(shareUrl, fetchInfo);

//console.log("public link response", response);

if(response.ok)
{
let respJson = await response.json();

uploadInfo.shareID = respJson.ocs.data.id;
uploads.set(id, uploadInfo);

return {url: respJson.ocs.data.url + "/download"};
}
else
return {aborted: true}

});

browser.cloudFile.onFileUploadAbort.addListener((account, id) => {
//console.log("aborting upload", id);
let uploadInfo = uploads.get(id);
if (uploadInfo && uploadInfo.abortController) {
uploadInfo.abortController.abort();
}
});

browser.cloudFile.onFileDeleted.addListener(async (account, id) => {
//console.log("delete upload", id);
let uploadInfo = uploads.get(id);
if (!uploadInfo) {
return;
}

// FIXME how do we get a confirmation popup in TB MailExtensions?
// let wishDelete = confirm("Do you wish to delete the file on the server?");
// if(!wishDelete){
// return;
// }

let accountInfo = await getAccountInfo(account.id);

let {shareID} = uploadInfo;
let {webdavUrl, username, token} = accountInfo;

const authHeader = "Basic " + btoa(username + ":" + token);

const serverUrl = webdavUrl.substr(0, webdavUrl.indexOf("remote.php"));
const shareUrl = serverUrl + "ocs/v1.php/apps/files_sharing/api/v1/shares/" + shareID;

let headers = {
Authorization: authHeader,
"OCS-APIRequest": true
};

let fetchInfo = {
headers,
method: "DELETE",
};

//console.log("sending delete", url, fetchInfo);

let response = await fetch(shareUrl, fetchInfo);

//console.log("delete response", response);

uploads.delete(id);

if (response.status > 299) {
throw new Error("response was not ok: server status code: " + response.status + ", response message: " + response.statusText);
}

});

browser.cloudFile.getAllAccounts().then(async (accounts) => {
let allAccountsInfo = await browser.storage.local.get();
for (let account of accounts) {
await browser.cloudFile.updateAccount(account.id, {
configured: account.id in allAccountsInfo,
});
}
});
10 changes: 0 additions & 10 deletions src/chrome.manifest

This file was deleted.

117 changes: 0 additions & 117 deletions src/chrome/content/about.xul

This file was deleted.

Binary file removed src/chrome/content/aboutLogo.png
Binary file not shown.
Binary file removed src/chrome/content/logo.png
Binary file not shown.
Loading

0 comments on commit 0b42a7d

Please sign in to comment.