@wenyan-md/core 2.0.7 → 3.0.0
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/README.md +2 -2
- package/dist/publish.js +114 -254
- package/dist/types/node/clientPublish.d.ts +15 -0
- package/dist/types/node/configStore.d.ts +8 -7
- package/dist/types/node/publish.d.ts +6 -10
- package/dist/types/node/render.d.ts +5 -0
- package/dist/types/node/theme.d.ts +16 -0
- package/dist/types/node/tokenStoreNodeAdapter.d.ts +7 -0
- package/dist/types/node/types.d.ts +31 -0
- package/dist/types/node/uploadCacheNodeAdapter.d.ts +8 -0
- package/dist/types/node/utils.d.ts +14 -4
- package/dist/types/node/wrapper.d.ts +8 -10
- package/dist/types/publish.d.ts +22 -0
- package/dist/types/tokenStore.d.ts +24 -0
- package/dist/types/uploadCacheStore.d.ts +27 -0
- package/dist/types/wechat.d.ts +1 -1
- package/dist/wechat.js +5 -5
- package/dist/wrapper.js +656 -6
- package/package.json +6 -12
- package/dist/configStore-lZ5bhrcC.js +0 -111
- package/dist/http.js +0 -1
- package/dist/types/node/tokenStore.d.ts +0 -18
- package/dist/types/node/uploadCacheStore.d.ts +0 -15
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface MediaInfo {
|
|
2
|
+
media_id: string;
|
|
3
|
+
url: string;
|
|
4
|
+
updated_at?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface CacheData {
|
|
7
|
+
[hash: string]: MediaInfo;
|
|
8
|
+
}
|
|
9
|
+
export interface UploadCacheStorageAdapter {
|
|
10
|
+
loadCache(): Promise<CacheData>;
|
|
11
|
+
saveCache(cache: CacheData): Promise<void>;
|
|
12
|
+
clearCache(): Promise<void>;
|
|
13
|
+
calcHash(buffer: ArrayBuffer): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
export declare class UploadCacheStore {
|
|
16
|
+
private cache;
|
|
17
|
+
private adapter;
|
|
18
|
+
private initPromise;
|
|
19
|
+
constructor(adapter: UploadCacheStorageAdapter);
|
|
20
|
+
private load;
|
|
21
|
+
private save;
|
|
22
|
+
waitForInit(): Promise<void>;
|
|
23
|
+
get(hash: string): Promise<MediaInfo | undefined>;
|
|
24
|
+
set(hash: string, mediaId: string, url: string): Promise<void>;
|
|
25
|
+
clear(): Promise<void>;
|
|
26
|
+
calcHash(buffer: ArrayBuffer): Promise<string>;
|
|
27
|
+
}
|
package/dist/types/wechat.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface WechatTokenResponse {
|
|
|
21
21
|
export interface WechatPublishResponse {
|
|
22
22
|
media_id: string;
|
|
23
23
|
}
|
|
24
|
-
export declare function createWechatClient(
|
|
24
|
+
export declare function createWechatClient(httpAdapter: HttpAdapter): {
|
|
25
25
|
fetchAccessToken(appId: string, appSecret: string): Promise<WechatTokenResponse>;
|
|
26
26
|
uploadMaterial(type: string, file: Blob, filename: string, accessToken: string): Promise<WechatUploadResponse>;
|
|
27
27
|
publishArticle(accessToken: string, options: WechatPublishOptions): Promise<WechatPublishResponse>;
|
package/dist/wechat.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const tokenUrl = "https://api.weixin.qq.com/cgi-bin/token";
|
|
2
2
|
const publishUrl = "https://api.weixin.qq.com/cgi-bin/draft/add";
|
|
3
3
|
const uploadUrl = "https://api.weixin.qq.com/cgi-bin/material/add_material";
|
|
4
|
-
function createWechatClient(
|
|
4
|
+
function createWechatClient(httpAdapter) {
|
|
5
5
|
return {
|
|
6
6
|
async fetchAccessToken(appId, appSecret) {
|
|
7
|
-
const res = await
|
|
7
|
+
const res = await httpAdapter.fetch(
|
|
8
8
|
`${tokenUrl}?grant_type=client_credential&appid=${appId}&secret=${appSecret}`
|
|
9
9
|
);
|
|
10
10
|
if (!res.ok) throw new Error(await res.text());
|
|
@@ -13,8 +13,8 @@ function createWechatClient(adapter) {
|
|
|
13
13
|
return data;
|
|
14
14
|
},
|
|
15
15
|
async uploadMaterial(type, file, filename, accessToken) {
|
|
16
|
-
const multipart =
|
|
17
|
-
const res = await
|
|
16
|
+
const multipart = httpAdapter.createMultipart("media", file, filename);
|
|
17
|
+
const res = await httpAdapter.fetch(`${uploadUrl}?access_token=${accessToken}&type=${type}`, {
|
|
18
18
|
...multipart,
|
|
19
19
|
method: "POST"
|
|
20
20
|
});
|
|
@@ -27,7 +27,7 @@ function createWechatClient(adapter) {
|
|
|
27
27
|
return data;
|
|
28
28
|
},
|
|
29
29
|
async publishArticle(accessToken, options) {
|
|
30
|
-
const res = await
|
|
30
|
+
const res = await httpAdapter.fetch(`${publishUrl}?access_token=${accessToken}`, {
|
|
31
31
|
method: "POST",
|
|
32
32
|
body: JSON.stringify({
|
|
33
33
|
articles: [options]
|