mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-22 16:46:42 +02:00
feat(api): route all image uploads through mana-media for CAS, thumbnails & Photos gallery
Picture, Contacts, Planta, Storage, and NutriPhi image uploads now go through mana-media instead of directly to S3. This enables SHA-256 deduplication, automatic thumbnail generation, EXIF extraction, and makes all images visible in the Photos gallery. Non-image files (PDFs, audio, docs) continue to use shared-storage directly. SVG avatars in Contacts also stay on shared-storage since Sharp can't process SVGs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
46dae20fa3
commit
502813f49c
10 changed files with 238 additions and 213 deletions
|
|
@ -29,22 +29,37 @@ routes.post('/:id/avatar', async (c) => {
|
|||
}
|
||||
|
||||
try {
|
||||
const { createContactsStorage, generateUserFileKey, getContentType } = await import(
|
||||
'@manacore/shared-storage'
|
||||
);
|
||||
const storage = createContactsStorage();
|
||||
const key = generateUserFileKey(
|
||||
userId,
|
||||
`avatar-${c.req.param('id')}.${file.name.split('.').pop()}`
|
||||
);
|
||||
const buffer = Buffer.from(await file.arrayBuffer());
|
||||
const buffer = await file.arrayBuffer();
|
||||
|
||||
const result = await storage.upload(key, buffer, {
|
||||
contentType: getContentType(file.name),
|
||||
public: true,
|
||||
});
|
||||
if (file.type === 'image/svg+xml') {
|
||||
// SVGs stay on shared-storage (Sharp can't process SVG)
|
||||
const { createContactsStorage, generateUserFileKey } = await import(
|
||||
'@manacore/shared-storage'
|
||||
);
|
||||
const storage = createContactsStorage();
|
||||
const key = generateUserFileKey(userId, `avatar-${c.req.param('id')}.svg`);
|
||||
const result = await storage.upload(key, Buffer.from(buffer), {
|
||||
contentType: 'image/svg+xml',
|
||||
public: true,
|
||||
});
|
||||
return c.json({ avatarUrl: result.url }, 201);
|
||||
}
|
||||
|
||||
return c.json({ avatarUrl: result.url }, 201);
|
||||
// Raster images -> mana-media for dedup, thumbnails & Photos gallery
|
||||
const { uploadImageToMedia } = await import('../../lib/media');
|
||||
const result = await uploadImageToMedia(
|
||||
buffer,
|
||||
`avatar-${c.req.param('id')}.${file.name.split('.').pop()}`,
|
||||
{ app: 'contacts', userId }
|
||||
);
|
||||
|
||||
return c.json(
|
||||
{
|
||||
avatarUrl: result.urls.thumbnail || result.urls.original,
|
||||
mediaId: result.id,
|
||||
},
|
||||
201
|
||||
);
|
||||
} catch {
|
||||
return c.json({ error: 'Upload failed' }, 500);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue