Skip to content

Commit 1bc7624

Browse files
committed
fix(useHost): Hosting service.
1 parent c2b6111 commit 1bc7624

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

src/main.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,9 +1363,15 @@ export default class InvioPlugin extends Plugin {
13631363
getRemoteDomain() {
13641364
let domain = this.settings.remoteDomain;
13651365
if (!domain) {
1366-
if (this.settings.useHost && this.settings.hostConfig?.hostPair?.slug) {
1367-
const slug = this.settings.hostConfig?.hostPair.slug;
1368-
domain = `https://${slug}.${ServerDomain}`;
1366+
if (this.settings.useHost) {
1367+
if (this.settings.hostConfig?.hostPair?.slug) {
1368+
const slug = this.settings.hostConfig?.hostPair.slug;
1369+
domain = `https://${slug}.${ServerDomain}`;
1370+
} else {
1371+
// Redo auth
1372+
Utils.gotoAuth();
1373+
return '';
1374+
}
13691375
} else {
13701376
if (!this.settings.s3.s3BucketName) return '';
13711377
domain = `https://${this.settings.s3.s3BucketName}.${this.settings.s3.s3Endpoint}`;
@@ -1391,11 +1397,10 @@ export default class InvioPlugin extends Plugin {
13911397
this.settings.localWatchDir,
13921398
this.app.vault.getName(),
13931399
);
1394-
const publishedKey = client.getUseHostSlugPath(pathName)
13951400
// Check remote link
1396-
const remoteContents = await client.listFromRemote(publishedKey?.split('/').slice(0, -1).join('/'), RemoteSrcPrefix);
1397-
const existed = remoteContents.find(item => item.key === (RemoteSrcPrefix + publishedKey).replace('//', '/'))
1398-
return existed ? (domain + `/${publishedKey.replace(/\.md$/, '.html')}`) : null
1401+
const remoteContents = await client.listFromRemote(pathName?.split('/').slice(0, -1).join('/'), RemoteSrcPrefix);
1402+
const existed = remoteContents.find(item => item.key === (RemoteSrcPrefix + pathName).replace('//', '/'))
1403+
return existed ? (domain + `${pathName.replace(/\.md$/, '.html').replace(this.settings.localWatchDir, '')}`) : null
13991404
}
14001405

14011406
async enableHostService() {

src/settings.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -515,32 +515,32 @@ export class InvioSettingTab extends PluginSettingTab {
515515

516516
// =============== Hosting Settings ======================
517517

518-
// const useHostDiv = containerEl.createEl("div");
519-
// useHostDiv.createEl("h2", { text: t('settings_host') });
520-
// new Setting(useHostDiv)
521-
// .setName(t('settings_host_switch_title'))
522-
// .setDesc(t('settings_host_switch_desc'))
523-
// .addToggle(tog => {
524-
// tog.setValue(this.plugin.settings.useHost)
525-
// .onChange(async (val) => {
526-
// this.plugin.settings.useHost = val;
527-
// await this.plugin.saveSettings();
528-
// if (this.plugin.settings.useHost) {
529-
// await this.plugin.enableHostService()
530-
// .catch(err => {
531-
// new Notice(t('settings_host_enable_error'));
532-
// })
533-
// .finally(() => {
534-
// this.hide();
535-
// this.display();
536-
// })
537-
// } else {
538-
// await this.plugin.disableHostService();
539-
// this.hide();
540-
// this.display();
541-
// }
542-
// })
543-
// })
518+
const useHostDiv = containerEl.createEl("div");
519+
useHostDiv.createEl("h2", { text: t('settings_host') });
520+
new Setting(useHostDiv)
521+
.setName(t('settings_host_switch_title'))
522+
.setDesc(t('settings_host_switch_desc'))
523+
.addToggle(tog => {
524+
tog.setValue(this.plugin.settings.useHost)
525+
.onChange(async (val) => {
526+
this.plugin.settings.useHost = val;
527+
await this.plugin.saveSettings();
528+
if (this.plugin.settings.useHost) {
529+
await this.plugin.enableHostService()
530+
.catch(err => {
531+
new Notice(t('settings_host_enable_error'));
532+
})
533+
.finally(() => {
534+
this.hide();
535+
this.display();
536+
})
537+
} else {
538+
await this.plugin.disableHostService();
539+
this.hide();
540+
this.display();
541+
}
542+
})
543+
})
544544

545545
if (this.plugin.settings.useHost) {
546546
const hostingDiv = containerEl.createEl("div", { cls: 'settings-config-section' });

0 commit comments

Comments
 (0)