@@ -12,7 +12,7 @@ import mongo from '#mongo'
1212import config from '#config'
1313import { authenticateApiKey , tryAuthenticateReadKey } from '../auth.ts'
1414import { artefactAccessFilter , artefactAccessFilterForAccount , assertDownloadAccess , assertDownloadAccessForAccount } from '../access.ts'
15- import { writeFile , readFile , getDownloadUrl , deleteFile , moveFile } from '../files-storage/index.ts'
15+ import { writeFile , readFile , getDownloadUrl , deleteFile , moveFile , fileStats } from '../files-storage/index.ts'
1616import { extractManifest , parseSemver , resolveVersionQuery , pruneOldVersions } from './service.ts'
1717import * as patchReqBody from '#doc/artefacts/patch-req/index.ts'
1818import { artefactThumbnailRouter } from '../thumbnails/router.ts'
@@ -92,7 +92,7 @@ router.get('/', async (req, res, next) => {
9292 }
9393 const skip = Math . max ( 0 , Math . min ( parseInt ( req . query . skip as string ) || 0 , 100000 ) )
9494 const size = Math . min ( parseInt ( req . query . size as string ) || 10 , 100 )
95- const sort : Record < string , 1 | - 1 > = req . query . sort === 'name' ? { name : 1 } : { updatedAt : - 1 }
95+ const sort : Record < string , 1 | - 1 > = req . query . sort === 'name' ? { name : 1 } : { dataUpdatedAt : - 1 }
9696
9797 // Text search on name
9898 if ( req . query . q ) {
@@ -265,6 +265,7 @@ router.post('/:name/versions', async (req, res, next) => {
265265 await moveFile ( stagingPath , tarballPath )
266266 stagingStored = false
267267 finalTarballPath = tarballPath
268+ const { size } = await fileStats ( tarballPath )
268269
269270 // Upsert artefact
270271 const now = new Date ( ) . toISOString ( )
@@ -278,7 +279,8 @@ router.post('/:name/versions', async (req, res, next) => {
278279 category,
279280 ...( manifest . processingConfigSchema ? { processingConfigSchema : manifest . processingConfigSchema } : { } ) ,
280281 ...( manifest . applicationConfigSchema ? { applicationConfigSchema : manifest . applicationConfigSchema } : { } ) ,
281- updatedAt : now
282+ updatedAt : now ,
283+ dataUpdatedAt : now
282284 } ,
283285 $setOnInsert : {
284286 _id : artefactId ,
@@ -302,6 +304,7 @@ router.post('/:name/versions', async (req, res, next) => {
302304 ...( architecture ? { architecture } : { } ) ,
303305 ...semverParts ,
304306 tarballPath,
307+ size,
305308 uploadedAt : now ,
306309 uploadedBy : apiKey
307310 ? { apiKeyId : apiKey . _id , apiKeyName : apiKey . name , shortId : apiKey . shortId }
@@ -442,6 +445,7 @@ router.post('/file/:name', async (req, res, next) => {
442445 await moveFile ( stagingPath , filePath )
443446 stagingStored = false
444447 newFilePath = filePath
448+ const { size } = await fileStats ( filePath )
445449
446450 const now = new Date ( ) . toISOString ( )
447451 await mongo . artefacts . updateOne (
@@ -450,13 +454,15 @@ router.post('/file/:name', async (req, res, next) => {
450454 $set : {
451455 filePath,
452456 fileName,
457+ size,
453458 category,
454459 ...( title !== undefined ? { title } : { } ) ,
455460 ...( description !== undefined ? { description } : { } ) ,
456461 uploadedBy : apiKey
457462 ? { apiKeyId : apiKey . _id , apiKeyName : apiKey . name , shortId : apiKey . shortId }
458463 : { internal : true } ,
459- updatedAt : now
464+ updatedAt : now ,
465+ dataUpdatedAt : now
460466 } ,
461467 $setOnInsert : {
462468 _id : artefactId ,
0 commit comments