MCPcopy Create free account
hub / github.com/tiann/hapi / registerGeneratedImage

Function registerGeneratedImage

cli/src/modules/common/generatedImages.ts:62–86  ·  view source on GitHub ↗
(args: { id: string; path: string; mimeType: string; bytes: Uint8Array; fileName?: string | null })

Source from the content-addressed store, hash-verified

60}
61
62export function registerGeneratedImage(args: { id: string; path: string; mimeType: string; bytes: Uint8Array; fileName?: string | null }): GeneratedImageMetadata {
63 const content = Buffer.from(args.bytes)
64 if (content.byteLength > MAX_GENERATED_IMAGE_BYTES) {
65 throw new Error('Image is too large to display inline')
66 }
67
68 const previous = generatedImages.get(args.id)
69 if (previous) {
70 generatedImageBytes -= previous.content.byteLength
71 }
72
73 const metadata: GeneratedImageMetadata = {
74 id: args.id,
75 fileName: args.fileName || basename(args.path) || `${args.id}.png`,
76 content,
77 mimeType: args.mimeType,
78 createdAt: Date.now()
79 }
80 generatedImages.set(args.id, metadata)
81 generatedImageBytes += content.byteLength
82
83 evictOldGeneratedImages()
84
85 return metadata
86}
87
88function evictOldGeneratedImages(): void {
89 while (generatedImages.size > MAX_GENERATED_IMAGE_COUNT || generatedImageBytes > MAX_GENERATED_IMAGE_TOTAL_BYTES) {

Callers 3

startHappyServerFunction · 0.90

Calls 3

basenameFunction · 0.90
evictOldGeneratedImagesFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected