Skip to content

Instantly share code, notes, and snippets.

@antonkalik
Created March 27, 2024 21:19
Show Gist options
  • Save antonkalik/836146bb6298a6e89d2671edfa98570e to your computer and use it in GitHub Desktop.
Save antonkalik/836146bb6298a6e89d2671edfa98570e to your computer and use it in GitHub Desktop.
Generate Attachements
import path from 'path';
import { Extension } from 'src/@types/enums';
type AttachmentFile = {
name: string;
ext?: Extension;
cid?: string;
};
export const generateAttachments = (files: AttachmentFile[] = []) =>
files.map(file => {
const ext = file.ext || Extension.png;
const filename = `${file.name}.${ext}`;
const imagePath = path.join(__dirname, '..', 'src/assets', filename);
return {
filename,
path: imagePath,
cid: file.cid || file.name,
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment