Skip to content

Commit e4c8efe

Browse files
committed
feat(remoteLink): Remote link check.
1 parent 0f5a6ef commit e4c8efe

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

src/langs/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
"syncrun_alreadyrunning": "{{pluginName}} already running in stage {{syncStatus}}!",
1919
"syncrun_no_watchdir_err": "Invio: Please choose a local folder to get started!",
20+
"syncrun_no_domain_err": "Need to config custom domain",
21+
"syncrun_copy_link_msg": "Link copied to the clipboard",
22+
"syncrun_copy_link_null_msg": "Remote link not found",
2023
"syncrun_syncingribbon": "{{pluginName}}: syncing from {{triggerSource}}",
2124
"syncrun_syncingribbon_err": "{{pluginName}}: file syncing failed",
2225
"syncrun_step0": "0/{{maxSteps}} Invio running in dry mode, not actual file changes would happen.",
@@ -58,6 +61,7 @@
5861
"menu_set_folder": "Set as working folder",
5962
"menu_sync_folder": "Folder Publish",
6063
"menu_share_folder": "Share This Folder",
64+
"menu_get_link": "Get Online Link",
6165
"menu_sync_file": "File Publish",
6266

6367
"modal_password_title": "Hold on and PLEASE READ ON...",

src/langs/zh_cn.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
"syncrun_alreadyrunning": "{{pluginName}} 正处于此阶段:{{syncStatus}}!",
1919
"syncrun_no_watchdir_err": "Invio: 请先配置本地同步文件夹",
20+
"syncrun_no_domain_err": "请先配置自定义域名",
21+
"syncrun_copy_link_msg": "链接已复制到剪贴板",
22+
"syncrun_copy_link_null_msg": "线上文件未同步,请先发布",
2023
"syncrun_syncingribbon": "{{pluginName}}:正在由 {{triggerSource}} 触发运行",
2124
"syncrun_syncingribbon_err": "{{pluginName}}: 文件同步失败",
2225
"syncrun_step0": "0/{{maxSteps}} Invio 在空跑(dry run)模式,不会发生实际的文件交换。",
@@ -58,6 +61,7 @@
5861
"menu_set_folder": "设置为工作目录",
5962
"menu_sync_folder": "文件夹同步",
6063
"menu_share_folder": "分享文件夹",
64+
"menu_get_link": "在线链接",
6165
"menu_sync_file": "文件同步",
6266

6367
"modal_password_title": "稍等一下,请阅读下文:",

src/langs/zh_tw.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
"syncrun_alreadyrunning": "{{pluginName}} 正處於此階段:{{syncStatus}}!",
1919
"syncrun_no_watchdir_err": "Invio: 请先配置本地同步文件夹",
20+
"syncrun_no_domain_err": "请先配置自定义域名",
21+
"syncrun_copy_link_msg": "链接已复制到剪贴板",
22+
"syncrun_copy_link_null_msg": "线上文件未同步,请先发布",
2023
"syncrun_syncingribbon": "{{pluginName}}:正在由 {{triggerSource}} 觸發執行",
2124
"syncrun_syncingribbon_err": "{{pluginName}}: 文件同步失败",
2225
"syncrun_step0": "0/{{maxSteps}} Invio 在空跑(dry run)模式,不會發生實際的檔案交換。",
@@ -68,6 +71,7 @@
6871
"menu_set_folder": "设置为工作目录",
6972
"menu_sync_folder": "文件夹同步",
7073
"menu_share_folder": "分享文件夹",
74+
"menu_get_link": "在线链接",
7175
"menu_sync_file": "文件同步",
7276

7377
"modal_remotebasedir_title": "您正在修改遠端基資料夾設定",

src/main.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,25 @@ export default class InvioPlugin extends Plugin {
923923
await this.syncRun('manual', [file.path])
924924
});
925925
})
926+
.addItem((item) => {
927+
item
928+
.setTitle(`${Menu_Tab}${t('menu_get_link')}`)
929+
.setIcon("document")
930+
.onClick(async () => {
931+
const filePath = file.path;
932+
const link = await this.getRemoteLink(filePath);
933+
if (link) {
934+
await navigator.clipboard.writeText(link);
935+
new Notice(
936+
this.t("syncrun_copy_link_msg")
937+
);
938+
} else {
939+
new Notice(
940+
this.t("syncrun_copy_link_null_msg")
941+
);
942+
}
943+
});
944+
})
926945
}
927946
})
928947
);
@@ -1173,12 +1192,37 @@ export default class InvioPlugin extends Plugin {
11731192
const slug = this.settings.hostConfig?.hostPair.slug;
11741193
domain = `https://${slug}.${ServerDomain}`;
11751194
} else {
1195+
if (!this.settings.s3.s3BucketName) return '';
11761196
domain = `https://${this.settings.s3.s3BucketName}.${this.settings.s3.s3Endpoint}`;
11771197
}
11781198
}
11791199
return domain;
11801200
}
11811201

1202+
async getRemoteLink(pathName: string) {
1203+
const domain = this.getRemoteDomain();
1204+
if (!domain) {
1205+
new Notice(
1206+
this.t("syncrun_no_domain_err")
1207+
);
1208+
return;
1209+
}
1210+
// TODO: Get remote link, but need remote domain first
1211+
const client = new RemoteClient(
1212+
this.settings.serviceType,
1213+
this.settings.s3,
1214+
this.settings.hostConfig,
1215+
this.settings.useHost,
1216+
this.settings.localWatchDir,
1217+
this.app.vault.getName(),
1218+
);
1219+
const publishedKey = client.getUseHostSlugPath(pathName)
1220+
// Check remote link
1221+
const remoteContents = await client.listFromRemote(publishedKey?.split('/').slice(0, -1).join('/'), RemoteSrcPrefix);
1222+
const existed = remoteContents.find(item => item.key === (RemoteSrcPrefix + publishedKey).replace('//', '/'))
1223+
return existed ? (domain + `/${publishedKey.replace(/\.md$/, '.html')}`) : null
1224+
}
1225+
11821226
async enableHostService() {
11831227
if (!this.settings.localWatchDir) {
11841228
new Notice(this.t('syncrun_no_watchdir_err'));

0 commit comments

Comments
 (0)