Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 必须使用 LF Line Sequence
WECHAT_APP_ID=123456
WECHAT_APP_SECRET=abcdef
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"lint": "eslint . --fix",
"test:bin": "pnpm build && node ./dist/cli.js render -f tests/publish.md -c tests/manhua.css --no-mac-style",
"test:realPublish": "pnpm build && node --env-file=.env.test ./dist/cli.js publish -f tests/publish.md -t phycat",
"test:serverPublish": "pnpm build && node ./dist/cli.js publish -f tests/publish.md -c tests/manhua.css --no-mac-style --server http://localhost:3000",
"test:serverPublish": "pnpm build && node --env-file=.env.test ./dist/cli.js publish -f tests/publish.md -c tests/manhua.css --no-mac-style --server http://localhost:3000",
"test:serve": "pnpm build && node --env-file=.env.test ./dist/cli.js serve"
},
"packageManager": "pnpm@10.7.1",
Expand Down
8 changes: 8 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ export function createProgram(version: string = pkg.version): Command {
addCommonOptions(pubCmd)
.option("--server <url>", "Server URL to publish through (e.g. https://api.yourdomain.com)")
.option("--api-key <apiKey>", "API key for the remote server")
.option("--app-id [id]", "WeChat ID to publish to</id>, if not specified, will use the env variable WECHAT_APP_ID")
.option("--app-secret [secret]", "WeChat Secret to publish to</secret>, if not specified, will use the env variable WECHAT_APP_SECRET")
.action(async (inputContent: string | undefined, options: ClientPublishOptions) => {
await runCommandWrapper(async () => {
// 如果传入了 --server,则走客户端(远程)模式
if (options.server) {
if(!options.appId){
options.appId = process.env.WECHAT_APP_ID;
}
if(!options.appSecret){
options.appSecret = process.env.WECHAT_APP_SECRET;
}
options.clientVersion = version; // 将 CLI 版本传递给服务器,便于调试和兼容性处理
const mediaId = await renderAndPublishToServer(inputContent, options, getInputContent);
console.log(`发布成功,Media ID: ${mediaId}`);
Expand Down
5 changes: 5 additions & 0 deletions src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface ServeOptions {
}

interface RenderRequest {
appId?: string;
appSecret?: string;
fileId: string;
theme?: string;
highlight?: string;
Expand Down Expand Up @@ -145,6 +147,9 @@ export async function serveCommand(options: ServeOptions) {
cover: gzhContent.cover,
author: gzhContent.author,
source_url: gzhContent.source_url,
},{
appId: body.appId,
appSecret: body.appSecret
});

if (data.media_id) {
Expand Down