Compare commits

..
4 Commits
Author SHA1 Message Date
fyears 94c7a4a874 0.3.2 2022-03-05 22:33:45 +08:00
fyears b573b2859c add fallback for dropbox 2022-03-05 22:32:58 +08:00
fyears e2c4d158b1 fix format 2022-03-05 22:31:01 +08:00
fyears 55890611e2 fix s3 pagnation 2022-03-05 12:55:33 +08:00
6 changed files with 124 additions and 18 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"id": "remotely-save", "id": "remotely-save",
"name": "Remotely Save", "name": "Remotely Save",
"version": "0.3.1", "version": "0.3.2",
"minAppVersion": "0.12.15", "minAppVersion": "0.12.15",
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.", "description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
"author": "fyears", "author": "fyears",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "remotely-save", "name": "remotely-save",
"version": "0.3.1", "version": "0.3.2",
"description": "This is yet another sync plugin for Obsidian app.", "description": "This is yet another sync plugin for Obsidian app.",
"scripts": { "scripts": {
"dev2": "node esbuild.config.mjs", "dev2": "node esbuild.config.mjs",
+9 -2
View File
@@ -156,13 +156,20 @@ const fixLastModifiedTimeInplace = (allFilesFolders: RemoteItem[]) => {
// see https://dropbox.tech/developers/pkce--what-and-why- // see https://dropbox.tech/developers/pkce--what-and-why-
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
export const getAuthUrlAndVerifier = async (appKey: string) => { export const getAuthUrlAndVerifier = async (
appKey: string,
needManualPatse: boolean = false
) => {
const auth = new DropboxAuth({ const auth = new DropboxAuth({
clientId: appKey, clientId: appKey,
}); });
const callback = needManualPatse
? undefined
: `obsidian://${COMMAND_CALLBACK_DROPBOX}`;
const authUrl = ( const authUrl = (
await auth.getAuthenticationUrl( await auth.getAuthenticationUrl(
`obsidian://${COMMAND_CALLBACK_DROPBOX}`, callback,
undefined, undefined,
"code", "code",
"offline", "offline",
+2 -2
View File
@@ -190,7 +190,6 @@ export const listFromRemote = async (
const contents = [] as _Object[]; const contents = [] as _Object[];
let isTruncated = true; let isTruncated = true;
let continuationToken = "";
do { do {
const rsp = await s3Client.send(new ListObjectsV2Command(confCmd)); const rsp = await s3Client.send(new ListObjectsV2Command(confCmd));
@@ -206,7 +205,8 @@ export const listFromRemote = async (
confCmd.ContinuationToken = rsp.NextContinuationToken; confCmd.ContinuationToken = rsp.NextContinuationToken;
if ( if (
isTruncated && isTruncated &&
(continuationToken === undefined || continuationToken === "") (confCmd.ContinuationToken === undefined ||
confCmd.ContinuationToken === "")
) { ) {
throw Error("isTruncated is true but no continuationToken provided"); throw Error("isTruncated is true but no continuationToken provided");
} }
+101 -2
View File
@@ -1,4 +1,11 @@
import { App, Modal, Notice, PluginSettingTab, Setting } from "obsidian"; import {
App,
Modal,
Notice,
PluginSettingTab,
Setting,
Platform,
} from "obsidian";
import type { SUPPORTED_SERVICES_TYPE, WebdavAuthType } from "./baseTypes"; import type { SUPPORTED_SERVICES_TYPE, WebdavAuthType } from "./baseTypes";
import { exportVaultSyncPlansToFiles } from "./debugMode"; import { exportVaultSyncPlansToFiles } from "./debugMode";
import { exportQrCodeUri } from "./importExport"; import { exportQrCodeUri } from "./importExport";
@@ -110,9 +117,36 @@ class DropboxAuthModal extends Modal {
async onOpen() { async onOpen() {
let { contentEl } = this; let { contentEl } = this;
let needManualPatse = false;
const userAgent = window.navigator.userAgent.toLocaleLowerCase() || "";
// some users report that,
// the Linux would open another instance Obsidian if jumping back,
// so fallback to manual paste on Linux
if (
Platform.isDesktopApp &&
!Platform.isMacOS &&
(/linux/.test(userAgent) ||
/ubuntu/.test(userAgent) ||
/debian/.test(userAgent) ||
/fedora/.test(userAgent) ||
/centos/.test(userAgent))
) {
needManualPatse = true;
}
const { authUrl, verifier } = await getAuthUrlAndVerifierDropbox( const { authUrl, verifier } = await getAuthUrlAndVerifierDropbox(
this.plugin.settings.dropbox.clientID this.plugin.settings.dropbox.clientID,
needManualPatse
); );
if (needManualPatse) {
contentEl.createEl("p", {
text: "Step 1: Visit the address in a browser, and follow the steps.",
});
contentEl.createEl("p", {
text: 'Step 2: In the end of the web flow, you obtain a long code. Paste it here then click "Submit".',
});
} else {
this.plugin.oauth2Info.verifier = verifier; this.plugin.oauth2Info.verifier = verifier;
contentEl.createEl("p", { contentEl.createEl("p", {
@@ -121,6 +155,7 @@ class DropboxAuthModal extends Modal {
contentEl.createEl("p", { contentEl.createEl("p", {
text: "Finally you should be redirected to Obsidian.", text: "Finally you should be redirected to Obsidian.",
}); });
}
const div2 = contentEl.createDiv(); const div2 = contentEl.createDiv();
div2.createEl( div2.createEl(
@@ -140,6 +175,70 @@ class DropboxAuthModal extends Modal {
href: authUrl, href: authUrl,
text: authUrl, text: authUrl,
}); });
if (needManualPatse) {
let authCode = "";
new Setting(contentEl)
.setName("Auth Code from web page")
.setDesc('You need to click "Confirm".')
.addText((text) =>
text
.setPlaceholder("")
.setValue("")
.onChange((val) => {
authCode = val.trim();
})
)
.addButton(async (button) => {
button.setButtonText("Confirm");
button.onClick(async () => {
new Notice("Trying to connect to Dropbox");
try {
const authRes = await sendAuthReqDropbox(
this.plugin.settings.dropbox.clientID,
verifier,
authCode
);
const self = this;
setConfigBySuccessfullAuthInplace(
this.plugin.settings.dropbox,
authRes,
() => self.plugin.saveSettings()
);
const client = new RemoteClient(
"dropbox",
undefined,
undefined,
this.plugin.settings.dropbox,
undefined,
this.app.vault.getName(),
() => self.plugin.saveSettings()
);
const username = await client.getUser();
this.plugin.settings.dropbox.username = username;
await this.plugin.saveSettings();
new Notice(
`Good! We've connected to Dropbox as user ${username}!`
);
this.authDiv.toggleClass(
"dropbox-auth-button-hide",
this.plugin.settings.dropbox.username !== ""
);
this.revokeAuthDiv.toggleClass(
"dropbox-revoke-auth-button-hide",
this.plugin.settings.dropbox.username === ""
);
this.revokeAuthSetting.setDesc(
`You've connected as user ${this.plugin.settings.dropbox.username}. If you want to disconnect, click this button.`
);
this.close();
} catch (err) {
console.error(err);
new Notice("Something goes wrong while connecting to Dropbox.");
}
});
});
}
} }
onClose() { onClose() {
+1 -1
View File
@@ -1,3 +1,3 @@
{ {
"0.3.1": "0.12.15" "0.3.2": "0.12.15"
} }