feat: add reserve proxy url (#479)

Co-authored-by: Adens <dwang@senparc.com>
Co-authored-by: fyears <1142836+fyears@users.noreply.github.com>
This commit is contained in:
Adens Wang 2024-04-05 10:36:58 +08:00 committed by GitHub
parent fe572b41c9
commit 220fd07a8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 38 additions and 17 deletions

View File

@ -32,6 +32,7 @@ export interface S3Config {
* @deprecated
*/
bypassCorsLocally?: boolean;
reverseProxyUrl: string;
}
export interface DropboxConfig {

View File

@ -57,7 +57,6 @@
"statusbar_lastsync_label": "Last successful Sync on {{date}}",
"statusbar_lastsync_never": "Never Synced",
"statusbar_lastsync_never_label": "Never Synced before",
"modal_password_title": "Hold on and PLEASE READ ON...",
"modal_password_shortdesc": "If the field is not empty, files would be encrypted locally before being uploaded.\nIf the field is empty, then files would be uploaded without encryption.",
"modal_password_attn1": "Attention 1/5: The vault name is NOT encrypted. The plugin creates a folder with the vault name on some remote services.",
@ -144,7 +143,6 @@
"settings_skiplargefiles": "Skip Large Files",
"settings_skiplargefiles_desc": "Skip files with sizes larger than the threshold. Here 1 MB = 10^6 bytes.",
"settings_skiplargefiles_notset": "(not set)",
"settings_ignorepaths": "Regex Of Paths To Ignore",
"settings_ignorepaths_desc": "Regex of paths of folders or files to ignore. One regex per line. The path is relative to the vault root without leading slash.",
"settings_enablestatusbar_info": "Show Last Successful Sync In Status Bar",
@ -154,7 +152,6 @@
"settings_resetstatusbar_time_desc": "Reset last successful sync time.",
"settings_resetstatusbar_button": "Reset",
"settings_resetstatusbar_notice": "Reset done!",
"settings_checkonnectivity": "Check Connectivity",
"settings_checkonnectivity_desc": "Check connectivity.",
"settings_checkonnectivity_button": "Check",
@ -187,6 +184,8 @@
"settings_s3_accuratemtime_desc": "Read the uploaded accurate last modified time for better sync algorithm. But it causes extra api requests / time / money to the S3 endpoint.",
"settings_s3_urlstyle": "S3 URL style",
"settings_s3_urlstyle_desc": "Whether to force path-style URLs for S3 objects (e.g., https://s3.amazonaws.com/*/ instead of https://*.s3.amazonaws.com/).",
"settings_s3_reverse_proxy_url": "S3 Reverse Proxy Url",
"settings_s3_reverse_proxy_url_desc": "S3 Reverse Proxy Url.(Leave blank if you don't have a reverse proxy)",
"settings_s3_connect_succ": "Great! The bucket can be accessed.",
"settings_s3_connect_fail": "The S3 bucket cannot be reached.",
"settings_dropbox": "Remote For Dropbox",
@ -323,6 +322,7 @@
"settings_resetcache_desc": "Reset local internal caches/databases (for debugging purposes). You would want to reload the plugin after resetting this. This option will not empty the {s3, password...} settings.",
"settings_resetcache_button": "Reset",
"settings_resetcache_notice": "Local internal cache/databases deleted. Please manually reload the plugin.",
"syncalgov3_title": "Remotely Save has HUGE updates on the sync algorithm",
"syncalgov3_texts": "Welcome to use Remotely Save!\nFrom this version, a new algorithm has been developed:\n<ul><li>More robust deletion sync,</li><li>minimal conflict handling,</li><li>no meta data uploaded any more,</li><li>deletion / modification protection,</li><li>backup mode</li><li>new encryption method</li><li>...</li></ul>\nStay tune for more! A full introduction is in the <a href='https://github.com/remotely-save/remotely-save/tree/master/docs/sync_algorithm/v3/intro.md'>doc website</a>.\nIf you agree to use this, please read and check two checkboxes then click the \"Agree\" button, and enjoy the plugin!\nIf you do not agree, please click the \"Do Not Agree\" button, the plugin will unload itself.\nAlso, please consider <a href='https://github.com/remotely-save/remotely-save'>visit the GitHub repo and star ⭐ it</a>! Or even <a href='https://github.com/remotely-save/donation'>buy me a coffee</a>. Your support is very important to me! Thanks!",
"syncalgov3_checkbox_manual_backup": "I will backup my vault manually firstly.",
@ -330,3 +330,4 @@
"syncalgov3_button_agree": "Agree",
"syncalgov3_button_disagree": "Do Not Agree"
}

View File

@ -57,7 +57,6 @@
"statusbar_lastsync_label": "上一次同步于:{{date}}",
"statusbar_lastsync_never": "没触发过同步",
"statusbar_lastsync_never_label": "没触发过同步",
"modal_password_title": "稍等一下,请阅读下文:",
"modal_password_shortdesc": "如果密码不是空的,那么文件会在上传之前,在本地先用此密码加密。\n如果密码是空的那么文件会被非加密地上传。",
"modal_password_attn1": "注意 1/5Vault名字是不会加密的本插件会在一些远程存储里创建一个和库名字有着同名的文件夹。",
@ -143,7 +142,6 @@
"settings_skiplargefiles": "跳过大文件",
"settings_skiplargefiles_desc": "跳过大于某一个阈值的文件。这里 1 MB = 10^6 bytes。",
"settings_skiplargefiles_notset": "(不设置)",
"settings_ignorepaths": "忽略的文件或文件夹的正则表达式",
"settings_ignorepaths_desc": "忽略的文件或文件夹的正则表达式。每行一条。路径是相对于库Vault根目录的没有前置 / 符号。",
"settings_enablestatusbar_info": "在状态栏显示上一次成功的同步",
@ -153,7 +151,6 @@
"settings_resetstatusbar_time_desc": "重设上一次成功同步的时间记录。",
"settings_resetstatusbar_button": "重设",
"settings_resetstatusbar_notice": "重设完毕!",
"settings_checkonnectivity": "检查可否连接",
"settings_checkonnectivity_desc": "检查可否连接。",
"settings_checkonnectivity_button": "检查",
@ -186,6 +183,8 @@
"settings_s3_accuratemtime_desc": "读取(已上传的)准确的文件修改时间,有助于同步算法更加准确和稳定。但是它也会导致额外的 api 请求、时间、金钱花费。",
"settings_s3_urlstyle": "S3 URL style",
"settings_s3_urlstyle_desc": "是否对 S3 对象强制使用 path style URL例如使用 https://s3.amazonaws.com/*/ 而不是 https://*.s3.amazonaws.com/)。",
"settings_s3_reverse_proxy_url": "S3 反向代理地址",
"settings_s3_reverse_proxy_url_desc": "S3 反向代理地址。(如果没有设置反向代理请留空)",
"settings_s3_connect_succ": "很好!可以访问到对应存储桶。",
"settings_s3_connect_fail": "无法访问到对应存储桶。",
"settings_dropbox": "Dropbox 设置",
@ -322,6 +321,7 @@
"settings_resetcache_desc": "(出于调试原因)重设本地缓存和数据库。您需要在重设之后重新载入此插件。本重设不会删除 s3密码……等设定。",
"settings_resetcache_button": "重设",
"settings_resetcache_notice": "本地同步缓存和数据库已被删除。请手动重新载入此插件。",
"syncalgov3_title": "Remotely Save 的同步算法有重大更新",
"syncalgov3_texts": "欢迎使用 Remotely Save\n从这个版本开始插件更新了同步算法\n<ul><li>更稳健的删除同步</li><li>引入冲突处理</li><li>避免上传元数据</li><li>修改删除保护</li><li>备份模式</li><li>新的加密方式</li><li>……</li></ul>\n敬请期待更多更新详细介绍请参阅<a href='https://github.com/remotely-save/remotely-save/tree/master/docs/sync_algorithm/v3/intro.md'>文档网站</a>。\n如果您同意使用新版本请阅读和勾选两个勾选框然后点击“同意”按钮开始使用插件吧\n如果您不同意请点击“不同意”按钮插件将自动停止运行unload。\n此外请考虑<a href='https://github.com/remotely-save/remotely-save'>访问 GitHub 页面然后点赞 ⭐</a>!您的支持对我十分重要!谢谢!",
"syncalgov3_checkbox_manual_backup": "我将会首先手动备份我的库Vault。",
@ -329,3 +329,4 @@
"syncalgov3_button_agree": "同意",
"syncalgov3_button_disagree": "不同意"
}

View File

@ -56,7 +56,6 @@
"statusbar_lastsync_label": "上一次同步於:{{date}}",
"statusbar_lastsync_never": "沒觸發過同步",
"statusbar_lastsync_never_label": "沒觸發過同步",
"modal_password_title": "稍等一下,請閱讀下文:",
"modal_password_shortdesc": "如果密碼不是空的,那麼檔案會在上傳之前,在本地先用此密碼加密。\n如果密碼是空的那麼檔案會被非加密地上傳。",
"modal_password_attn1": "注意 1/5儲存庫Vault名字是不會加密的本外掛會在一些遠端儲存裡建立一個和庫名字有著同名的資料夾。",
@ -142,7 +141,6 @@
"settings_skiplargefiles": "跳過大檔案",
"settings_skiplargefiles_desc": "跳過大於某一個閾值的檔案。這裡 1 MB = 10^6 bytes。",
"settings_skiplargefiles_notset": "(不設定)",
"settings_ignorepaths": "忽略的檔案或資料夾的正則表示式",
"settings_ignorepaths_desc": "忽略的檔案或資料夾的正則表示式。每行一條。路徑是相對於庫Vault根目錄的沒有前置 / 符號。",
"settings_enablestatusbar_info": "在狀態列顯示上一次成功的同步",
@ -152,7 +150,6 @@
"settings_resetstatusbar_time_desc": "重設上一次成功同步的時間記錄。",
"settings_resetstatusbar_button": "重設",
"settings_resetstatusbar_notice": "重設完畢!",
"settings_checkonnectivity": "檢查可否連線",
"settings_checkonnectivity_desc": "檢查可否連線。",
"settings_checkonnectivity_button": "檢查",
@ -185,6 +182,8 @@
"settings_s3_accuratemtime_desc": "讀取(已上傳的)準確的檔案修改時間,有助於同步演算法更加準確和穩定。但是它也會導致額外的 api 請求、時間、金錢花費。",
"settings_s3_urlstyle": "S3 URL style",
"settings_s3_urlstyle_desc": "是否對 S3 物件強制使用 path style URL例如使用 https://s3.amazonaws.com/*/ 而不是 https://*.s3.amazonaws.com/)。",
"settings_s3_reverse_proxy_url": "S3 反向代理地址",
"settings_s3_reverse_proxy_url_desc": "S3 反向代理地址。(如果沒有設置反向代理請留空)",
"settings_s3_connect_succ": "很好!可以訪問到對應儲存桶。",
"settings_s3_connect_fail": "無法訪問到對應儲存桶。",
"settings_dropbox": "Dropbox 設定",
@ -321,6 +320,7 @@
"settings_resetcache_desc": "(出於除錯原因)重設本地快取和資料庫。您需要在重設之後重新載入此外掛。本重設不會刪除 s3密碼……等設定。",
"settings_resetcache_button": "重設",
"settings_resetcache_notice": "本地同步快取和資料庫已被刪除。請手動重新載入此外掛。",
"syncalgov3_title": "Remotely Save 的同步演算法有重大更新",
"syncalgov3_texts": "歡迎使用 Remotely Save\n從這個版本開始外掛更新了同步演算法\n<ul><li>更穩健的刪除同步</li><li>引入衝突處理</li><li>避免上傳元資料</li><li>修改刪除保護</li><li>備份模式</li><li>新的加密方式</li><li>……</li></ul>\n敬請期待更多更新詳細介紹請參閱<a href='https://github.com/remotely-save/remotely-save/tree/master/docs/sync_algorithm/v3/intro.md'>文件網站</a>。\n如果您同意使用新版本請閱讀和勾選兩個勾選框然後點選“同意”按鈕開始使用外掛吧\n如果您不同意請點選“不同意”按鈕外掛將自動停止執行unload。\n此外請考慮<a href='https://github.com/remotely-save/remotely-save'>訪問 GitHub 頁面然後點贊 ⭐</a>!您的支援對我十分重要!謝謝!",
"syncalgov3_checkbox_manual_backup": "我將會首先手動備份我的庫Vault。",
@ -328,3 +328,4 @@
"syncalgov3_button_agree": "同意",
"syncalgov3_button_disagree": "不同意"
}

View File

@ -56,10 +56,12 @@ import { Cipher } from "./encryptUnified";
*/
class ObsHttpHandler extends FetchHttpHandler {
requestTimeoutInMs: number | undefined;
constructor(options?: FetchHttpHandlerOptions) {
s3Config: S3Config | undefined;
constructor(options?: FetchHttpHandlerOptions, s3Config?: S3Config) {
super(options);
this.requestTimeoutInMs =
options === undefined ? undefined : options.requestTimeout;
this.s3Config = s3Config;
}
async handle(
request: HttpRequest,
@ -80,9 +82,11 @@ class ObsHttpHandler extends FetchHttpHandler {
}
const { port, method } = request;
const url = `${request.protocol}//${request.hostname}${
port ? `:${port}` : ""
}${path}`;
let url = `${request.protocol}//${request.hostname}${port ? `:${port}` : ""
}${path}`;
if (this.s3Config && this.s3Config.reverseProxyUrl && this.s3Config.reverseProxyUrl !== "") {
url = url.replace(this.s3Config.s3Endpoint, this.s3Config.reverseProxyUrl);
}
const body =
method === "GET" || method === "HEAD" ? undefined : request.body;
@ -167,6 +171,7 @@ export const DEFAULT_S3_CONFIG: S3Config = {
forcePathStyle: false,
remotePrefix: "",
useAccurateMTime: false, // it causes money, disable by default
reverseProxyUrl: "",
};
export type S3ObjectType = _Object;
@ -305,8 +310,9 @@ export const getS3Client = (s3Config: S3Config) => {
}
let s3Client: S3Client;
if ((VALID_REQURL && s3Config.bypassCorsLocally) || (s3Config.reverseProxyUrl && s3Config.reverseProxyUrl !== "")) {
console.log("reverseProxyUrl", s3Config.reverseProxyUrl);
if (VALID_REQURL && s3Config.bypassCorsLocally) {
s3Client = new S3Client({
region: s3Config.s3Region,
endpoint: endpoint,
@ -315,7 +321,7 @@ export const getS3Client = (s3Config: S3Config) => {
accessKeyId: s3Config.s3AccessKeyID,
secretAccessKey: s3Config.s3SecretAccessKey,
},
requestHandler: new ObsHttpHandler(),
requestHandler: new ObsHttpHandler(undefined, s3Config),
});
} else {
s3Client = new S3Client({

View File

@ -976,8 +976,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
dropdown
.setValue(
`${
this.plugin.settings.s3.bypassCorsLocally ? "enable" : "disable"
`${this.plugin.settings.s3.bypassCorsLocally ? "enable" : "disable"
}`
)
.onChange(async (value) => {
@ -1056,6 +1055,18 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
).open();
});
});
new Setting(s3Div)
.setName(t("settings_s3_reverse_proxy_url"))
.setDesc(t("settings_s3_reverse_proxy_url_desc"))
.addText((text) =>
text
.setPlaceholder("")
.setValue(this.plugin.settings.s3.reverseProxyUrl)
.onChange(async (value) => {
this.plugin.settings.s3.reverseProxyUrl = value.trim();
await this.plugin.saveSettings();
})
);
new Setting(s3Div)
.setName(t("settings_checkonnectivity"))