Skip to content

Commit

Permalink
Add PACKAGES files
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Mar 8, 2025
1 parent 38cd950 commit e91d1ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/db.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {MongoClient, GridFSBucket} from 'mongodb';
import {Readable} from "node:stream";
import path from 'node:path';
import {pkgfields, doc_to_paths} from './tools.js';
import createError from 'http-errors';

Expand Down Expand Up @@ -234,18 +235,29 @@ function mongo_universe_files(user, prefix, start_after){
if(!docs.length) //should not happen because we checked earlier
throw createError(404, `No packages found in ${universe}`);
var files = [];
var indexes = {};
docs.forEach(function(doc){
doc_to_paths(doc).forEach(function(path){
if(!prefix || path.startsWith(prefix)) {
doc_to_paths(doc).forEach(function(fpath){
if(!prefix || fpath.startsWith(prefix)) {
files.push({
Key: path,
Key: fpath,
ETag: doc._id,
LastModified: doc._published.toISOString(),
Size: doc._filesize
});
var repodir = path.dirname(fpath);
if(!(indexes[repodir] > doc._published)){
indexes[repodir] = doc._published;
}
}
});
});

for (const [path, date] of Object.entries(indexes)) {
files.push({ Key: path + '/PACKAGES', LastModified: date.toISOString()});
files.push({ Key: path + '/PACKAGES.gz', LastModified: date.toISOString()});
}

if(start_after){
var index = files.findIndex(x => x.Key == start_after);
if(index > -1){
Expand Down
6 changes: 4 additions & 2 deletions views/S3List.pug
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ ListBucketResult(xmlns="http://s3.amazonaws.com/doc/2006-03-01/")
Contents
Key #{x.Key}
LastModified #{x.LastModified}
ETag "#{x.ETag}"
Size #{x.Size}
if x.ETag
ETag "#{x.ETag}"
if x.Size
Size #{x.Size}

0 comments on commit e91d1ad

Please sign in to comment.