MCPcopy Create free account
hub / github.com/CreminiAI/skillpack / saveAttachment

Function saveAttachment

src/runtime/adapters/attachment-utils.ts:36–59  ·  view source on GitHub ↗
(
  rootDir: string,
  channelId: string,
  filename: string,
  buffer: Buffer,
  mimeType?: string,
)

Source from the content-addressed store, hash-verified

34 * Save a buffer as an attachment file and return a ChannelAttachment descriptor.
35 */
36export async function saveAttachment(
37 rootDir: string,
38 channelId: string,
39 filename: string,
40 buffer: Buffer,
41 mimeType?: string,
42): Promise<ChannelAttachment> {
43 const dir = getAttachmentDir(rootDir, channelId);
44 fs.mkdirSync(dir, { recursive: true });
45
46 const ts = Date.now();
47 const safeName = sanitizeFilename(filename);
48 const storedName = `${ts}-${safeName}`;
49 const fullPath = path.join(dir, storedName);
50
51 fs.writeFileSync(fullPath, buffer);
52
53 return {
54 filename,
55 localPath: fullPath,
56 mimeType,
57 size: buffer.byteLength,
58 };
59}
60
61/**
62 * Download a file from a URL and save it as an attachment.

Callers 1

Calls 2

getAttachmentDirFunction · 0.85
sanitizeFilenameFunction · 0.85

Tested by

no test coverage detected