|
1 | 1 | import { ReceiveTypes } from '@hawk.so/types'; |
2 | 2 | import * as telegram from '../utils/telegram'; |
3 | 3 | const mongo = require('../mongo'); |
| 4 | +const { ObjectId } = require('mongodb'); |
4 | 5 | const { ApolloError, UserInputError } = require('apollo-server-express'); |
5 | 6 | const Validator = require('../utils/validator'); |
6 | 7 | const EventsFactory = require('../models/eventsFactory'); |
@@ -577,13 +578,56 @@ module.exports = { |
577 | 578 | release: release, |
578 | 579 | }); |
579 | 580 |
|
| 581 | + let enrichedFiles = Array.isArray(releaseDoc?.files) ? releaseDoc.files : []; |
| 582 | + |
| 583 | + if (enrichedFiles.length > 0) { |
| 584 | + try { |
| 585 | + const filesColl = mongo.databases.events.collection('releases.files'); |
| 586 | + |
| 587 | + const ids = [...new Set( |
| 588 | + enrichedFiles |
| 589 | + .filter(f => f && typeof f === 'object' && f._id) |
| 590 | + .map(f => String(f._id)) |
| 591 | + )].map(id => new ObjectId(id)); |
| 592 | + |
| 593 | + if (ids.length > 0) { |
| 594 | + const filesInfo = await filesColl.find( |
| 595 | + { _id: { $in: ids } }, |
| 596 | + { projection: { length: 1, uploadDate: 1 } } |
| 597 | + ).toArray(); |
| 598 | + |
| 599 | + const metaById = new Map( |
| 600 | + filesInfo.map(doc => [String(doc._id), { length: doc.length, uploadDate: doc.uploadDate }]) |
| 601 | + ); |
| 602 | + |
| 603 | + enrichedFiles = enrichedFiles.map((entry) => { |
| 604 | + if (typeof entry === 'string') { |
| 605 | + return entry; |
| 606 | + } |
| 607 | + |
| 608 | + const meta = metaById.get(String(entry._id)); |
| 609 | + |
| 610 | + return { |
| 611 | + mapFileName: entry.mapFileName, |
| 612 | + originFileName: entry.originFileName, |
| 613 | + length: meta?.length ?? null, |
| 614 | + uploadDate: meta?.uploadDate ?? null, |
| 615 | + }; |
| 616 | + }); |
| 617 | + } |
| 618 | + } catch (e) { |
| 619 | + // In case of any error with enrichment, fallback to original structure |
| 620 | + enrichedFiles = releaseDoc?.files || []; |
| 621 | + } |
| 622 | + } |
| 623 | + |
580 | 624 | return { |
581 | 625 | release, |
582 | 626 | projectId: project._id, |
583 | 627 | commitsCount: Array.isArray(releaseDoc?.commits) ? releaseDoc.commits.length : 0, |
584 | 628 | filesCount: Array.isArray(releaseDoc?.files) ? releaseDoc.files.length : 0, |
585 | 629 | commits: releaseDoc?.commits || [], |
586 | | - files: releaseDoc?.files || [], |
| 630 | + files: enrichedFiles, |
587 | 631 | timestamp: releaseDoc?._id ? dateFromObjectId(releaseDoc._id) : null, |
588 | 632 | }; |
589 | 633 | }, |
|
0 commit comments