@anteros/core 0.0.1-alpha.8 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/files.ts CHANGED
@@ -352,12 +352,43 @@ export async function handleDelete(
352
352
  tenant_id: string,
353
353
  collection: string,
354
354
  fileId: string,
355
- filename: string,
356
355
  ): Promise<void> {
357
356
  const storage = getStorageForCollection(collection, tenant_id);
358
357
  const col = getFileCollection(collection, tenant_id);
358
+
359
+ // Look up the document to get the stored filename
360
+ let filename: string | undefined;
361
+ if (col?.trackMetaData !== false) {
362
+ try {
363
+ const rest = new useRest({ tenant_id, internal: true, useHook: false, useCustomApi: false });
364
+ const doc = await rest.findOne<any>(collection, fileId);
365
+ filename = doc?._file?.filename;
366
+ } catch {}
367
+ }
368
+
369
+ // Delete the physical file from storage
359
370
  const subpath = col?.storage?.path || undefined;
360
- await storage.delete(tenant_id, collection, fileId, filename, subpath);
371
+ if (filename) {
372
+ await storage.delete(tenant_id, collection, fileId, filename, subpath);
373
+ } else {
374
+ // Fallback: try common extensions
375
+ for (const ext of ['.jpg', '.jpeg', '.png', '.webp', '.avif', '.gif', '.svg', '.pdf', '.mp4', '.webm', '.mp3', '.wav', '.json', '.csv', '.zip', '']) {
376
+ try {
377
+ await storage.delete(tenant_id, collection, fileId, fileId + ext, subpath);
378
+ break;
379
+ } catch {}
380
+ }
381
+ }
382
+
383
+ // Delete the metadata document from MongoDB
384
+ if (col?.trackMetaData !== false) {
385
+ try {
386
+ const rest = new useRest({ tenant_id, internal: true, useHook: false, useCustomApi: false });
387
+ await rest.deleteOne(collection, fileId);
388
+ } catch (err: any) {
389
+ console.error('Failed to delete file metadata:', err?.message || err);
390
+ }
391
+ }
361
392
  }
362
393
 
363
394
  // ─── Replication ──────────────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@anteros/core",
3
3
  "module": "index.ts",
4
- "version": "0.0.1-alpha.8",
4
+ "version": "0.0.2",
5
5
  "type": "module",
6
6
  "description": "Anteros Core",
7
7
  "private": false,
package/server/api.ts CHANGED
@@ -732,13 +732,12 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
732
732
  }
733
733
  await checkFileAccess(colDelete?.api?.access as any, 'delete', tenant_id, c);
734
734
 
735
- const filename = basename(c.req.param('file') as string);
736
- if (!filename || filename.startsWith('.') || filename.includes('..') || filename.includes('/')) {
737
- throw new AppError('Invalid filename', { status: 400, code: 'INVALID_FILENAME' });
735
+ const fileId = c.req.param('file') as string;
736
+ if (!fileId || fileId.startsWith('.') || fileId.includes('..') || fileId.includes('/')) {
737
+ throw new AppError('Invalid file id', { status: 400, code: 'INVALID_FILE_ID' });
738
738
  }
739
- const fileId = filename.replace(/\.[^.]+$/, '');
740
739
 
741
- await handleDelete(tenant_id, collection, fileId, filename);
740
+ await handleDelete(tenant_id, collection, fileId);
742
741
 
743
742
  return c.json({ message: 'File deleted', ok: true });
744
743
  } catch (err: any) {