@wenyan-md/core 1.0.9 → 1.0.11
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/dist/browser/wenyan-core.js +42 -42
- package/dist/core.js +202 -204
- package/dist/publish.js +130 -118
- package/dist/types/wechatApi.d.ts +8 -0
- package/package.json +3 -2
package/dist/publish.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { JSDOM as W } from "jsdom";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
2
|
+
import { createReadStream as L } from "fs";
|
|
3
|
+
import { stat as F } from "fs/promises";
|
|
4
|
+
import b, { basename as N } from "path";
|
|
5
|
+
import { FormData as j, Blob as R } from "formdata-node";
|
|
6
6
|
var I = (t, e, r) => {
|
|
7
7
|
if (!e.has(t))
|
|
8
8
|
throw TypeError("Cannot " + r);
|
|
9
|
-
},
|
|
9
|
+
}, l = (t, e, r) => (I(t, e, "read from private field"), r ? r.call(t) : e.get(t)), p = (t, e, r) => {
|
|
10
10
|
if (e.has(t))
|
|
11
11
|
throw TypeError("Cannot add the same private member more than once");
|
|
12
12
|
e instanceof WeakSet ? e.add(t) : e.set(t, r);
|
|
13
|
-
},
|
|
14
|
-
async function*
|
|
15
|
-
if (t.byteLength <=
|
|
13
|
+
}, y = (t, e, r, a) => (I(t, e, "write to private field"), e.set(t, r), r), P = (t) => typeof t == "object" && t != null && !Array.isArray(t), h = (t) => typeof t == "function", C = (t) => P(t) && h(t[Symbol.asyncIterator]), T = 65536;
|
|
14
|
+
async function* z(t) {
|
|
15
|
+
if (t.byteLength <= T) {
|
|
16
16
|
yield t;
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
let e = 0;
|
|
20
20
|
for (; e < t.byteLength; ) {
|
|
21
|
-
const r = Math.min(t.byteLength - e,
|
|
21
|
+
const r = Math.min(t.byteLength - e, T), a = t.buffer.slice(e, e + r);
|
|
22
22
|
e += a.byteLength, yield new Uint8Array(a);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
async function*
|
|
25
|
+
async function* D(t) {
|
|
26
26
|
const e = t.getReader();
|
|
27
27
|
for (; ; ) {
|
|
28
28
|
const { done: r, value: a } = await e.read();
|
|
@@ -31,51 +31,51 @@ async function* C(t) {
|
|
|
31
31
|
yield a;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
async function*
|
|
34
|
+
async function* x(t) {
|
|
35
35
|
for await (const e of t)
|
|
36
|
-
yield*
|
|
36
|
+
yield* z(e);
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
if (
|
|
40
|
-
return
|
|
38
|
+
var H = (t) => {
|
|
39
|
+
if (C(t))
|
|
40
|
+
return x(t);
|
|
41
41
|
if (h(t.getReader))
|
|
42
|
-
return
|
|
42
|
+
return x(D(t));
|
|
43
43
|
throw new TypeError(
|
|
44
44
|
"Unsupported data source: Expected either ReadableStream or async iterable."
|
|
45
45
|
);
|
|
46
46
|
};
|
|
47
|
-
async function*
|
|
47
|
+
async function* O(t) {
|
|
48
48
|
let e = 0;
|
|
49
49
|
for (; e !== t.size; ) {
|
|
50
50
|
const a = await t.slice(
|
|
51
51
|
e,
|
|
52
|
-
Math.min(t.size, e +
|
|
52
|
+
Math.min(t.size, e + T)
|
|
53
53
|
).arrayBuffer();
|
|
54
54
|
e += a.byteLength, yield new Uint8Array(a);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
async function* S(t, e = !1) {
|
|
58
58
|
for (const r of t)
|
|
59
|
-
ArrayBuffer.isView(r) ? e ? yield*
|
|
59
|
+
ArrayBuffer.isView(r) ? e ? yield* z(r) : yield r : h(r.stream) ? yield* H(r.stream()) : yield* O(r);
|
|
60
60
|
}
|
|
61
|
-
function*
|
|
61
|
+
function* U(t, e, r = 0, a) {
|
|
62
62
|
a ??= e;
|
|
63
63
|
let n = r < 0 ? Math.max(e + r, 0) : Math.min(r, e), i = a < 0 ? Math.max(e + a, 0) : Math.min(a, e);
|
|
64
64
|
const s = Math.max(i - n, 0);
|
|
65
65
|
let o = 0;
|
|
66
|
-
for (const
|
|
66
|
+
for (const c of t) {
|
|
67
67
|
if (o >= s)
|
|
68
68
|
break;
|
|
69
|
-
const
|
|
70
|
-
if (n &&
|
|
71
|
-
n -=
|
|
69
|
+
const f = ArrayBuffer.isView(c) ? c.byteLength : c.size;
|
|
70
|
+
if (n && f <= n)
|
|
71
|
+
n -= f, i -= f;
|
|
72
72
|
else {
|
|
73
|
-
let
|
|
74
|
-
ArrayBuffer.isView(
|
|
73
|
+
let d;
|
|
74
|
+
ArrayBuffer.isView(c) ? (d = c.subarray(n, Math.min(f, i)), o += d.byteLength) : (d = c.slice(n, Math.min(f, i)), o += d.size), i -= f, n = 0, yield d;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
var u, _, g,
|
|
78
|
+
var u, _, g, V = class v {
|
|
79
79
|
/**
|
|
80
80
|
* Returns a new [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object.
|
|
81
81
|
* The content of the blob consists of the concatenation of the values given in the parameter array.
|
|
@@ -102,10 +102,10 @@ var u, _, g, O = class A {
|
|
|
102
102
|
ArrayBuffer.isView(i) ? s = new Uint8Array(i.buffer.slice(
|
|
103
103
|
i.byteOffset,
|
|
104
104
|
i.byteOffset + i.byteLength
|
|
105
|
-
)) : i instanceof ArrayBuffer ? s = new Uint8Array(i.slice(0)) : i instanceof
|
|
105
|
+
)) : i instanceof ArrayBuffer ? s = new Uint8Array(i.slice(0)) : i instanceof v ? s = i : s = a.encode(String(i)), y(this, g, l(this, g) + (ArrayBuffer.isView(s) ? s.byteLength : s.size)), l(this, u).push(s);
|
|
106
106
|
}
|
|
107
107
|
const n = r.type === void 0 ? "" : String(r.type);
|
|
108
|
-
|
|
108
|
+
y(this, _, /^[\x20-\x7E]*$/.test(n) ? n : "");
|
|
109
109
|
}
|
|
110
110
|
static [Symbol.hasInstance](e) {
|
|
111
111
|
return !!(e && typeof e == "object" && h(e.constructor) && (h(e.stream) || h(e.arrayBuffer)) && /^(Blob|File)$/.test(e[Symbol.toStringTag]));
|
|
@@ -114,13 +114,13 @@ var u, _, g, O = class A {
|
|
|
114
114
|
* Returns the [`MIME type`](https://developer.mozilla.org/en-US/docs/Glossary/MIME_type) of the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File).
|
|
115
115
|
*/
|
|
116
116
|
get type() {
|
|
117
|
-
return
|
|
117
|
+
return l(this, _);
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Returns the size of the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) in bytes.
|
|
121
121
|
*/
|
|
122
122
|
get size() {
|
|
123
|
-
return
|
|
123
|
+
return l(this, g);
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
126
|
* Creates and returns a new [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object which contains data from a subset of the blob on which it's called.
|
|
@@ -130,7 +130,7 @@ var u, _, g, O = class A {
|
|
|
130
130
|
* @param contentType The content type to assign to the new Blob; this will be the value of its type property. The default value is an empty string.
|
|
131
131
|
*/
|
|
132
132
|
slice(e, r, a) {
|
|
133
|
-
return new
|
|
133
|
+
return new v(U(l(this, u), this.size, e, r), {
|
|
134
134
|
type: a
|
|
135
135
|
});
|
|
136
136
|
}
|
|
@@ -140,7 +140,7 @@ var u, _, g, O = class A {
|
|
|
140
140
|
async text() {
|
|
141
141
|
const e = new TextDecoder();
|
|
142
142
|
let r = "";
|
|
143
|
-
for await (const a of S(
|
|
143
|
+
for await (const a of S(l(this, u)))
|
|
144
144
|
r += e.decode(a, { stream: !0 });
|
|
145
145
|
return r += e.decode(), r;
|
|
146
146
|
}
|
|
@@ -150,7 +150,7 @@ var u, _, g, O = class A {
|
|
|
150
150
|
async arrayBuffer() {
|
|
151
151
|
const e = new Uint8Array(this.size);
|
|
152
152
|
let r = 0;
|
|
153
|
-
for await (const a of S(
|
|
153
|
+
for await (const a of S(l(this, u)))
|
|
154
154
|
e.set(a, r), r += a.length;
|
|
155
155
|
return e.buffer;
|
|
156
156
|
}
|
|
@@ -158,7 +158,7 @@ var u, _, g, O = class A {
|
|
|
158
158
|
* Returns a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) which upon reading returns the data contained within the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
|
|
159
159
|
*/
|
|
160
160
|
stream() {
|
|
161
|
-
const e = S(
|
|
161
|
+
const e = S(l(this, u), !0);
|
|
162
162
|
return new ReadableStream({
|
|
163
163
|
async pull(r) {
|
|
164
164
|
const { value: a, done: n } = await e.next();
|
|
@@ -178,8 +178,8 @@ var u, _, g, O = class A {
|
|
|
178
178
|
u = /* @__PURE__ */ new WeakMap();
|
|
179
179
|
_ = /* @__PURE__ */ new WeakMap();
|
|
180
180
|
g = /* @__PURE__ */ new WeakMap();
|
|
181
|
-
var
|
|
182
|
-
Object.defineProperties(
|
|
181
|
+
var A = V;
|
|
182
|
+
Object.defineProperties(A.prototype, {
|
|
183
183
|
type: { enumerable: !0 },
|
|
184
184
|
size: { enumerable: !0 },
|
|
185
185
|
slice: { enumerable: !0 },
|
|
@@ -187,7 +187,7 @@ Object.defineProperties(T.prototype, {
|
|
|
187
187
|
text: { enumerable: !0 },
|
|
188
188
|
arrayBuffer: { enumerable: !0 }
|
|
189
189
|
});
|
|
190
|
-
var
|
|
190
|
+
var k, M, G = class extends A {
|
|
191
191
|
/**
|
|
192
192
|
* Creates a new File instance.
|
|
193
193
|
*
|
|
@@ -196,22 +196,22 @@ var M, k, V = class extends T {
|
|
|
196
196
|
* @param options An options object containing optional attributes for the file.
|
|
197
197
|
*/
|
|
198
198
|
constructor(t, e, r = {}) {
|
|
199
|
-
if (super(t, r), p(this,
|
|
199
|
+
if (super(t, r), p(this, k, void 0), p(this, M, 0), arguments.length < 2)
|
|
200
200
|
throw new TypeError(
|
|
201
201
|
`Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`
|
|
202
202
|
);
|
|
203
|
-
|
|
203
|
+
y(this, k, String(e));
|
|
204
204
|
const a = r.lastModified === void 0 ? Date.now() : Number(r.lastModified);
|
|
205
|
-
Number.isNaN(a) ||
|
|
205
|
+
Number.isNaN(a) || y(this, M, a);
|
|
206
206
|
}
|
|
207
207
|
static [Symbol.hasInstance](t) {
|
|
208
|
-
return t instanceof
|
|
208
|
+
return t instanceof A && t[Symbol.toStringTag] === "File" && typeof t.name == "string";
|
|
209
209
|
}
|
|
210
210
|
/**
|
|
211
211
|
* Name of the file referenced by the File object.
|
|
212
212
|
*/
|
|
213
213
|
get name() {
|
|
214
|
-
return
|
|
214
|
+
return l(this, k);
|
|
215
215
|
}
|
|
216
216
|
/* c8 ignore next 3 */
|
|
217
217
|
get webkitRelativePath() {
|
|
@@ -221,36 +221,36 @@ var M, k, V = class extends T {
|
|
|
221
221
|
* The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
|
|
222
222
|
*/
|
|
223
223
|
get lastModified() {
|
|
224
|
-
return
|
|
224
|
+
return l(this, M);
|
|
225
225
|
}
|
|
226
226
|
get [Symbol.toStringTag]() {
|
|
227
227
|
return "File";
|
|
228
228
|
}
|
|
229
229
|
};
|
|
230
|
-
M = /* @__PURE__ */ new WeakMap();
|
|
231
230
|
k = /* @__PURE__ */ new WeakMap();
|
|
232
|
-
|
|
231
|
+
M = /* @__PURE__ */ new WeakMap();
|
|
232
|
+
var m, w, J = class q {
|
|
233
233
|
constructor(e) {
|
|
234
|
-
p(this, m, void 0), p(this,
|
|
234
|
+
p(this, m, void 0), p(this, w, void 0), y(this, m, e.path), y(this, w, e.start || 0), this.name = N(l(this, m)), this.size = e.size, this.lastModified = e.lastModified;
|
|
235
235
|
}
|
|
236
236
|
slice(e, r) {
|
|
237
|
-
return new
|
|
238
|
-
path:
|
|
237
|
+
return new q({
|
|
238
|
+
path: l(this, m),
|
|
239
239
|
lastModified: this.lastModified,
|
|
240
|
-
start:
|
|
240
|
+
start: l(this, w) + e,
|
|
241
241
|
size: r - e
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
async *stream() {
|
|
245
|
-
const { mtimeMs: e } = await
|
|
245
|
+
const { mtimeMs: e } = await F(l(this, m));
|
|
246
246
|
if (e > this.lastModified)
|
|
247
247
|
throw new DOMException(
|
|
248
248
|
"The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.",
|
|
249
249
|
"NotReadableError"
|
|
250
250
|
);
|
|
251
|
-
this.size && (yield*
|
|
252
|
-
start:
|
|
253
|
-
end:
|
|
251
|
+
this.size && (yield* L(l(this, m), {
|
|
252
|
+
start: l(this, w),
|
|
253
|
+
end: l(this, w) + this.size - 1
|
|
254
254
|
}));
|
|
255
255
|
}
|
|
256
256
|
get [Symbol.toStringTag]() {
|
|
@@ -258,102 +258,114 @@ var m, y, J = class P {
|
|
|
258
258
|
}
|
|
259
259
|
};
|
|
260
260
|
m = /* @__PURE__ */ new WeakMap();
|
|
261
|
-
|
|
262
|
-
var
|
|
263
|
-
function
|
|
261
|
+
w = /* @__PURE__ */ new WeakMap();
|
|
262
|
+
var K = J;
|
|
263
|
+
function X(t, { mtimeMs: e, size: r }, a, n = {}) {
|
|
264
264
|
let i;
|
|
265
|
-
|
|
266
|
-
const s = new
|
|
267
|
-
return i || (i = s.name), new
|
|
265
|
+
P(a) ? [n, i] = [a, void 0] : i = a;
|
|
266
|
+
const s = new K({ path: t, size: r, lastModified: e });
|
|
267
|
+
return i || (i = s.name), new G([s], i, {
|
|
268
268
|
...n,
|
|
269
269
|
lastModified: s.lastModified
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
|
-
async function
|
|
273
|
-
const a = await
|
|
274
|
-
return
|
|
272
|
+
async function Z(t, e, r) {
|
|
273
|
+
const a = await F(t);
|
|
274
|
+
return X(t, a, e, r);
|
|
275
275
|
}
|
|
276
276
|
/*! Based on fetch-blob. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> & David Frank */
|
|
277
|
-
const
|
|
278
|
-
async function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
throw e.errcode ? new Error(`获取 Access Token 失败,错误码:${e.errcode},${e.errmsg}`) : new Error(`获取 Access Token 失败: ${e}`);
|
|
284
|
-
} catch (t) {
|
|
285
|
-
throw t;
|
|
277
|
+
const Q = "https://api.weixin.qq.com/cgi-bin/token", Y = "https://api.weixin.qq.com/cgi-bin/draft/add", ee = "https://api.weixin.qq.com/cgi-bin/material/add_material", te = process.env.WECHAT_APP_ID || "", re = process.env.WECHAT_APP_SECRET || "";
|
|
278
|
+
async function ae() {
|
|
279
|
+
const t = await fetch(`${Q}?grant_type=client_credential&appid=${te}&secret=${re}`);
|
|
280
|
+
if (!t.ok) {
|
|
281
|
+
const e = await t.text();
|
|
282
|
+
throw new Error(`获取AccessToken失败: ${t.status} ${e}`);
|
|
286
283
|
}
|
|
284
|
+
return await t.json();
|
|
287
285
|
}
|
|
288
|
-
async function
|
|
289
|
-
const n = new
|
|
286
|
+
async function ie(t, e, r, a) {
|
|
287
|
+
const n = new j();
|
|
290
288
|
n.append("media", e, r);
|
|
291
|
-
const i = await fetch(`${
|
|
289
|
+
const i = await fetch(`${ee}?access_token=${a}&type=${t}`, {
|
|
292
290
|
method: "POST",
|
|
293
291
|
body: n
|
|
294
292
|
});
|
|
295
293
|
if (!i.ok) {
|
|
296
|
-
const
|
|
297
|
-
throw new Error(
|
|
294
|
+
const o = await i.text();
|
|
295
|
+
throw new Error(`上传素材失败: ${i.status} ${o}`);
|
|
298
296
|
}
|
|
299
297
|
const s = await i.json();
|
|
300
|
-
|
|
301
|
-
throw new Error(`上传失败,错误码:${s.errcode},错误信息:${s.errmsg}`);
|
|
302
|
-
const o = s.url.replace("http://", "https://");
|
|
303
|
-
return s.url = o, s;
|
|
298
|
+
return s.url && s.url.startsWith("http://") && (s.url = s.url.replace("http://", "https://")), s;
|
|
304
299
|
}
|
|
300
|
+
async function se(t, e, r, a) {
|
|
301
|
+
const n = await fetch(`${Y}?access_token=${a}`, {
|
|
302
|
+
method: "POST",
|
|
303
|
+
body: JSON.stringify({
|
|
304
|
+
articles: [
|
|
305
|
+
{
|
|
306
|
+
title: t,
|
|
307
|
+
content: e,
|
|
308
|
+
thumb_media_id: r
|
|
309
|
+
}
|
|
310
|
+
]
|
|
311
|
+
})
|
|
312
|
+
});
|
|
313
|
+
if (!n.ok) {
|
|
314
|
+
const i = await n.text();
|
|
315
|
+
throw new Error(`发布失败: ${n.status} ${i}`);
|
|
316
|
+
}
|
|
317
|
+
return await n.json();
|
|
318
|
+
}
|
|
319
|
+
const B = process.env.HOST_IMAGE_PATH || "", ne = "/mnt/host-downloads";
|
|
305
320
|
async function E(t, e, r) {
|
|
321
|
+
let a, n;
|
|
306
322
|
if (t.startsWith("http")) {
|
|
307
|
-
const
|
|
308
|
-
if (!
|
|
323
|
+
const s = await fetch(t);
|
|
324
|
+
if (!s.ok || !s.body)
|
|
309
325
|
throw new Error(`Failed to download image from URL: ${t}`);
|
|
310
|
-
const
|
|
311
|
-
|
|
326
|
+
const o = b.basename(t.split("?")[0]), c = b.extname(o);
|
|
327
|
+
n = r ?? (c === "" ? `${o}.jpg` : o);
|
|
328
|
+
const f = await s.arrayBuffer();
|
|
329
|
+
a = new R([f]);
|
|
312
330
|
} else {
|
|
313
|
-
const
|
|
314
|
-
|
|
331
|
+
const s = B ? t.replace(B, ne) : t, o = b.basename(s), c = b.extname(o);
|
|
332
|
+
n = r ?? (c === "" ? `${o}.jpg` : o), a = await Z(t);
|
|
315
333
|
}
|
|
334
|
+
const i = await ie("image", a, n, e);
|
|
335
|
+
if (i.errcode)
|
|
336
|
+
throw new Error(`上传失败,错误码:${i.errcode},错误信息:${i.errmsg}`);
|
|
337
|
+
return i;
|
|
316
338
|
}
|
|
317
|
-
async function
|
|
339
|
+
async function oe(t, e) {
|
|
318
340
|
if (!t.includes("<img"))
|
|
319
341
|
return { html: t, firstImageId: "" };
|
|
320
|
-
const r = new W(t), a = r.window.document, i = Array.from(a.querySelectorAll("img")).map(async (
|
|
321
|
-
const
|
|
322
|
-
if (
|
|
323
|
-
if (
|
|
324
|
-
return
|
|
342
|
+
const r = new W(t), a = r.window.document, i = Array.from(a.querySelectorAll("img")).map(async (f) => {
|
|
343
|
+
const d = f.getAttribute("src");
|
|
344
|
+
if (d) {
|
|
345
|
+
if (d.startsWith("https://mmbiz.qpic.cn"))
|
|
346
|
+
return d;
|
|
325
347
|
{
|
|
326
|
-
const
|
|
327
|
-
return
|
|
348
|
+
const $ = await E(d, e);
|
|
349
|
+
return f.setAttribute("src", $.url), $.media_id;
|
|
328
350
|
}
|
|
329
351
|
}
|
|
330
352
|
return null;
|
|
331
353
|
}), o = (await Promise.all(i)).filter(Boolean)[0] || "";
|
|
332
354
|
return { html: r.serialize(), firstImageId: o };
|
|
333
355
|
}
|
|
334
|
-
async function
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
thumb_media_id: o
|
|
347
|
-
}]
|
|
348
|
-
})
|
|
349
|
-
})).json();
|
|
350
|
-
if (l.media_id)
|
|
351
|
-
return l;
|
|
352
|
-
throw l.errcode ? new Error(`上传到公众号草稿失败,错误码:${l.errcode},${l.errmsg}`) : new Error(`上传到公众号草稿失败: ${l}`);
|
|
353
|
-
} catch (a) {
|
|
354
|
-
throw a;
|
|
355
|
-
}
|
|
356
|
+
async function ue(t, e, r) {
|
|
357
|
+
const a = await ae();
|
|
358
|
+
if (!a.access_token)
|
|
359
|
+
throw a.errcode ? new Error(`获取 Access Token 失败,错误码:${a.errcode},${a.errmsg}`) : new Error(`获取 Access Token 失败: ${a}`);
|
|
360
|
+
const n = e.replace(/\n<li/g, "<li").replace(/<\/li>\n/g, "</li>"), { html: i, firstImageId: s } = await oe(n, a.access_token);
|
|
361
|
+
let o = "";
|
|
362
|
+
if (r ? o = (await E(r, a.access_token, "cover.jpg")).media_id : s.startsWith("https://mmbiz.qpic.cn") ? o = (await E(s, a.access_token, "cover.jpg")).media_id : o = s, !o)
|
|
363
|
+
throw new Error("你必须指定一张封面图或者在正文中至少出现一张图片。");
|
|
364
|
+
const c = await se(t, i, o, a.access_token);
|
|
365
|
+
if (c.media_id)
|
|
366
|
+
return c;
|
|
367
|
+
throw c.errcode ? new Error(`上传到公众号草稿失败,错误码:${c.errcode},${c.errmsg}`) : new Error(`上传到公众号草稿失败: ${c}`);
|
|
356
368
|
}
|
|
357
369
|
export {
|
|
358
|
-
|
|
370
|
+
ue as publishToDraft
|
|
359
371
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { File, Blob } from "formdata-node";
|
|
2
|
+
export type UploadResponse = {
|
|
3
|
+
media_id: string;
|
|
4
|
+
url: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function fetchAccessToken(): Promise<any>;
|
|
7
|
+
export declare function uploadMaterial(type: string, fileData: Blob | File, fileName: string, accessToken: string): Promise<any>;
|
|
8
|
+
export declare function publishArticle(title: string, content: string, thumbMediaId: string, accessToken: string): Promise<any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wenyan-md/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "Core library for Wenyan markdown rendering & publishing",
|
|
5
5
|
"author": "Lei <caol64@gmail.com> (https://github.com/caol64)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"build:all": "pnpm build && pnpm build:browser && pnpm build:styles && pnpm build:math",
|
|
75
75
|
"test:main": "pnpm build && vitest run main.test.js",
|
|
76
76
|
"test:wrapper": "pnpm build && vitest run wrapper.test.js",
|
|
77
|
-
"test:publish": "pnpm build && vitest run publish.test.js"
|
|
77
|
+
"test:publish": "pnpm build && vitest run test/publish.test.js",
|
|
78
|
+
"test:realPublish": "pnpm build && vitest run test/realPublish.test.js"
|
|
78
79
|
}
|
|
79
80
|
}
|