mirror of
https://github.com/remotely-save/remotely-save.git
synced 2024-06-07 21:10:45 +00:00
more verbose reason for conn fail
This commit is contained in:
parent
63a66d69f9
commit
4f3e8803da
@ -271,15 +271,22 @@ export class RemoteClient {
|
||||
}
|
||||
};
|
||||
|
||||
checkConnectivity = async () => {
|
||||
checkConnectivity = async (callbackFunc?: any) => {
|
||||
if (this.serviceType === "s3") {
|
||||
return await s3.checkConnectivity(this.s3Client, this.s3Config);
|
||||
return await s3.checkConnectivity(
|
||||
this.s3Client,
|
||||
this.s3Config,
|
||||
callbackFunc
|
||||
);
|
||||
} else if (this.serviceType === "webdav") {
|
||||
return await webdav.checkConnectivity(this.webdavClient);
|
||||
return await webdav.checkConnectivity(this.webdavClient, callbackFunc);
|
||||
} else if (this.serviceType === "dropbox") {
|
||||
return await dropbox.checkConnectivity(this.dropboxClient);
|
||||
return await dropbox.checkConnectivity(this.dropboxClient, callbackFunc);
|
||||
} else if (this.serviceType === "onedrive") {
|
||||
return await onedrive.checkConnectivity(this.onedriveClient);
|
||||
return await onedrive.checkConnectivity(
|
||||
this.onedriveClient,
|
||||
callbackFunc
|
||||
);
|
||||
} else {
|
||||
throw Error(`not supported service type ${this.serviceType}`);
|
||||
}
|
||||
|
@ -636,7 +636,10 @@ export const deleteFromRemote = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const checkConnectivity = async (client: WrappedDropboxClient) => {
|
||||
export const checkConnectivity = async (
|
||||
client: WrappedDropboxClient,
|
||||
callbackFunc?: any
|
||||
) => {
|
||||
try {
|
||||
const results = await getRemoteMeta(client, "/");
|
||||
if (results === undefined) {
|
||||
@ -644,8 +647,10 @@ export const checkConnectivity = async (client: WrappedDropboxClient) => {
|
||||
}
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error("dropbox connectivity error:");
|
||||
console.error(err);
|
||||
log.debug(err);
|
||||
if (callbackFunc !== undefined) {
|
||||
callbackFunc(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
@ -866,11 +866,18 @@ export const deleteFromRemote = async (
|
||||
await client.deleteJson(remoteFileName);
|
||||
};
|
||||
|
||||
export const checkConnectivity = async (client: WrappedOnedriveClient) => {
|
||||
export const checkConnectivity = async (
|
||||
client: WrappedOnedriveClient,
|
||||
callbackFunc?: any
|
||||
) => {
|
||||
try {
|
||||
const k = await getUserDisplayName(client);
|
||||
return k !== "<unknown display name>";
|
||||
} catch (err) {
|
||||
log.debug(err);
|
||||
if (callbackFunc !== undefined) {
|
||||
callbackFunc(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
@ -498,7 +498,8 @@ export const deleteFromRemote = async (
|
||||
*/
|
||||
export const checkConnectivity = async (
|
||||
s3Client: S3Client,
|
||||
s3Config: S3Config
|
||||
s3Config: S3Config,
|
||||
callbackFunc?: any
|
||||
) => {
|
||||
try {
|
||||
const results = await s3Client.send(
|
||||
@ -509,10 +510,19 @@ export const checkConnectivity = async (
|
||||
results.$metadata === undefined ||
|
||||
results.$metadata.httpStatusCode === undefined
|
||||
) {
|
||||
const err = "results or $metadata or httStatusCode is undefined";
|
||||
log.debug(err);
|
||||
if (callbackFunc !== undefined) {
|
||||
callbackFunc(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return results.$metadata.httpStatusCode === 200;
|
||||
} catch (err) {
|
||||
log.debug(err);
|
||||
if (callbackFunc !== undefined) {
|
||||
callbackFunc(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
@ -523,15 +523,27 @@ export const deleteFromRemote = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const checkConnectivity = async (client: WrappedWebdavClient) => {
|
||||
export const checkConnectivity = async (
|
||||
client: WrappedWebdavClient,
|
||||
callbackFunc?: any
|
||||
) => {
|
||||
try {
|
||||
await client.init();
|
||||
const results = await getRemoteMeta(client, "/");
|
||||
if (results === undefined) {
|
||||
const err = "results is undefined";
|
||||
log.debug(err);
|
||||
if (callbackFunc !== undefined) {
|
||||
callbackFunc(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (err) {
|
||||
log.debug(err);
|
||||
if (callbackFunc !== undefined) {
|
||||
callbackFunc(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
@ -826,11 +826,15 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
button.onClick(async () => {
|
||||
new Notice(t("settings_checkonnectivity_checking"));
|
||||
const client = new RemoteClient("s3", this.plugin.settings.s3);
|
||||
const res = await client.checkConnectivity();
|
||||
const errors = { msg: "" };
|
||||
const res = await client.checkConnectivity((err: any) => {
|
||||
errors.msg = err;
|
||||
});
|
||||
if (res) {
|
||||
new Notice(t("settings_s3_connect_succ"));
|
||||
} else {
|
||||
new Notice(t("settings_s3_connect_fail"));
|
||||
new Notice(errors.msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -959,11 +963,15 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
() => self.plugin.saveSettings()
|
||||
);
|
||||
|
||||
const res = await client.checkConnectivity();
|
||||
const errors = { msg: "" };
|
||||
const res = await client.checkConnectivity((err: any) => {
|
||||
errors.msg = `${err}`;
|
||||
});
|
||||
if (res) {
|
||||
new Notice(t("settings_dropbox_connect_succ"));
|
||||
} else {
|
||||
new Notice(t("settings_dropbox_connect_fail"));
|
||||
new Notice(errors.msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1074,11 +1082,15 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
() => self.plugin.saveSettings()
|
||||
);
|
||||
|
||||
const res = await client.checkConnectivity();
|
||||
const errors = { msg: "" };
|
||||
const res = await client.checkConnectivity((err: any) => {
|
||||
errors.msg = `${err}`;
|
||||
});
|
||||
if (res) {
|
||||
new Notice(t("settings_onedrive_connect_succ"));
|
||||
} else {
|
||||
new Notice(t("settings_onedrive_connect_fail"));
|
||||
new Notice(errors.msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1230,7 +1242,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
this.app.vault.getName(),
|
||||
() => self.plugin.saveSettings()
|
||||
);
|
||||
const res = await client.checkConnectivity();
|
||||
const errors = { msg: "" };
|
||||
const res = await client.checkConnectivity((err: any) => {
|
||||
errors.msg = `${err}`;
|
||||
});
|
||||
if (res) {
|
||||
new Notice(t("settings_webdav_connect_succ"));
|
||||
} else {
|
||||
@ -1244,6 +1259,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
corsErrMsg: corsErrMsg,
|
||||
})
|
||||
);
|
||||
new Notice(errors.msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user