--- title: "@cmtx/markdown-it-presigned-url-adapter-nodejs" category: guide sidebar_order: 99 sidebar_group: "@cmtx/markdown-it-presigned-url-adapter-nodejs" lang: en --- # @cmtx/markdown-it-presigned-url-adapter-nodejs [![npm version](https://img.shields.io/npm/v/@cmtx/markdown-it-presigned-url-adapter-nodejs.svg)](https://www.npmjs.com/package/@cmtx/markdown-it-presigned-url-adapter-nodejs) Node.js adapter for `@cmtx/markdown-it-presigned-url`. Implements URL signing and cache management for OSS/COS presigned URLs. ## 1. Installation ```bash pnpm add @cmtx/markdown-it-presigned-url-adapter-nodejs ``` ## 2. Quick Start ```typescript import { createUrlSigner, createUrlCacheManager } from "@cmtx/markdown-it-presigned-url-adapter-nodejs"; import { createStorage } from "@cmtx/storage"; import MarkdownIt from "markdown-it"; import { presignedUrlPlugin } from "@cmtx/markdown-it-presigned-url"; const storage = createStorage({ provider: "ali-oss", config: { /* ... */ } }); const signer = createUrlSigner(storage); const cache = createUrlCacheManager(); const md = new MarkdownIt().use(presignedUrlPlugin, { signer, cache }); const html = md.render("![](image.png)"); ``` ## 3. API ### UrlSigner Signs image URLs with presigned URLs from the configured storage provider. ```typescript interface UrlSigner { sign(url: string): Promise; } ``` ### UrlCacheManager Manages a cache of signed URLs to avoid repeated signing requests. ```typescript interface UrlCacheManager { get(url: string): string | undefined; set(url: string, signedUrl: string, ttl?: number): void; clear(): void; } ``` ### PresignedUrlCache The underlying cache implementation with TTL support. ## 4. How It Works 1. markdown-it encounters an image URL 2. `@cmtx/markdown-it-presigned-url` intercepts it and delegates to `UrlSigner` 3. The adapter checks `UrlCacheManager` for a cached signed URL 4. If cache miss, it calls storage adapter to generate a presigned URL 5. The signed URL is cached and returned ## 5. Related Packages - [`@cmtx/markdown-it-presigned-url`](../markdown-it-presigned-url/) — markdown-it plugin - [`@cmtx/storage`](../storage/) — storage abstraction layer ## 6. Development ```bash pnpm -F @cmtx/markdown-it-presigned-url-adapter-nodejs build pnpm -F @cmtx/markdown-it-presigned-url-adapter-nodejs test ```