Skip to content

Commit 276ae47

Browse files
committed
全库笔记批量上传下载图片
1 parent 9431bbc commit 276ae47

38 files changed

Lines changed: 368 additions & 119 deletions

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "custom-image-auto-uploader",
33
"name": "Custom Image Auto Uploader",
4-
"version": "2.7.14",
4+
"version": "2.8.0",
55
"minAppVersion": "1.6.5",
66
"description": "You can batch download images from your notes on desktop, iOS, and Android platforms, and batch upload and save them to a remote server, home NAS, or cloud storage (such as Alibaba Cloud OSS, Amazon S3, Cloudflare R2, MinIO). Additionally, you can stretch, crop, and resize the images.",
77
"author": "HaierKeys",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Custom Image Auto Uploader",
3-
"version": "2.7.14",
3+
"version": "2.8.0",
44
"description": "You can upload and save images from your notes to your remote server, home NAS, or sync them to your cloud storage (Alibaba Cloud OSS, Amazon S3, Cloudflare R2).",
55
"main": "main.js",
66
"scripts": {

readme-zh.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
## ✨ 核心功能
2727

2828
* **⬇️ 批量下载**:一键将笔记内的网络图片下载至本地。
29+
* **⬇️ 多笔记批量下载**:可以一键下载整个笔记仓库所有笔记中的图片。
2930
* **☁️ 批量上传**:将本地图片上传至远端服务,支持多种存储后端:
3031
* **自建服务**:配合 [Custom Image Gateway](https://github.com/haierkeys/custom-image-gateway) 使用。
3132
* **云存储**:阿里云 OSS, Amazon S3, Cloudflare R2, MinIO 等。
3233
* **通用协议**:WebDAV, 远端服务器, 家庭 NAS。
34+
* **☁️ 多笔记批量上传**:可以一键上传整个笔记仓库所有笔记中的图片。
3335
* **✂️ 图片处理**:支持在笔记属性或正文中即时处理图片(如博客封面图):
3436
* 等比左上填充 (Cover)
3537
* 等比居中填充 (Contain)
@@ -43,7 +45,7 @@
4345

4446
我们正在持续改进,以下是未来的开发计划:
4547

46-
- [ ] **多笔记批量上传下载**:可以一键下载/上传整个笔记仓库所有笔记中的图片。
48+
4749
- [ ] **清理未连接图片**:可以一键清理笔记仓库中未和笔记连接的本地图片。
4850

4951
## 🚀 快速开始

src/lang.ts renamed to src/lang/lang.ts

Lines changed: 88 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
import { moment } from "obsidian";
2-
3-
import ar from "src/lang/locale/ar";
4-
import be from "src/lang/locale/be";
5-
import ca from "src/lang/locale/ca";
6-
import da from "src/lang/locale/da";
7-
import de from "src/lang/locale/de";
8-
import en from "src/lang/locale/en";
9-
import enGB from "src/lang/locale/en-gb";
10-
import es from "src/lang/locale/es";
11-
//import fa from "src/lang/locale/fa";
12-
import fr from "src/lang/locale/fr";
13-
import he from "src/lang/locale/he";
14-
import hu from "src/lang/locale/hu";
15-
import id from "src/lang/locale/id";
16-
import it from "src/lang/locale/it";
17-
import ja from "src/lang/locale/ja";
18-
import ko from "src/lang/locale/ko";
19-
import ms from "src/lang/locale/ms";
20-
import ne from "src/lang/locale/ne";
21-
import nl from "src/lang/locale/nl";
22-
import nb from "src/lang/locale/nb";
23-
import pl from "src/lang/locale/pl";
24-
import pt from "src/lang/locale/pt";
1+
import zhTW from "src/lang/locale/zh-tw";
2+
import zhCN from "src/lang/locale/zh-cn";
253
import ptBR from "src/lang/locale/pt-br";
26-
import ro from "src/lang/locale/ro";
27-
import ru from "src/lang/locale/ru";
28-
import sq from "src/lang/locale/sq";
29-
import th from "src/lang/locale/th";
30-
import tr from "src/lang/locale/tr";
31-
import uk from "src/lang/locale/uk";
324
import vi from "src/lang/locale/vi";
33-
import zhCN from "src/lang/locale/zh-cn";
34-
import zhTW from "src/lang/locale/zh-tw";
5+
import uk from "src/lang/locale/uk";
6+
import tr from "src/lang/locale/tr";
7+
import th from "src/lang/locale/th";
8+
import sq from "src/lang/locale/sq";
9+
import ru from "src/lang/locale/ru";
10+
import ro from "src/lang/locale/ro";
11+
import pt from "src/lang/locale/pt";
12+
import pl from "src/lang/locale/pl";
13+
import nl from "src/lang/locale/nl";
14+
import ne from "src/lang/locale/ne";
15+
import nb from "src/lang/locale/nb";
16+
import ms from "src/lang/locale/ms";
17+
import ko from "src/lang/locale/ko";
18+
import ja from "src/lang/locale/ja";
19+
import it from "src/lang/locale/it";
20+
import id from "src/lang/locale/id";
21+
import hu from "src/lang/locale/hu";
22+
import he from "src/lang/locale/he";
23+
//import fa from "src/lang/locale/fa";
24+
import fr from "src/lang/locale/fr";
25+
import es from "src/lang/locale/es";
26+
import en from "src/lang/locale/en";
27+
import de from "src/lang/locale/de";
28+
import da from "src/lang/locale/da";
29+
import ca from "src/lang/locale/ca";
30+
import be from "src/lang/locale/be";
31+
import ar from "src/lang/locale/ar";
32+
import { moment } from "obsidian";
3533

3634

37-
export interface lang {
38-
[propName: string]: any;
39-
}
35+
/**
36+
* Locale object type.
37+
* 假设每个 locale 文件都是键 => 字符串(常见情形),使用更严格的类型。
38+
*/
39+
export type LangMap = Record<string, string>;
4040

4141
export const localeMap: { [k: string]: Partial<typeof en> } = {
4242
ar,
@@ -45,7 +45,6 @@ export const localeMap: { [k: string]: Partial<typeof en> } = {
4545
da,
4646
de,
4747
en,
48-
"en-gb": enGB,
4948
es,
5049
// fa,
5150
fr,
@@ -73,18 +72,64 @@ export const localeMap: { [k: string]: Partial<typeof en> } = {
7372
"zh-tw": zhTW,
7473
};
7574

76-
const locale = localeMap[moment.locale()];
75+
const locale = localeMap[moment.locale()] as Partial<LangMap> | undefined;
76+
77+
78+
function getValueFromPath(root: Record<string, unknown>, path: string): unknown {
79+
const normalized = path
80+
.replace(/\[(?:'([^']*)'|"([^"]*)"|([^'\]"[\]]+))\]/g, (_m, g1, g2, g3) => {
81+
const key = g1 ?? g2 ?? g3;
82+
return "." + key;
83+
})
84+
.replace(/^\./, "");
85+
86+
if (normalized === "") return undefined;
87+
88+
const parts = normalized.split(".");
89+
let cur: unknown = root;
90+
for (const part of parts) {
91+
if (cur == null) return undefined;
92+
if (part === "") return undefined;
93+
if (typeof cur === "object") {
94+
cur = (cur as Record<string, unknown>)[part];
95+
} else {
96+
return undefined;
97+
}
98+
}
99+
return cur;
100+
}
101+
77102

78-
// https://stackoverflow.com/a/41015840/
79103
function interpolate(str: string, params: Record<string, unknown>): string {
80-
const names: string[] = Object.keys(params);
81-
const vals: unknown[] = Object.values(params);
82-
return new Function(...names, `return \`${str}\`;`)(...vals);
104+
if (!str || typeof str !== "string") return String(str ?? "");
105+
return str.replace(/\$\{([^}]+)\}/g, (_match, expression) => {
106+
const path = expression.trim();
107+
if (!/^[A-Za-z0-9_.[\]'"\s-]+$/.test(path)) {
108+
return "";
109+
}
110+
const val = getValueFromPath(params, path);
111+
if (val === undefined || val === null) return "";
112+
if (typeof val === "string") return val;
113+
if (typeof val === "number" || typeof val === "boolean" || typeof val === "bigint") {
114+
return String(val);
115+
}
116+
try {
117+
return JSON.stringify(val);
118+
} catch {
119+
return "";
120+
}
121+
});
83122
}
84123

85-
export function $(str: keyof typeof en, params?: Record<string, unknown>): string {
86124

87-
const result = (locale && locale[str]) || en[str];
125+
export function $(
126+
str: Extract<keyof typeof en, string>,
127+
params?: Record<string, unknown>
128+
): string {
129+
// str 的类型现在必为 string,安全用于索引
130+
const key = str;
131+
const fallback = en[key];
132+
const result = (locale && (locale[key] as string)) ?? fallback ?? key;
88133

89134
if (params) {
90135
return interpolate(result, params);

src/lang/locale/ar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { lang } from "../../lang";
1+
import { LangMap } from "../lang";
22

33

4-
export default <lang>{
4+
export default <LangMap>{
55
//main
66
"下载全部图片": "تحميل جميع الصور",
77
"上传全部图片": "رفع جميع الصور",

src/lang/locale/be.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { lang } from "../../lang";
1+
import { LangMap } from "../lang";
22

33

4-
export default <lang>{
4+
export default <LangMap>{
55
//main
66
"下载全部图片": "Спампаваць усе выявы",
77
"上传全部图片": "Загрузіць усе выявы",

src/lang/locale/ca.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { lang } from "../../lang";
1+
import { LangMap } from "../lang";
22

33

4-
export default <lang>{
4+
export default <LangMap>{
55
//main
66
"下载全部图片": "Descarregar totes les imatges",
77
"上传全部图片": "Pujar totes les imatges",

src/lang/locale/da.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { lang } from "../../lang";
1+
import { LangMap } from "../lang";
22

33

4-
export default <lang>{
4+
export default <LangMap>{
55
//main
66
"下载全部图片": "Hent alle billeder",
77
"上传全部图片": "Upload alle billeder",

src/lang/locale/de.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { lang } from "../../lang";
1+
import { LangMap } from "../lang";
22

33

4-
export default <lang>{
4+
export default <LangMap>{
55
//main
66
"下载全部图片": "Alle Bilder herunterladen",
77
"上传全部图片": "Alle Bilder hochladen",

src/lang/locale/en.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { lang } from "../../lang";
1+
import { LangMap } from "../lang";
22

33

4-
export default <lang>{
4+
export default <LangMap>{
55
"Custom Image Auto Uploader": "Custom Image Auto Uploader",
66
"已开启": "Enabled",
77
"已关闭": "Disabled",
@@ -96,4 +96,8 @@ export default <lang>{
9696
"压缩后的最大宽度,单位像素,默认1200": "The maximum width of the compressed image, in pixels, default 1200",
9797
"上传速度优化 - 最大高度": "Upload speed optimization - Maximum height",
9898
"压缩后的最大高度,单位像素,默认1200": "The maximum height of the compressed image, in pixels, default 1200",
99+
"下载当前笔记图片": "Download Current Note Images",
100+
"上传当前笔记图片": "Upload Current Note Images",
101+
"下载全库图片": "Download Whole Vault Images",
102+
"上传全库图片": "Upload Whole Vault Images",
99103
};

0 commit comments

Comments
 (0)