import { TransformKit } from '@transform-kit/sdk';
const tk = new TransformKit({ apiKey: process.env.API_KEY! });
export async function onProfilePhotoUpload(formData: FormData) {
const file = formData.get('photo') as File;
const bytes = Buffer.from(await file.arrayBuffer());
const [photo] = await tk.runPipeline(
[{ bytes, filename: file.name }],
{
nodes: [
{ id: 'in', type: 'pipeline.input' },
{ id: 'thumb', type: 'image.resize', config: { mode: { value: 'pixels' }, width: { value: 400 }, height: { value: 400 }, fit: { value: 'inside' } } } },
{ id: 'thumbOut', type: 'pipeline.output', config: { suffix: { value: 'thumb' } } },
{ id: 'banner', type: 'image.resize', config: { mode: { value: 'pixels' }, width: { value: 1200 }, height: { value: 630 }, fit: { value: 'inside' } } } },
{ id: 'bannerOut', type: 'pipeline.output', config: { suffix: { value: 'banner' } } },
{ id: 'export', type: 'image.resize', config: { mode: { value: 'pixels' }, width: { value: 2400 }, height: { value: 2400 }, fit: { value: 'inside' } } } },
{ id: 'exportOut', type: 'pipeline.output', config: { suffix: { value: 'export' } } },
],
edges: [
{ source: 'in', target: 'thumb' },
{ source: 'thumb', target: 'thumbOut' },
{ source: 'in', target: 'banner' },
{ source: 'banner', target: 'bannerOut' },
{ source: 'in', target: 'export' },
{ source: 'export', target: 'exportOut' },
],
},
);
return photo.outputs.map((o) => ({ label: o.output, url: o.media.url }));
}