Lines 5-45javascript
5import sharp from "sharp";
6import { DirectApiClient, DirectApiError, unwrapEnvelope } from "./direct-client.js";
7import { isDebug, isVerbose } from "../utils/config.js";
8import { assertSafeUploadPath } from "../utils/sensitive-path.js";
9import { assertSafeHttpUrl } from "../utils/url-safety.js";
10import { redactSensitiveText } from "../utils/redact.js";
11const ANALYSIS_STATUS = {
18const DEFAULT_ANALYSIS_TIMEOUT_MS = 180_000;
19const DEFAULT_ANALYSIS_INTERVAL_MS = 3_000;
20export class DamClient {
22 constructor(client = new DirectApiClient()) {
25 async createAssetId() {
26 const response = await this.client.post("/tb-dam/asset/id");
27 const data = unwrapEnvelope(response);
29 throw new Error("创建 DAM content_id 失败:接口没有返回 id");
33 async uploadLocalAsset(file, options = {}) {
34 const filePath = assertSafeUploadPath(resolve(process.cwd(), file), {
35 allowSensitivePath: options.allowSensitivePath,
LowWeak Crypto
Package source references weak cryptographic algorithms.
dist/src/api/dam-client.jsView on unpkg · L25 38 await access(filePath);
39 const fileBuffer = await readFile(filePath);
40 const format = inferFormat(filePath, fileBuffer);
41 const mimeType = inferMimeType(format);
42 const fileStat = await stat(filePath);
43 const contentId = options.register ? await this.createAssetId() : undefined;
44 const token = await this.createUploadToken(format, contentId);
45 await putObjectWithFallback(token, filePath, mimeType);