Add Webhook material pack import
This commit is contained in:
1 parent
1299d70777
commit
77ae7d4dca
17 files changed
+667
-4
No files matched your search
@@ -1,6 +1,10 @@
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
import type { createSealClient } from "../../core/http/factory.js";
|
||||
import { existsSync } from "node:fs";
|
||||
import { runTool } from "../helpers.js";
|
||||
import * as api from "../../domains/seal/api.js";
|
||||
import { findWebhookIntegration } from "../../domains/seal/api.js";
|
||||
import { previewMaterialPack, pushMaterialPack, readMaterialPackFile } from "../../domains/seal/material-pack/index.js";
|
||||
import {
|
||||
booleanOption,
|
||||
parseWebhookMode,
|
||||
@@ -11,6 +15,12 @@ import {
|
||||
import { outputOptions } from "../printer.js";
|
||||
import type { ParsedArgs } from "../types.js";
|
||||
|
||||
export async function handleWebhookMaterialPackPreview(filePath: string) {
|
||||
if (!existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
|
||||
const input = readMaterialPackFile(filePath);
|
||||
console.log(JSON.stringify(await previewMaterialPack(input.fileBuffer, input.fileName), null, 2));
|
||||
}
|
||||
|
||||
export async function handleWebhookCommand(
|
||||
action: string | undefined,
|
||||
maybeName: string | undefined,
|
||||
@@ -18,6 +28,29 @@ export async function handleWebhookCommand(
|
||||
corp: CorpConfig,
|
||||
args: ParsedArgs
|
||||
) {
|
||||
if (action === "material-pack" || action === "material-pack-push") {
|
||||
const operation = action === "material-pack-push" ? "push" : maybeName;
|
||||
const filePath = action === "material-pack-push"
|
||||
? stringOption(args.options.file) ?? stringOption(args.options.input)
|
||||
: args.command[3] ?? stringOption(args.options.file) ?? stringOption(args.options.input);
|
||||
if (!filePath) throw new Error("Usage: seal-use webhook material-pack <preview|push> <材料包.zip>");
|
||||
if (!existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
|
||||
const input = readMaterialPackFile(filePath);
|
||||
if (operation === "preview") {
|
||||
console.log(JSON.stringify(await previewMaterialPack(input.fileBuffer, input.fileName), null, 2));
|
||||
return;
|
||||
}
|
||||
if (operation !== "push") throw new Error("Usage: seal-use webhook material-pack <preview|push> <材料包.zip>");
|
||||
const selector = stringOption(args.options.webhook) ?? stringOption(args.options.selector);
|
||||
if (!selector) throw new Error("Push requires --webhook <idOrName>");
|
||||
const integration = findWebhookIntegration(await api.listWebhookIntegrations(client), selector);
|
||||
const result = await pushMaterialPack(input.fileBuffer, input.fileName, {
|
||||
webhookUrl: integration.incomingDocumentWebhook.url,
|
||||
secret: integration.secret
|
||||
});
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
}
|
||||
if (action === "list") {
|
||||
await runTool(
|
||||
"seal_webhook_list",
|
||||
|
||||
@@ -121,6 +121,8 @@ Usage:
|
||||
seal-use webhook add --name <name> --result-url <url> [--mode assisted|semi_automatic|fully_automatic] [--auto-approval-rate 60] [--secret <secret>] [--corp <corpId>]
|
||||
seal-use webhook update <idOrName> [--name <name>] [--result-url <url>] [--mode assisted|semi_automatic|fully_automatic] [--auto-approval-rate 60] [--secret <secret>|--rotate-secret] [--corp <corpId>]
|
||||
seal-use webhook delete <idOrName> --yes [--corp <corpId>]
|
||||
seal-use webhook material-pack preview <材料包.zip|信息表.xlsx> [--corp <corpId>]
|
||||
seal-use webhook material-pack push <材料包.zip|信息表.xlsx> --webhook <idOrName> [--corp <corpId>]
|
||||
seal-use deploy hosecloud requirements [--corp <corpId>]
|
||||
seal-use deploy hosecloud list [--corp <corpId>]
|
||||
seal-use deploy hosecloud get <sign-key> [--corp <corpId>]
|
||||
|
||||
+8
-1
@@ -28,7 +28,7 @@ import { handleToolCommand } from "./commands/tool.js";
|
||||
import { handleToolsListCommand } from "./commands/tools.js";
|
||||
import { handleUpdateCommand } from "./commands/update.js";
|
||||
import { handleUsersCommand } from "./commands/users.js";
|
||||
import { handleWebhookCommand } from "./commands/webhook.js";
|
||||
import { handleWebhookCommand, handleWebhookMaterialPackPreview } from "./commands/webhook.js";
|
||||
import { selectCorp } from "./helpers.js";
|
||||
import { booleanOption, numberOption, parseArgs, stringOption } from "./parser.js";
|
||||
import {
|
||||
@@ -155,6 +155,13 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
|
||||
throw new Error(`Unknown command: ${args.command.join(" ")}. Run 'seal-use help' for available commands.`);
|
||||
}
|
||||
|
||||
if (area === "webhook" && action === "material-pack" && maybeName === "preview") {
|
||||
const filePath = args.command[3] ?? stringOption(args.options.file) ?? stringOption(args.options.input);
|
||||
if (!filePath) throw new Error("Usage: seal-use webhook material-pack preview <材料包.zip>");
|
||||
await handleWebhookMaterialPackPreview(filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "openapi") {
|
||||
handleOpenApiCommand(args);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user