Bladeren bron

add user key support

Gildas 4 jaren geleden
bovenliggende
commit
de6d79de95

+ 4 - 0
_locales/de/messages.json

@@ -495,6 +495,10 @@
 		"message": "Confirm you allow SingleFile to send to the Woleet API a SHA256 hash of each page you are going to save. You can find more information about this feature in the help page or by clicking on the question mark next to the option.",
 		"description": "Popup text displayed wen enabling the option 'add proof of existence'"
 	},
+	"optionWoleetKey": {
+		"message": "access token",
+		"description": "Options page label: 'access token'"
+	},
 	"optionSaveToGDrive": {
 		"message": "In Google Drive speichern",
 		"description": "Options page label: 'upload to Google Drive'"

+ 4 - 0
_locales/en/messages.json

@@ -495,6 +495,10 @@
 		"message": "Confirm you allow SingleFile to send to the Woleet API a SHA256 hash of each page you are going to save. You can find more information about this feature in the help page or by clicking on the question mark next to the option.",
 		"description": "Popup text displayed wen enabling the option 'add proof of existence'"
 	},
+	"optionWoleetKey": {
+		"message": "access token",
+		"description": "Options page label: 'access token'"
+	},
 	"optionSaveToGDrive": {
 		"message": "upload to Google Drive",
 		"description": "Options page label: 'upload to Google Drive'"

+ 4 - 0
_locales/es/messages.json

@@ -495,6 +495,10 @@
 		"message": "Confirm you allow SingleFile to send to the Woleet API a SHA256 hash of each page you are going to save. You can find more information about this feature in the help page or by clicking on the question mark next to the option.",
 		"description": "Popup text displayed wen enabling the option 'add proof of existence'"
 	},
+	"optionWoleetKey": {
+		"message": "access token",
+		"description": "Options page label: 'access token'"
+	},
 	"optionSaveToGDrive": {
 		"message": "subir a Google Drive",
 		"description": "Options page label: 'upload to Google Drive'"

+ 4 - 0
_locales/fr/messages.json

@@ -495,6 +495,10 @@
 		"message": "Confirmez que vous autorisez SingleFile à envoyer à l'API de Woleet un hachage SHA256 de chaque page que vous allez enregistrer. Vous trouverez plus d'informations sur cette fonctionnalité dans la page d'aide ou en cliquant sur le point d'interrogation à côté de l'option.",
 		"description": "Popup text displayed wen enabling the option 'add proof of existence'"
 	},
+	"optionWoleetKey": {
+		"message": "jeton d'accès",
+		"description": "Options page label: 'access token'"
+	},
 	"optionSaveToGDrive": {
 		"message": "téléverser sur Google Drive",
 		"description": "Options page label: 'upload to Google Drive'"

+ 4 - 0
_locales/ja/messages.json

@@ -495,6 +495,10 @@
 		"message": "Confirm you allow SingleFile to send to the Woleet API a SHA256 hash of each page you are going to save. You can find more information about this feature in the help page or by clicking on the question mark next to the option.",
 		"description": "Popup text displayed wen enabling the option 'add proof of existence'"
 	},
+	"optionWoleetKey": {
+		"message": "access token",
+		"description": "Options page label: 'access token'"
+	},
 	"optionSaveToGDrive": {
 		"message": "Google Drive に保存",
 		"description": "Options page label: 'upload to Google Drive'"

+ 4 - 0
_locales/pl/messages.json

@@ -495,6 +495,10 @@
 		"message": "Potwierdź, że zezwalasz SingleFile na wysyłanie do interfejsu API Woleet skrótu SHA256 każdej strony, którą chcesz zapisać. Więcej informacji na temat tej funkcji można znaleźć na stronie pomocy lub klikając znak zapytania obok opcji.",
 		"description": "Popup text displayed wen enabling the option 'add proof of existence'"
 	},
+	"optionWoleetKey": {
+		"message": "token dostępu",
+		"description": "Options page label: 'access token'"
+	},
 	"optionSaveToGDrive": {
 		"message": "przesyłaj na Dysk Google",
 		"description": "Options page label: 'upload to Google Drive'"

+ 4 - 0
_locales/ru/messages.json

@@ -495,6 +495,10 @@
 		"message": "Подтвердите, что разрешаете SingleFile отправлять в Woleet API SHA256-хеш каждой сохраняемой вами страницы. Дополнительную информацию об этой функции можно найти на странице помощи или нажав на знак вопроса рядом с параметром.",
 		"description": "Popup text displayed wen enabling the option 'add proof of existence'"
 	},
+	"optionWoleetKey": {
+		"message": "токен доступа",
+		"description": "Options page label: 'access token'"
+	},
 	"optionSaveToGDrive": {
 		"message": "загрузить на Google Drive",
 		"description": "Options page label: 'upload to Google Drive'"

+ 4 - 0
_locales/uk/messages.json

@@ -495,6 +495,10 @@
 		"message": "Confirm you allow SingleFile to send to the Woleet API a SHA256 hash of each page you are going to save. You can find more information about this feature in the help page or by clicking on the question mark next to the option.",
 		"description": "Popup text displayed wen enabling the option 'add proof of existence'"
 	},
+	"optionWoleetKey": {
+		"message": "access token",
+		"description": "Options page label: 'access token'"
+	},
 	"optionSaveToGDrive": {
 		"message": "upload to Google Drive",
 		"description": "Options page label: 'upload to Google Drive'"

+ 4 - 0
_locales/zh_CN/messages.json

@@ -495,6 +495,10 @@
 		"message": "请确认您是否允许 SingleFile 将您要保存的每个页面的 SHA256 哈希值发送给 Woleet API 。您可以在帮助页面或者通过点击该选项旁的问号找到此功能的更多信息。",
 		"description": "Popup text displayed wen enabling the option 'add proof of existence'"
 	},
+	"optionWoleetKey": {
+		"message": "access token",
+		"description": "Options page label: 'access token'"
+	},
 	"optionSaveToGDrive": {
 		"message": "保存到 Google Drive",
 		"description": "Options page label: 'upload to Google Drive'"

+ 4 - 0
_locales/zh_TW/messages.json

@@ -495,6 +495,10 @@
 		"message": "請確認您是否允許 SingleFile 將您要保存的每個頁面的 SHA256 哈希值發送給 Woleet API 。您可以在幫助頁面或者通過點擊該選項旁的問號找到此功能的更多信息。",
 		"description": "Popup text displayed wen enabling the option 'add proof of existence'"
 	},
+	"optionWoleetKey": {
+		"message": "access token",
+		"description": "Options page label: 'access token'"
+	},
 	"optionSaveToGDrive": {
 		"message": "保存到 Google Drive",
 		"description": "Options page label: 'upload to Google Drive'"

+ 1 - 1
extension/core/bg/autosave.js

@@ -219,7 +219,7 @@ async function saveContent(message, tab) {
 					}
 				}
 				if (pageData.hash) {
-					await woleet.anchor(pageData.hash);
+					await woleet.anchor(pageData.hash, options.woleetKey);
 				}
 			}
 		} finally {

+ 2 - 1
extension/core/bg/config.js

@@ -111,7 +111,8 @@ const DEFAULT_CONFIG = {
 	insertMetaNoIndex: false,
 	insertMetaCSP: true,
 	passReferrerOnError: false,
-	insertSingleFileComment: true
+	insertSingleFileComment: true,
+	woleetKey: ""
 };
 
 let configStorage;

+ 1 - 1
extension/core/bg/downloads.js

@@ -75,7 +75,7 @@ async function onMessage(message, sender) {
 	if (message.method.endsWith(".end")) {
 		if (message.hash) {
 			try {
-				await woleet.anchor(message.hash);
+				await woleet.anchor(message.hash, message.woleetKey);
 			} catch (error) {
 				ui.onError(sender.tab.id, error.message + " (Woleet)");
 			}

+ 1 - 1
extension/core/common/download.js

@@ -86,7 +86,7 @@ async function downloadPage(pageData, options) {
 		}
 		browser.runtime.sendMessage({ method: "ui.processEnd" });
 	}
-	await browser.runtime.sendMessage({ method: "downloads.end", taskId: options.taskId, hash: pageData.hash });
+	await browser.runtime.sendMessage({ method: "downloads.end", taskId: options.taskId, hash: pageData.hash, woleetKey: options.woleetKey });
 }
 
 async function downloadPageForeground(pageData) {

+ 3 - 2
extension/lib/woleet/woleet.js

@@ -26,13 +26,14 @@ const apiKey = "";
 export {
 	anchor
 };
-async function anchor(hash) {
+async function anchor(hash, userKey) {
+	let bearer = userKey || apiKey;
 	const response = await fetch(urlService, {
 		method: "POST",
 		headers: {
 			"Accept": "application/json",
 			"Content-Type": "application/json",
-			"Authorization": "Bearer " + apiKey
+			"Authorization": "Bearer " + bearer
 		},
 		body: JSON.stringify({
 			"name": hash,

+ 7 - 0
extension/ui/bg/ui-options.js

@@ -38,6 +38,7 @@ const insertMetaCSPLabel = document.getElementById("insertMetaCSPLabel");
 const saveToClipboardLabel = document.getElementById("saveToClipboardLabel");
 const saveToFilesystemLabel = document.getElementById("saveToFilesystemLabel");
 const addProofLabel = document.getElementById("addProofLabel");
+const woleetKeyLabel = document.getElementById("woleetKeyLabel");
 const saveToGDriveLabel = document.getElementById("saveToGDriveLabel");
 const saveToGitHubLabel = document.getElementById("saveToGitHubLabel");
 const githubTokenLabel = document.getElementById("githubTokenLabel");
@@ -134,6 +135,7 @@ const saveRawPageInput = document.getElementById("saveRawPageInput");
 const insertMetaCSPInput = document.getElementById("insertMetaCSPInput");
 const saveToClipboardInput = document.getElementById("saveToClipboardInput");
 const addProofInput = document.getElementById("addProofInput");
+const woleetKeyInput = document.getElementById("woleetKeyInput");
 const saveToGDriveInput = document.getElementById("saveToGDriveInput");
 const saveToGitHubInput = document.getElementById("saveToGitHubInput");
 const githubTokenInput = document.getElementById("githubTokenInput");
@@ -415,6 +417,7 @@ addProofInput.addEventListener("click", async event => {
 		addProofInput.checked = false;
 		if (await confirm(browser.i18n.getMessage("optionsAddProofConfirm"), event.clientY - 100)) {
 			addProofInput.checked = true;
+			woleetKeyInput.disabled = false;
 		}
 		await update();
 	}
@@ -476,6 +479,7 @@ insertMetaCSPLabel.textContent = browser.i18n.getMessage("optionInsertMetaCSP");
 saveToClipboardLabel.textContent = browser.i18n.getMessage("optionSaveToClipboard");
 saveToFilesystemLabel.textContent = browser.i18n.getMessage("optionSaveToFilesystem");
 addProofLabel.textContent = browser.i18n.getMessage("optionAddProof");
+woleetKeyLabel.textContent = browser.i18n.getMessage("optionWoleetKey");
 saveToGDriveLabel.textContent = browser.i18n.getMessage("optionSaveToGDrive");
 saveToGitHubLabel.textContent = browser.i18n.getMessage("optionSaveToGitHub");
 githubTokenLabel.textContent = browser.i18n.getMessage("optionGitHubToken");
@@ -685,6 +689,8 @@ async function refresh(profileName) {
 	insertMetaCSPInput.checked = profileOptions.insertMetaCSP;
 	saveToClipboardInput.checked = profileOptions.saveToClipboard;
 	addProofInput.checked = profileOptions.addProof;
+	woleetKeyInput.value = profileOptions.woleetKey;
+	woleetKeyInput.disabled = !profileOptions.addProof;
 	saveToGDriveInput.checked = profileOptions.saveToGDrive;
 	saveToGitHubInput.checked = profileOptions.saveToGitHub;
 	githubTokenInput.value = profileOptions.githubToken;
@@ -779,6 +785,7 @@ async function update() {
 			insertMetaCSP: insertMetaCSPInput.checked,
 			saveToClipboard: saveToClipboardInput.checked,
 			addProof: addProofInput.checked,
+			woleetKey: woleetKeyInput.value,
 			saveToGDrive: saveToGDriveInput.checked,
 			saveToGitHub: saveToGitHubInput.checked,
 			githubToken: githubTokenInput.value,

+ 4 - 0
extension/ui/pages/help.html

@@ -545,6 +545,10 @@
 						</ul>
 						<p> More information <a href="https://doc.woleet.io" target="_blank">doc.woleet.io</a> </p>
 					</li>
+					<li data-options-label="woleetKeyLabel" hidden> <span class="option">Option: access token</span>
+						<p>Enter your personal access token on Woleet, see the <a href="https://www.woleet.io/"
+								target="_blank">documentation page</a> on Woleet for more information.</p>
+					</li>
 					<li data-options-label="backgroundSaveLabel"> <span class="option">Option: save pages in
 							background</span>
 						<p>Uncheck this option if you get invalid file names like

+ 4 - 0
extension/ui/pages/options.html

@@ -319,6 +319,10 @@
 				<label for="addProofInput" id="addProofLabel"></label>
 				<input type="checkbox" id="addProofInput">
 			</div>
+			<div class="option second-level vertical" hidden>
+				<label for="woleetKeyInput" id="woleetKeyLabel"></label>
+				<input type="text" id="woleetKeyInput">
+			</div>
 			<div class="option">
 				<label for="backgroundSaveInput" id="backgroundSaveLabel"></label>
 				<input type="checkbox" id="backgroundSaveInput">