unified requrl everywhere
This commit is contained in:
parent
39a33243e8
commit
e03522efe4
@ -3,6 +3,7 @@
|
|||||||
* To avoid circular dependency.
|
* To avoid circular dependency.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { Platform, requireApiVersion } from "obsidian";
|
||||||
import type { LangType, LangTypeAndAuto } from "./i18n";
|
import type { LangType, LangTypeAndAuto } from "./i18n";
|
||||||
|
|
||||||
export const DEFAULT_CONTENT_TYPE = "application/octet-stream";
|
export const DEFAULT_CONTENT_TYPE = "application/octet-stream";
|
||||||
@ -148,3 +149,5 @@ export interface FileOrFolderMixedState {
|
|||||||
|
|
||||||
export const API_VER_STAT_FOLDER = "0.13.27";
|
export const API_VER_STAT_FOLDER = "0.13.27";
|
||||||
export const API_VER_REQURL = "0.13.26";
|
export const API_VER_REQURL = "0.13.26";
|
||||||
|
export const VALID_REQURL =
|
||||||
|
requireApiVersion(API_VER_REQURL) && !Platform.isAndroidApp;
|
||||||
|
|||||||
@ -22,19 +22,13 @@ import { buildQueryString } from "@aws-sdk/querystring-builder";
|
|||||||
import { HeaderBag, HttpHandlerOptions, Provider } from "@aws-sdk/types";
|
import { HeaderBag, HttpHandlerOptions, Provider } from "@aws-sdk/types";
|
||||||
import { Buffer } from "buffer";
|
import { Buffer } from "buffer";
|
||||||
import * as mime from "mime-types";
|
import * as mime from "mime-types";
|
||||||
import {
|
import { Vault, requestUrl, RequestUrlParam } from "obsidian";
|
||||||
Vault,
|
|
||||||
requestUrl,
|
|
||||||
RequestUrlParam,
|
|
||||||
RequestUrlResponse,
|
|
||||||
requireApiVersion,
|
|
||||||
} from "obsidian";
|
|
||||||
import { Readable } from "stream";
|
import { Readable } from "stream";
|
||||||
import {
|
import {
|
||||||
API_VER_REQURL,
|
|
||||||
DEFAULT_CONTENT_TYPE,
|
DEFAULT_CONTENT_TYPE,
|
||||||
RemoteItem,
|
RemoteItem,
|
||||||
S3Config,
|
S3Config,
|
||||||
|
VALID_REQURL,
|
||||||
} from "./baseTypes";
|
} from "./baseTypes";
|
||||||
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
|
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
|
||||||
import {
|
import {
|
||||||
@ -194,7 +188,7 @@ export const getS3Client = (s3Config: S3Config) => {
|
|||||||
endpoint = `https://${endpoint}`;
|
endpoint = `https://${endpoint}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requireApiVersion(API_VER_REQURL) && s3Config.bypassCorsLocally) {
|
if (VALID_REQURL && s3Config.bypassCorsLocally) {
|
||||||
const s3Client = new S3Client({
|
const s3Client = new S3Client({
|
||||||
region: s3Config.s3Region,
|
region: s3Config.s3Region,
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
|
|||||||
@ -1,19 +1,11 @@
|
|||||||
import { Buffer } from "buffer";
|
import { Buffer } from "buffer";
|
||||||
import {
|
import { Vault, requestUrl } from "obsidian";
|
||||||
Vault,
|
|
||||||
request,
|
|
||||||
requestUrl,
|
|
||||||
requireApiVersion,
|
|
||||||
Platform,
|
|
||||||
Notice,
|
|
||||||
RequestUrlResponse,
|
|
||||||
} from "obsidian";
|
|
||||||
|
|
||||||
import { Queue } from "@fyears/tsqueue";
|
import { Queue } from "@fyears/tsqueue";
|
||||||
import chunk from "lodash/chunk";
|
import chunk from "lodash/chunk";
|
||||||
import flatten from "lodash/flatten";
|
import flatten from "lodash/flatten";
|
||||||
import { getReasonPhrase } from "http-status-codes";
|
import { getReasonPhrase } from "http-status-codes";
|
||||||
import { API_VER_REQURL, RemoteItem, WebdavConfig } from "./baseTypes";
|
import { RemoteItem, VALID_REQURL, WebdavConfig } from "./baseTypes";
|
||||||
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
|
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
|
||||||
import { bufferToArrayBuffer, getPathFolder, mkdirpInVault } from "./misc";
|
import { bufferToArrayBuffer, getPathFolder, mkdirpInVault } from "./misc";
|
||||||
|
|
||||||
@ -28,7 +20,7 @@ import type {
|
|||||||
ResponseDataDetailed,
|
ResponseDataDetailed,
|
||||||
} from "webdav/web";
|
} from "webdav/web";
|
||||||
import { getPatcher } from "webdav/web";
|
import { getPatcher } from "webdav/web";
|
||||||
if (requireApiVersion(API_VER_REQURL) && !Platform.isAndroidApp) {
|
if (VALID_REQURL) {
|
||||||
getPatcher().patch(
|
getPatcher().patch(
|
||||||
"request",
|
"request",
|
||||||
async (
|
async (
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import {
|
|||||||
API_VER_REQURL,
|
API_VER_REQURL,
|
||||||
SUPPORTED_SERVICES_TYPE,
|
SUPPORTED_SERVICES_TYPE,
|
||||||
SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR,
|
SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR,
|
||||||
|
VALID_REQURL,
|
||||||
WebdavAuthType,
|
WebdavAuthType,
|
||||||
WebdavDepthType,
|
WebdavDepthType,
|
||||||
} from "./baseTypes";
|
} from "./baseTypes";
|
||||||
@ -747,7 +748,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!requireApiVersion(API_VER_REQURL)) {
|
if (!VALID_REQURL) {
|
||||||
s3Div.createEl("p", {
|
s3Div.createEl("p", {
|
||||||
text: t("settings_s3_cors"),
|
text: t("settings_s3_cors"),
|
||||||
});
|
});
|
||||||
@ -769,7 +770,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
text: t("settings_s3_prod2"),
|
text: t("settings_s3_prod2"),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!requireApiVersion(API_VER_REQURL)) {
|
if (!VALID_REQURL) {
|
||||||
s3LinksUl.createEl("li").createEl("a", {
|
s3LinksUl.createEl("li").createEl("a", {
|
||||||
href: "https://docs.aws.amazon.com/AmazonS3/latest/userguide/enabling-cors-examples.html",
|
href: "https://docs.aws.amazon.com/AmazonS3/latest/userguide/enabling-cors-examples.html",
|
||||||
text: t("settings_s3_prod3"),
|
text: t("settings_s3_prod3"),
|
||||||
@ -862,7 +863,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (requireApiVersion(API_VER_REQURL)) {
|
if (VALID_REQURL) {
|
||||||
new Setting(s3Div)
|
new Setting(s3Div)
|
||||||
.setName(t("settings_s3_bypasscorslocally"))
|
.setName(t("settings_s3_bypasscorslocally"))
|
||||||
.setDesc(
|
.setDesc(
|
||||||
@ -1277,9 +1278,6 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
this.plugin.settings.serviceType !== "webdav"
|
this.plugin.settings.serviceType !== "webdav"
|
||||||
);
|
);
|
||||||
|
|
||||||
const webdavReq =
|
|
||||||
requireApiVersion(API_VER_REQURL) && !Platform.isAndroidApp;
|
|
||||||
|
|
||||||
webdavDiv.createEl("h2", { text: t("settings_webdav") });
|
webdavDiv.createEl("h2", { text: t("settings_webdav") });
|
||||||
|
|
||||||
webdavDiv.createEl("p", {
|
webdavDiv.createEl("p", {
|
||||||
@ -1287,7 +1285,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
cls: "webdav-disclaimer",
|
cls: "webdav-disclaimer",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!webdavReq) {
|
if (!VALID_REQURL) {
|
||||||
if (Platform.isAndroidApp) {
|
if (Platform.isAndroidApp) {
|
||||||
webdavDiv.createEl("p", {
|
webdavDiv.createEl("p", {
|
||||||
text: t("settings_webdav_cors_android"),
|
text: t("settings_webdav_cors_android"),
|
||||||
@ -1372,12 +1370,12 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
.setDesc(t("settings_webdav_auth_desc"))
|
.setDesc(t("settings_webdav_auth_desc"))
|
||||||
.addDropdown(async (dropdown) => {
|
.addDropdown(async (dropdown) => {
|
||||||
dropdown.addOption("basic", "basic");
|
dropdown.addOption("basic", "basic");
|
||||||
if (webdavReq) {
|
if (VALID_REQURL) {
|
||||||
dropdown.addOption("digest", "digest");
|
dropdown.addOption("digest", "digest");
|
||||||
}
|
}
|
||||||
|
|
||||||
// new version config, copied to old version, we need to reset it
|
// new version config, copied to old version, we need to reset it
|
||||||
if (!webdavReq && this.plugin.settings.webdav.authType !== "basic") {
|
if (!VALID_REQURL && this.plugin.settings.webdav.authType !== "basic") {
|
||||||
this.plugin.settings.webdav.authType = "basic";
|
this.plugin.settings.webdav.authType = "basic";
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
}
|
}
|
||||||
@ -1475,7 +1473,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
if (res) {
|
if (res) {
|
||||||
new Notice(t("settings_webdav_connect_succ"));
|
new Notice(t("settings_webdav_connect_succ"));
|
||||||
} else {
|
} else {
|
||||||
if (webdavReq) {
|
if (VALID_REQURL) {
|
||||||
new Notice(t("settings_webdav_connect_fail"));
|
new Notice(t("settings_webdav_connect_fail"));
|
||||||
} else {
|
} else {
|
||||||
new Notice(t("settings_webdav_connect_fail_withcors"));
|
new Notice(t("settings_webdav_connect_fail_withcors"));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user