@rongyan/wxpost-cli 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/commands/add-draft.js +18 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rongyan/wxpost-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "熔岩微信公众号发布客户端",
|
|
5
5
|
"bin": {
|
|
6
6
|
"wxpost": "bin/wxpost-cli.js"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"node": ">=18"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@rongyan/mdflow-cli": "^0.1.
|
|
40
|
+
"@rongyan/mdflow-cli": "^0.1.5",
|
|
41
41
|
"imagemin": "^9.0.1",
|
|
42
42
|
"imagemin-jpegtran": "^8.0.0",
|
|
43
43
|
"imagemin-optipng": "^8.0.0"
|
|
@@ -122,6 +122,23 @@ async function maybeCompress(buffer, filename, sizeLimit, hardLimit, allowedExts
|
|
|
122
122
|
async function uploadContentImages(wxhtml, mdDir, appid) {
|
|
123
123
|
const IMG_RE = /(<img\b[^>]*?\ssrc=")([^"]+)(")/gi;
|
|
124
124
|
|
|
125
|
+
function toLocalImagePath(src) {
|
|
126
|
+
const normalizedSrc = src.startsWith('file://')
|
|
127
|
+
? new URL(src).pathname
|
|
128
|
+
: src;
|
|
129
|
+
|
|
130
|
+
let decodedSrc = normalizedSrc;
|
|
131
|
+
try {
|
|
132
|
+
decodedSrc = decodeURI(normalizedSrc);
|
|
133
|
+
} catch {
|
|
134
|
+
// Keep original src if decoding fails so we don't make the path worse.
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return path.isAbsolute(decodedSrc)
|
|
138
|
+
? decodedSrc
|
|
139
|
+
: path.resolve(mdDir, decodedSrc);
|
|
140
|
+
}
|
|
141
|
+
|
|
125
142
|
// 收集所有唯一的本地 src
|
|
126
143
|
const localSrcs = new Set();
|
|
127
144
|
for (const m of wxhtml.matchAll(IMG_RE)) {
|
|
@@ -135,7 +152,7 @@ async function uploadContentImages(wxhtml, mdDir, appid) {
|
|
|
135
152
|
// 逐一上传,建立 src → wx_url 映射
|
|
136
153
|
const urlMap = new Map();
|
|
137
154
|
for (const src of localSrcs) {
|
|
138
|
-
const absPath =
|
|
155
|
+
const absPath = toLocalImagePath(src);
|
|
139
156
|
if (!fs.existsSync(absPath)) {
|
|
140
157
|
throw new Error(`内容图不存在: ${absPath}`);
|
|
141
158
|
}
|