usable google drive
Some checks failed
BuildCI / build (16.x) (push) Failing after 6m13s

This commit is contained in:
fyears 2024-06-02 23:36:45 +08:00
parent f6ba4631e1
commit 6bced35f42
23 changed files with 444 additions and 43 deletions

View File

@ -22,6 +22,7 @@ This is yet another unofficial sync plugin for Obsidian. If you like it or find
- OneDrive for personal
- Webdav
- Webdis
- Google Drive (PRO feature)
- [Here](./docs/services_connectable_or_not.md) shows more connectable (or not-connectable) services in details.
- **Obsidian Mobile supported.** Vaults can be synced across mobile and desktop devices with the cloud service as the "broker".
- **[End-to-end encryption](./docs/encryption/README.md) supported.** Files would be encrypted using openssl format before being sent to the cloud **if** user specify a password.
@ -119,6 +120,10 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a
- Mostly experimental.
- You have to setup and protect your web server by yourself.
### Google Drive (PRO feature)
PRO (paid) feature "sync with Google Drive" allows users to to sync with Google Drive. Tutorials and limitations are documented [here](./docs/remote_services/googledrive/README.md).
## Scheduled Auto Sync
- You can configure auto syncing every N minutes in settings.
@ -133,7 +138,7 @@ In the latest version, you can change the settings to allow syncing `_` files or
## PRO Features
See [PRO](./pro/README.md) for more details.
See [PRO](./docs/pro/README.md) for more details.
## How To Debug

53
docs/pro/README.md Normal file
View File

@ -0,0 +1,53 @@
# PRO Features
From version 0.5.x, Remotely Save introduces PRO (paid) features. Users need to subscribe to (pay) them to use them.
**If you are using basic features only, you don't need an online account, and you don't need to pay for the plugin.**
# Links
* Remotely Save official website: <https://remotelysave.com>
* Sign up / Sign in: <https://remotelysave.com/user/signupin>
* User profile: <https://remotelysave.com/user/profile>
# Disclaimer
It's different from, and NOT affiliated with Obsidian account.
# Steps
## Steps of signing up and signing in
1. Go to the website, sign up and sign in. You can directly visit <https://remotelysave.com/user/signupin> or click the link in Remotely Save plugin setting page.
![pro setting](./pro_setting.png)
2. Use an email and your password as usual. Don't need to be GMail account.
## Steps of connecting
You need to connect your plugin to your online account. In Obsidian, in your Remotely Save plugin setting, you can click the button "Connect" to start the flow.
1. You will see a special address on website. Click it and visit the website
2. Click "allow" on the website.
3. In the end of the auth flow on the website, you will be shown up a code, please copy it...
4. And paste the code back to the plugin modal inside Obsidian, and confirm.
![connect flow](./connect_flow.png)
## Steps of subscribing to some features.
1. Firstly please visit your [profile page](https://remotelysave.com/user/profile) online.
2. You can subscribe to some features. Prices vary.
![PRO features online](./pro_features_enabled_on_website.png)
3. Go back to your Remotely Save plugin inside Obsidian, click "Check again" button in PRO settings. So that the plugin knows some features are enabled.
![check again PRO features](./check_pro_features_in_settings.png)
4. Sync and enjoy your PRO features!
## Why so complicated?
Because we doesn't have payment method inside the plugin, so we have to:
* build a website,
* require users having online accounts
* and connect the plugin to the online account.
Moreover, an online account allows flexibe management of subscriptions.

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8c73da29a621d225387640b76ec0dcfb56b3ffad151dab374d3b7cc76067a1a0
size 94377

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:116c2a8ec1a277a3985f4056b390574fc57145ec5635d44accf2a7445666264a
size 626668

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4c45c08e6fc487341032aac511c332e3f9978a44e9b93377a73648b56b684b62
size 155427

3
docs/pro/pro_setting.png Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:08d128125dba033f5dd18a6ea8d942b284ddca6c5c3b0362c47dcb4a7153a8f9
size 395800

View File

@ -0,0 +1,59 @@
# Google Drive (PRO)
# Intro
* It's a PRO feature of Remotely Save plugin.
* **This plugin is NOT an official Google product, and just uses Google Drive's public api.**
# Steps
## Steps of Remotely Save subscription
1. Please sign up and sign in an online account, connect your plugin to your online account firstly. See [the PRO tutorial](../../pro/README.md) firstly.
2. Subscribe to "sync with Google Drive" feature online.
3. Go back to your Remotely Save plugin inside Obsidian, click "Check again" button in PRO settings. So that the plugin knows some features are enabled. In this case, sync with Google Drive should be detected.
## Steps of Connecting to your Google Drive
After you enabled the PRO feature in your Remotely Save plugin, you can connect to your Google Drive account now.
1. In Remotely Save settings, change your sync service to Google Drive.
![change remote to google drive](./change_remote_to_google_drive.png)
2. Click Auth, visit the link, go to Remotely Save website to start.
![visit start link](./google_drive_auth_link.png)
3. On the website, click the link to go to Google Drive auth page.
4. Follow the instruction on Google website, and allow (continue) Remotely Save to connect.
![allow Remotely Save in Google website](./google_drive_auth_allow.png)
5. You will be redirected to Remotely Save website, and you will get a code. Copy it...
![redirected back and get the code](./google_drive_auth_code_show.png)
6. ... And paste the code back to the plugin inside Obsidian. Click submit.
![submit the code in setting](./google_drive_code_submit.png)
7. A notice will tell you that you've connected or not.
8. Sync! The plugin will create a vault folder in the root of your Google Drive and upload notes into that folder.
9. **Read the caveats below.**
# Why so complicated?
Because Google Drive's api doesn't fit into the special envorinment of Obsidian plugin. So we need a website.
# The credential
The website does **NOT** store or save the credential (the code you obtian in the end of the flow). The website is just a "bridge" to help you obtain that code, and just manage your subscription to PRO features.
But please be aware that the code is saved locally in your Obsidian. It works like a special password. So that the plugin can upload or download or modify the files for you.
# The caveats
* As of June 2024, this feature is in beta stage. **Back up your vault before using this feature.**
* The plugin can **only** sees, reads or writes the files and folders created by itself!
It means that, you CANNOT manually create the vault folder in your Google Drive account. And if you manually upload any files using Google's official website, the plugin does **NOT** see them. All operations must go through Obsidian and uploaded by the plugin.
You can, however, view, and download the files on Google Drive [official web page](https://drive.google.com/drive/u/0/my-drive).
Precisely speaking, the plugin applies for the `drive.file` scope recommended by Google. See [the doc](https://developers.google.com/drive/api/guides/api-specific-auth#benefits) by Google for the scope's benefits. Basically the plugin will never (is unable to) mess up your other files or folders.
Moreover, this scope is "not-sensitive", so that the plugin doesn't need to go through Google's complicated verification process while applying for it.
* Google Drive, unlike other cloud storage, allows files of same name co-existing in the same folder! (hmmmmm...) It may or may not make the plugin stop working. Users might need to remove the duplicated file manually on Google's official website.

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:eaa9aa8ba6b066dfefdce08a8d1da1d97089f5c2de0ba4c0c026d6df9eb9ece8
size 99896

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6683a63718053603ae7dde44063a3807ba0def7e935da0b40fcc8e181afd24ae
size 342848

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:310bd4c7d5fe19521ec7184b2eee749f0eecf00397f2b8e68480c23b4fd7c943
size 153504

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:dcebb1f73829670883071447a8eee46c972b26fe8735c7422949cb6fe927b8ab
size 179369

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7e5a85c28f5614e4de75eacc021c2876d36596bcb77f0744a6edcff7777b9530
size 155004

View File

@ -4,9 +4,9 @@
Remotely Save has some "pro features", which users have to pay for using them.
## Sign Up / Sign In
## Sign Up / Sign In And Connect
Please go to <https://remotelysave.com> to sign up and sign in an account firstly.
See the tutorial about your PRO account [here](../docs/pro/README.md).
## Smart Conflict
@ -14,6 +14,10 @@ Basic (free) version can detect conflicts, but users have to choose to keep newe
PRO (paid) feature "Smart Conflict" gives users one more option: merge small markdown files, or duplicate large markdown files or non-markdown files.
## Sync With Google Drive
PRO (paid) feature "sync with Google Drive" allows users to to sync with Google Drive. Tutorials and limitations are documented [here](../docs/remote_services/googledrive/README.md).
## License
The codes or files or subfolders inside the current folder (`pro` in the repo), are released under "source available" license: "PolyForm Strict License 1.0.0".

View File

@ -246,13 +246,7 @@ export const checkProRunnableAndFixInplace = async (
pluginVersion: string,
saveUpdatedConfigFunc: () => Promise<any> | undefined
): Promise<true> => {
// if no pro features are used, we are good to go, no checking
if (
featuresToCheck.contains("feature-smart_conflict") &&
config.conflictAction !== "smart_conflict"
) {
return true;
}
console.debug(`checkProRunnableAndFixInplace`);
// many checks if status is valid
@ -280,6 +274,8 @@ export const checkProRunnableAndFixInplace = async (
}
}
const errorMsgs = [];
// check for the features
if (featuresToCheck.contains("feature-smart_conflict")) {
if (config.conflictAction === "smart_conflict") {
@ -288,15 +284,45 @@ export const checkProRunnableAndFixInplace = async (
(x) => x.featureName === "feature-smart_conflict"
).length === 1
) {
return true;
// good to go
} else {
throw Error(
errorMsgs.push(
`You're trying to use "smart conflict" PRO feature but you haven't subscribe to it.`
);
}
} else {
return true;
// good to go
}
}
if (featuresToCheck.contains("feature-google_drive")) {
console.debug(
`checking "feature-google_drive", serviceType=${config.serviceType}`
);
console.debug(
`enabledProFeatures=${JSON.stringify(config.pro.enabledProFeatures)}`
);
if (config.serviceType === "googledrive") {
if (
config.pro.enabledProFeatures.filter(
(x) => x.featureName === "feature-google_drive"
).length === 1
) {
// good to go
} else {
errorMsgs.push(
`You're trying to use "sync with Google Drive" PRO feature but you haven't subscribe to it.`
);
}
} else {
// good to go
}
}
if (errorMsgs.length !== 0) {
throw Error(errorMsgs.join("\n\n"));
}
return true;
};

View File

@ -213,7 +213,7 @@ export class FakeFsGoogleDrive extends FakeFs {
});
const k1: { files: File[] } = await k.json();
console.debug(k1);
// console.debug(k1);
if (k1.files.length > 0) {
// yeah we find it
this.baseDirID = k1.files[0].id!;
@ -308,11 +308,11 @@ export class FakeFsGoogleDrive extends FakeFs {
id: f.id,
folderPath: f.keyRaw,
};
console.debug(
`looping result of _walkFolder(${id},${folderPath}), adding child=${JSON.stringify(
child
)}`
);
// console.debug(
// `looping result of _walkFolder(${id},${folderPath}), adding child=${JSON.stringify(
// child
// )}`
// );
children.push(child);
}
}
@ -322,16 +322,16 @@ export class FakeFsGoogleDrive extends FakeFs {
parents = children;
}
console.debug(`in the end of walk:`);
console.debug(allFiles);
console.debug(this.keyToGDEntity);
// console.debug(`in the end of walk:`);
// console.debug(allFiles);
// console.debug(this.keyToGDEntity);
return allFiles;
}
async _walkFolder(parentID: string, parentFolderPath: string) {
console.debug(
`input of single level: parentID=${parentID}, parentFolderPath=${parentFolderPath}`
);
// console.debug(
// `input of single level: parentID=${parentID}, parentFolderPath=${parentFolderPath}`
// );
const filesOneLevel: GDEntity[] = [];
let nextPageToken: string | undefined = undefined;
if (parentID === undefined || parentID === "" || parentID === "root") {
@ -359,7 +359,7 @@ export class FakeFsGoogleDrive extends FakeFs {
}
const k1 = await k.json();
console.debug(k1);
// console.debug(k1);
for (const file of k1.files as File[]) {
const entity = fromFileToGDEntity(file, parentID, parentFolderPath);
this.keyToGDEntity[entity.keyRaw] = entity; // build cache

View File

@ -7,8 +7,14 @@
"protocol_pro_connect_fail": "Something went wrong from response from Remotely Save official website. Maybe the network connection is not good. Maybe you rejected the auth?",
"protocol_pro_connect_succ_revoke": "You've connected as user {{email}}. If you want to disconnect, click this button.",
"modal_googledriveauth_tutorial": "<p>Please firstly go to the address, then go on the auth flow. In the end, you will see a code, please paste that code here and submit.</p>",
"modal_googledriveauth_copybutton": "Click to copy the auth url",
"modal_googledriveauth_copynotice": "The auth url is copied to the clipboard!",
"modal_googledrivce_maualinput": "The Code from the website",
"modal_googledrivce_maualinput_desc": "Please input the code here from the end of auth flow, and press confirm.",
"modal_googledrive_maualinput_notice": "We are trying to connect to Google and update the credentials...",
"modal_googledrive_maualinput_succ_notice": "Great! The credentials are updated!",
"modal_googledrive_maualinput_fail_notice": "Oops! Failed to update the credentials. Please try again later.",
"modal_googledriverevokeauth_step1": "Step 1: Go to the following address, you can remove the connection there.",
"modal_googledriverevokeauth_step2": "Step 2: Click the button below, to clean the locally-saved login credentials.",
"modal_googledriverevokeauth_clean": "Clean Locally-Saved Login Credentials",
@ -30,10 +36,14 @@
"modal_proauth_maualinput_notice": "Trying to connect, wait...",
"modal_proauth_maualinput_conn_fail": "Failed to connect",
"settings_googledrive": "Google Drive (PRO)",
"settings_chooseservice_googledrive": "Google Drive (PRO)",
"settings_googledrive_disclaimer1": "Disclaimer: This app is NOT an official Google product.",
"settings_googledrive": "Google Drive (PRO) (beta)",
"settings_chooseservice_googledrive": "Google Drive (PRO) (beta)",
"settings_googledrive_disclaimer1": "Disclaimer: This app is NOT an official Google product. The app just uses Google Drive's public api.",
"settings_googledrive_disclaimer2": "Disclaimer: The information is stored locally. Other malicious/harmful/faulty plugins could read the info. If you see any unintentional access to your Google Drive, please immediately disconnect this app on https://myaccount.google.com/permissions .",
"settings_googledrive_pro_desc": "<p><strong>!!It's a PRO feature of Remotely Save! You need a Remotely Save online account for this feature!!</strong>(<a href=\"#settings-pro\">scroll down</a> for more info about PRO account.)</p>",
"settings_googledrive_notshowuphint": "Google Drive Settings Not Available",
"settings_googledrive_notshowuphint_desc": "Google Drive settings are not available, because you haven't subscribed to the PRO feature in your Remotely Save account.",
"settings_googledrive_notshowuphint_view_pro": "View PRO Settings",
"settings_googledrive_folder": "We will create and sync inside the folder {{remoteBaseDir}} on your Google Drive. DO NOT create this folder by yourself manually.",
"settings_googledrive_revoke": "Revoke Auth",
"settings_googledrive_revoke_desc": "You've connected. If you want to disconnect, click this button.",

View File

@ -7,6 +7,22 @@
"protocol_pro_connect_fail": "Remotely Save 官网返回错误。可能是网络连接不稳定。也可能是您拒绝了授权?",
"protocol_pro_connect_succ_revoke": "您已连接上账号 {{email}}。如果要取消连接,请点击此按钮。",
"modal_googledriveauth_tutorial": "<p>请访问此网址,然后会进入授权流程。最后,您会看到一个码,请复制粘贴到这里然后提交。</p>",
"modal_googledriveauth_copybutton": "点击以复制网址",
"modal_googledriveauth_copynotice": "网址已复制!",
"modal_googledrivce_maualinput": "网站上的码",
"modal_googledrivce_maualinput_desc": "请粘贴授权流程最后的那个码,然后点击确认。",
"modal_googledrive_maualinput_notice": "正在尝试连接 Google 并更新授权信息......",
"modal_googledrive_maualinput_succ_notice": "很好!授权信息已更新!",
"modal_googledrive_maualinput_fail_notice": "更新授权信息失败。请稍后重试。",
"modal_googledriverevokeauth_step1": "第 1 步:访问以下网址,可以删除连接。",
"modal_googledriverevokeauth_step2": "第 2 步:点击以下按钮,从而清理本地的登录信息。",
"modal_googledriverevokeauth_clean": "清理本地登录信息",
"modal_googledriverevokeauth_clean_desc": "您需要点击此按钮。",
"modal_googledriverevokeauth_clean_button": "清理",
"modal_googledriverevokeauth_clean_notice": "已清理!",
"modal_googledriverevokeauth_clean_fail": "清理授权时候发生了错误。",
"modal_prorevokeauth": "点击这里和按照步骤取消授权。",
"modal_prorevokeauth_clean": "清理",
"modal_prorevokeauth_clean_desc": "清理本地授权记录",
@ -20,6 +36,26 @@
"modal_proauth_maualinput_notice": "正在连接,请稍候......",
"modal_proauth_maualinput_conn_fail": "连接失败",
"settings_googledrive": "Google Drive (PRO) (beta)",
"settings_chooseservice_googledrive": "Google Drive (PRO) (beta)",
"settings_googledrive_disclaimer1": "声明:本插件不是 Google 的官方产品。只是用到了它的公开 API。",
"settings_googledrive_disclaimer2": "声明:您所输入的信息存储于本地。其它有害的或者出错的插件,是有可能读取到这些信息的。如果您发现任何不符合预期的 Google Drive 访问,请立刻在以下网站操作断开连接: https://myaccount.google.com/permissions 。",
"settings_googledrive_pro_desc": "<p><strong>!!这是 PRO付费功能! 您需要在线账号来使用此功能!!</strong><a href=\"#settings-pro\">向下滑</a>可以看到 PRO 账号的更多信息。)</p>",
"settings_googledrive_notshowuphint": "Google Drive 设置不可用",
"settings_googledrive_notshowuphint_desc": "Google Drive 设置不可用,因为您没有在 Remotely Save 账号里开启这个 PRO 功能。",
"settings_googledrive_notshowuphint_view_pro": "查看 PRO 相关设置",
"settings_googledrive_folder": "我们会在 Google Drive 创建此文件夹并同步内容进去: {{remoteBaseDir}} 。请不要手动在网站上创建。",
"settings_googledrive_revoke": "撤回鉴权",
"settings_googledrive_revoke_desc": "您现在已连接。如果想取消连接,请点击此按钮。",
"settings_googledrive_revoke_button": "撤回鉴权",
"settings_googledrive_auth": "鉴权",
"settings_googledrive_auth_desc": "鉴权.",
"settings_googledrive_auth_button": "鉴权",
"settings_googledrive_connect_succ": "很好!我们可连接上 Google Drive",
"settings_googledrive_connect_fail": "我们未能连接上 Google Drive。",
"settings_export_googledrive_button": "导出 Google Drive 部分",
"settings_pro": "账号PRO 付费功能)",
"settings_pro_tutorial": "<p>使用 Remotely Save 的<stong>基本</strong>功能是<strong>免费的</strong>,而且<strong>不</strong>需要注册对应账号。</p><p>但是,您<strong>需要</strong>注册账号和对<strong>PRO</strong>功能<strong>付费</strong>使用,如智能处理冲突功能。</p><p>第一步:点击按钮从而注册和登录网站:<a href=\"https://remotelysave.com\">https://remotelysave.com</a>。注意:这和 Obsidian 官方账号无关,是不同的账号。</p><p>第二部:点击“连接”按钮,从而连接本设备和在线账号。",
"settings_pro_features": "功能",

View File

@ -7,6 +7,22 @@
"protocol_pro_connect_fail": "Remotely Save 官網返回錯誤。可能是網路連線不穩定。也可能是您拒絕了授權?",
"protocol_pro_connect_succ_revoke": "您已連線上賬號 {{email}}。如果要取消連線,請點選此按鈕。",
"modal_googledriveauth_tutorial": "<p>請訪問此網址,然後會進入授權流程。最後,您會看到一個碼,請複製貼上到這裡然後提交。</p>",
"modal_googledriveauth_copybutton": "點選以複製網址",
"modal_googledriveauth_copynotice": "網址已複製!",
"modal_googledrivce_maualinput": "網站上的碼",
"modal_googledrivce_maualinput_desc": "請貼上授權流程最後的那個碼,然後點選確認。",
"modal_googledrive_maualinput_notice": "正在嘗試連線 Google 並更新授權資訊......",
"modal_googledrive_maualinput_succ_notice": "很好!授權資訊已更新!",
"modal_googledrive_maualinput_fail_notice": "更新授權資訊失敗。請稍後重試。",
"modal_googledriverevokeauth_step1": "第 1 步:訪問以下網址,可以刪除連線。",
"modal_googledriverevokeauth_step2": "第 2 步:點選以下按鈕,從而清理本地的登入資訊。",
"modal_googledriverevokeauth_clean": "清理本地登入資訊",
"modal_googledriverevokeauth_clean_desc": "您需要點選此按鈕。",
"modal_googledriverevokeauth_clean_button": "清理",
"modal_googledriverevokeauth_clean_notice": "已清理!",
"modal_googledriverevokeauth_clean_fail": "清理授權時候發生了錯誤。",
"modal_prorevokeauth": "點選這裡和按照步驟取消授權。",
"modal_prorevokeauth_clean": "清理",
"modal_prorevokeauth_clean_desc": "清理本地授權記錄",
@ -20,6 +36,26 @@
"modal_proauth_maualinput_notice": "正在連線,請稍候......",
"modal_proauth_maualinput_conn_fail": "連線失敗",
"settings_googledrive": "Google Drive (PRO) (beta)",
"settings_chooseservice_googledrive": "Google Drive (PRO) (beta)",
"settings_googledrive_disclaimer1": "宣告:本外掛不是 Google 的官方產品。只是用到了它的公開 API。",
"settings_googledrive_disclaimer2": "宣告:您所輸入的資訊儲存於本地。其它有害的或者出錯的外掛,是有可能讀取到這些資訊的。如果您發現任何不符合預期的 Google Drive 訪問,請立刻在以下網站操作斷開連線: https://myaccount.google.com/permissions 。",
"settings_googledrive_pro_desc": "<p><strong>!!這是 PRO付費功能! 您需要線上賬號來使用此功能!!</strong><a href=\"#settings-pro\">向下滑</a>可以看到 PRO 賬號的更多資訊。)</p>",
"settings_googledrive_notshowuphint": "Google Drive 設定不可用",
"settings_googledrive_notshowuphint_desc": "Google Drive 設定不可用,因為您沒有在 Remotely Save 賬號裡開啟這個 PRO 功能。",
"settings_googledrive_notshowuphint_view_pro": "檢視 PRO 相關設定",
"settings_googledrive_folder": "我們會在 Google Drive 建立此資料夾並同步內容進去: {{remoteBaseDir}} 。請不要手動在網站上建立。",
"settings_googledrive_revoke": "撤回鑑權",
"settings_googledrive_revoke_desc": "您現在已連線。如果想取消連線,請點選此按鈕。",
"settings_googledrive_revoke_button": "撤回鑑權",
"settings_googledrive_auth": "鑑權",
"settings_googledrive_auth_desc": "鑑權.",
"settings_googledrive_auth_button": "鑑權",
"settings_googledrive_connect_succ": "很好!我們可連線上 Google Drive",
"settings_googledrive_connect_fail": "我們未能連線上 Google Drive。",
"settings_export_googledrive_button": "匯出 Google Drive 部分",
"settings_pro": "賬號PRO 付費功能)",
"settings_pro_tutorial": "<p>使用 Remotely Save 的<stong>基本</strong>功能是<strong>免費的</strong>,而且<strong>不</strong>需要註冊對應賬號。</p><p>但是,您<strong>需要</strong>註冊賬號和對<strong>PRO</strong>功能<strong>付費</strong>使用,如智慧處理衝突功能。</p><p>第一步:點選按鈕從而註冊和登入網站:<a href=\"https://remotelysave.com\">https://remotelysave.com</a>。注意:這和 Obsidian 官方賬號無關,是不同的賬號。</p><p>第二部:點選“連線”按鈕,從而連線本裝置和線上賬號。",
"settings_pro_features": "功能",

View File

@ -3,8 +3,12 @@ import { type App, Modal, Notice, Setting } from "obsidian";
import { getClient } from "../../src/fsGetter";
import type { TransItemType } from "../../src/i18n";
import type RemotelySavePlugin from "../../src/main";
import { stringToFragment } from "../../src/misc";
import { ChangeRemoteBaseDirModal } from "../../src/settings";
import { DEFAULT_GOOGLEDRIVE_CONFIG } from "./fsGoogleDrive";
import {
DEFAULT_GOOGLEDRIVE_CONFIG,
sendRefreshTokenReq,
} from "./fsGoogleDrive";
class GoogleDriveAuthModal extends Modal {
readonly plugin: RemotelySavePlugin;
@ -34,6 +38,9 @@ class GoogleDriveAuthModal extends Modal {
const authUrl = "https://remotelysave.com/auth/googledrive/start";
const div2 = contentEl.createDiv();
div2.createDiv({
text: stringToFragment(t("modal_googledriveauth_tutorial")),
});
div2.createEl(
"button",
{
@ -51,6 +58,65 @@ class GoogleDriveAuthModal extends Modal {
href: authUrl,
text: authUrl,
});
let refreshToken = "";
new Setting(contentEl)
.setName(t("modal_googledrivce_maualinput"))
.setDesc(t("modal_googledrivce_maualinput_desc"))
.addText((text) =>
text
.setPlaceholder("")
.setValue("")
.onChange((val) => {
refreshToken = val.trim();
})
)
.addButton(async (button) => {
button.setButtonText(t("submit"));
button.onClick(async () => {
new Notice(t("modal_googledrive_maualinput_notice"));
try {
if (this.plugin.settings.googledrive === undefined) {
this.plugin.settings.googledrive = cloneDeep(
DEFAULT_GOOGLEDRIVE_CONFIG
);
}
this.plugin.settings.googledrive.refreshToken = refreshToken;
this.plugin.settings.googledrive.accessToken = "access";
this.plugin.settings.googledrive.accessTokenExpiresAtTimeMs = 1;
this.plugin.settings.googledrive.accessTokenExpiresInMs = 1;
// TODO: abstraction leaking now, how to fix?
const k = await sendRefreshTokenReq(refreshToken);
const ts = Date.now();
this.plugin.settings.googledrive.accessToken = k.access_token;
this.plugin.settings.googledrive.accessTokenExpiresInMs =
k.expires_in * 1000;
this.plugin.settings.googledrive.accessTokenExpiresAtTimeMs =
ts + k.expires_in * 1000 - 60 * 2 * 1000;
await this.plugin.saveSettings();
// try to remove data in clipboard
await navigator.clipboard.writeText("");
new Notice(t("modal_googledrive_maualinput_succ_notice"));
} catch (e) {
console.error(e);
new Notice(t("modal_googledrive_maualinput_fail_notice"));
} finally {
this.authDiv.toggleClass(
"googledrive-auth-button-hide",
this.plugin.settings.googledrive.refreshToken !== ""
);
this.revokeAuthDiv.toggleClass(
"googledrive-revoke-auth-button-hide",
this.plugin.settings.googledrive.refreshToken === ""
);
this.close();
}
});
});
}
onClose() {
@ -108,12 +174,12 @@ class GoogleDriveRevokeAuthModal extends Modal {
await this.plugin.saveSettings();
this.authDiv.toggleClass(
"onedrive-auth-button-hide",
this.plugin.settings.onedrive.username !== ""
"googledrive-auth-button-hide",
this.plugin.settings.googledrive.refreshToken !== ""
);
this.revokeAuthDiv.toggleClass(
"onedrive-revoke-auth-button-hide",
this.plugin.settings.onedrive.username === ""
"googledrive-revoke-auth-button-hide",
this.plugin.settings.googledrive.refreshToken === ""
);
new Notice(t("modal_googledriverevokeauth_clean_notice"));
this.close();
@ -167,7 +233,41 @@ export const generateGoogleDriveSettingsPart = (
}),
});
const googleDriveSelectAuthDiv = googleDriveDiv.createDiv();
googleDriveLongDescDiv.createDiv({
text: stringToFragment(t("settings_googledrive_pro_desc")),
cls: "googledrive-disclaimer",
});
const googleDriveNotShowUpHintSetting = new Setting(googleDriveDiv)
.setName(t("settings_googledrive_notshowuphint"))
.setDesc(t("settings_googledrive_notshowuphint_desc"))
.addButton(async (button) => {
button.setButtonText(t("settings_googledrive_notshowuphint_view_pro"));
button.onClick(async () => {
window.location.href = "#settings-pro";
});
});
const googleDriveAllowedToUsedDiv = googleDriveDiv.createDiv();
// if pro enabled, show up; otherwise hide.
const allowGoogleDrive =
plugin.settings.pro?.enabledProFeatures.filter(
(x) => x.featureName === "feature-google_drive"
).length === 1;
console.debug(`allow to show up google drive settings? ${allowGoogleDrive}`);
if (allowGoogleDrive) {
googleDriveAllowedToUsedDiv.removeClass("googledrive-allow-to-use-hide");
googleDriveNotShowUpHintSetting.settingEl.addClass(
"googledrive-allow-to-use-hide"
);
} else {
googleDriveAllowedToUsedDiv.addClass("googledrive-allow-to-use-hide");
googleDriveNotShowUpHintSetting.settingEl.removeClass(
"googledrive-allow-to-use-hide"
);
}
const googleDriveSelectAuthDiv = googleDriveAllowedToUsedDiv.createDiv();
const googleDriveAuthDiv = googleDriveSelectAuthDiv.createDiv({
cls: "googledrive-auth-button-hide settings-auth-related",
});
@ -224,7 +324,7 @@ export const generateGoogleDriveSettingsPart = (
let newgoogleDriveRemoteBaseDir =
plugin.settings.googledrive.remoteBaseDir || "";
new Setting(googleDriveDiv)
new Setting(googleDriveAllowedToUsedDiv)
.setName(t("settings_remotebasedir"))
.setDesc(t("settings_remotebasedir_desc"))
.addText((text) =>
@ -246,7 +346,7 @@ export const generateGoogleDriveSettingsPart = (
).open();
});
});
new Setting(googleDriveDiv)
new Setting(googleDriveAllowedToUsedDiv)
.setName(t("settings_checkonnectivity"))
.setDesc(t("settings_checkonnectivity_desc"))
.addButton(async (button) => {
@ -269,5 +369,9 @@ export const generateGoogleDriveSettingsPart = (
});
});
return googleDriveDiv;
return {
googleDriveDiv: googleDriveDiv,
googleDriveAllowedToUsedDiv: googleDriveAllowedToUsedDiv,
googleDriveNotShowUpHintSetting: googleDriveNotShowUpHintSetting,
};
};

View File

@ -150,6 +150,9 @@ export class ProAuthModal extends Modal {
);
this.plugin.oauth2Info.revokeDiv = undefined;
// try to remove data in clipboard
await navigator.clipboard.writeText("");
this.close();
} catch (err) {
console.error(err);
@ -244,7 +247,9 @@ export const generateProSettingsPart = (
t: (x: TransItemType, vars?: any) => string,
app: App,
plugin: RemotelySavePlugin,
saveUpdatedConfigFunc: () => Promise<any> | undefined
saveUpdatedConfigFunc: () => Promise<any> | undefined,
googleDriveAllowedToUsedDiv: HTMLDivElement,
googleDriveNotShowUpHintSetting: Setting
) => {
proDiv
.createEl("h2", { text: t("settings_pro") })
@ -290,6 +295,28 @@ export const generateProSettingsPart = (
})
)
);
const allowGoogleDrive =
plugin.settings.pro?.enabledProFeatures.filter(
(x) => x.featureName === "feature-google_drive"
).length === 1;
console.debug(
`allow to show up google drive settings? ${allowGoogleDrive}`
);
if (allowGoogleDrive) {
googleDriveAllowedToUsedDiv.removeClass(
"googledrive-allow-to-use-hide"
);
googleDriveNotShowUpHintSetting.settingEl.addClass(
"googledrive-allow-to-use-hide"
);
} else {
googleDriveAllowedToUsedDiv.addClass("googledrive-allow-to-use-hide");
googleDriveNotShowUpHintSetting.settingEl.removeClass(
"googledrive-allow-to-use-hide"
);
}
new Notice(t("settings_pro_features_refresh_succ"));
});
});

View File

@ -1796,7 +1796,11 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
// below for googledrive
//////////////////////////////////////////////////
const googleDriveDiv = generateGoogleDriveSettingsPart(
const {
googleDriveDiv,
googleDriveAllowedToUsedDiv,
googleDriveNotShowUpHintSetting,
} = generateGoogleDriveSettingsPart(
containerEl,
t,
this.app,
@ -2473,8 +2477,14 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
//////////////////////////////////////////////////
const proDiv = containerEl.createEl("div");
generateProSettingsPart(proDiv, t, this.app, this.plugin, () =>
this.plugin.saveSettings()
generateProSettingsPart(
proDiv,
t,
this.app,
this.plugin,
() => this.plugin.saveSettings(),
googleDriveAllowedToUsedDiv,
googleDriveNotShowUpHintSetting
);
//////////////////////////////////////////////////

View File

@ -1508,7 +1508,7 @@ export async function syncer(
// check pro feature
// if anything goes wrong, it will throw
await checkProRunnableAndFixInplace(
["feature-smart_conflict"],
["feature-smart_conflict", "feature-google_drive"],
settings,
pluginVersion,
configSaver

View File

@ -79,6 +79,10 @@
display: none;
}
.googledrive-allow-to-use-hide {
display: none;
}
.googledrive-auth-button-hide {
display: none;
}