@thevinci/web 1.3.0 → 1.3.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.
@@ -746,15 +746,25 @@ export const registerFsRoutes = (app, dependencies) => {
746
746
  const Busboy = (await import('busboy')).default;
747
747
  const busboy = Busboy({ headers: req.headers, limits: { files: 50 } });
748
748
 
749
- const targetDir = req.body?.path || '';
749
+ let targetDir = '';
750
750
  const uploadedFiles = [];
751
751
  const errors = [];
752
+ let responseSent = false;
753
+
754
+ const sendError = (status, error) => {
755
+ if (responseSent) return;
756
+ responseSent = true;
757
+ return res.status(status).json({ error: error || 'Upload failed' });
758
+ };
759
+
760
+ busboy.on('field', (fieldname, value) => {
761
+ if (fieldname === 'path' && typeof value === 'string') {
762
+ targetDir = value;
763
+ }
764
+ });
752
765
 
753
766
  busboy.on('file', (fieldname, file, info) => {
754
767
  const filename = info?.filename || fieldname;
755
- const encoding = info?.encoding || '7bit';
756
- const mimeType = info?.mimeType || 'application/octet-stream';
757
-
758
768
  const resolvedTarget = targetDir ? `${targetDir}/${filename}` : filename;
759
769
 
760
770
  const writePromise = (async () => {
@@ -785,10 +795,15 @@ export const registerFsRoutes = (app, dependencies) => {
785
795
 
786
796
  writePromise
787
797
  .then((result) => uploadedFiles.push(result))
788
- .catch((err) => errors.push({ filename, error: err.message }));
798
+ .catch((err) => {
799
+ console.error(`[upload] Failed to write ${filename}:`, err.message);
800
+ errors.push({ filename, error: err.message });
801
+ });
789
802
  });
790
803
 
791
804
  busboy.on('finish', () => {
805
+ if (responseSent) return;
806
+ responseSent = true;
792
807
  if (errors.length > 0 && uploadedFiles.length === 0) {
793
808
  return res.status(500).json({ error: errors[0].error || 'Upload failed', errors });
794
809
  }
@@ -796,8 +811,12 @@ export const registerFsRoutes = (app, dependencies) => {
796
811
  });
797
812
 
798
813
  busboy.on('error', (err) => {
799
- console.error('Busboy error:', err);
800
- return res.status(500).json({ error: 'Upload failed' });
814
+ console.error('[upload] Busboy error:', err);
815
+ return sendError(500, 'Upload failed');
816
+ });
817
+
818
+ req.on('aborted', () => {
819
+ console.error('[upload] Request aborted');
801
820
  });
802
821
 
803
822
  req.pipe(busboy);