Skip to content

Commit

Permalink
Only link to existing universes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Jan 5, 2025
1 parent cce798b commit 5f41aff
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion routes/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function(req, res, next){
res.set('Cache-Control', `public, max-age=60, stale-while-revalidate=${cdn_cache}`);

if(doc){
const revision = 2; // bump to invalidate all caches
const revision = 3; // bump to invalidate all caches
const etag = `W/"${doc._id}${revision}"`;
const date = new Date(doc._published.getTime() + revision * 1000).toUTCString();
res.set('ETag', etag);
Expand Down
17 changes: 12 additions & 5 deletions routes/pkginfo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express';
import createError from 'http-errors';
import url from 'node:url';
import {get_package_info} from '../src/db.js';
import {get_package_info, get_all_universes} from '../src/db.js';
const router = express.Router();

function avatar_url(login, size){
Expand Down Expand Up @@ -133,9 +133,15 @@ function filter_releases(pkgdata){
}
}

function filter_contributions(pkgdata, max = 12){
function filter_contributions(pkgdata, universes, max = 12){
if(pkgdata._contributions){
return Object.fromEntries(Object.entries(pkgdata._contributions).slice(0,max))
return Object.entries(pkgdata._contributions).slice(0,max).map(function([login, count]){
return {
login: login,
count: count,
href: universes.includes(login) && `https://${login}.r-universe.dev/contributors`
}
});
}
}

Expand Down Expand Up @@ -220,7 +226,8 @@ function description_to_html(txt = ""){
}

router.get('/:package', function(req, res, next) {
return get_package_info(req.params.package, req.universe).then(function(pkgdata){
const promises = [get_package_info(req.params.package, req.universe), get_all_universes()];
return Promise.all(promises).then(function([pkgdata, universes]){
pkgdata.url = url;
pkgdata.format_count = format_count;
pkgdata.universe = pkgdata._user;
Expand All @@ -237,7 +244,7 @@ router.get('/:package', function(req, res, next) {
pkgdata._problems = problem_summary(pkgdata);
pkgdata._lastupdate = pretty_time_diff(pkgdata._commit.time);
pkgdata._releases = filter_releases(pkgdata);
pkgdata._contributions = filter_contributions(pkgdata);
pkgdata._contributions = filter_contributions(pkgdata, universes);
pkgdata._universe_type = pkgdata._userbio.type;
pkgdata._universe_name = pkgdata._userbio.name;
pkgdata._universe_bio = pkgdata._userbio.description;
Expand Down
10 changes: 10 additions & 0 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const db = production && client.db('cranlike');
const bucket = production && new GridFSBucket(db, {bucketName: 'files'});
const packages = production && db.collection('packages');
const chunks = production && db.collection('files.chunks');
const universes = production && packages.distinct('_universes');
console.log("Connected to MongoDB!");

function mongo_latest(q){
Expand Down Expand Up @@ -602,3 +603,12 @@ export function bucket_find(query, options = {}){
throw "Not implemented for devel";
}
}

//use cached result because we dont want any delay for this
export function get_all_universes(){
if(production){
return universes;
} else {
throw "Not implemented for devel";
}
}
6 changes: 3 additions & 3 deletions views/pkginfo.pug
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ block content
canvas#package-updates-canvas(height='300')
if _contributions
.package-details-contributors.text-center
each count, login in _contributions
a.me-1.package-details-contributor.text-decoration-none(href=`https://${login}.r-universe.dev/contributors`)
img.package-contributor-img.img-fluid.p-1.shadow-lg(loading="lazy" data-count=count data-login=login style='width: 80px; border-radius: 50%;' src=avatar_url(login, 160))
each x in _contributions
a.me-1.package-details-contributor.text-decoration-none(href=x.href)
img.package-contributor-img.img-fluid.p-1.shadow-lg(loading="lazy" data-count=x.count data-login=x.login style='width: 80px; border-radius: 50%;' src=avatar_url(x.login, 160))

#readme.package-details-readme.row.card.mt-4(data-scroll-to="tooltip" data-position="left" data-title='Documentation' data-intro='Rendered documentation from the README and help pages.')
a.plink.card-title.card-header.text-center.text-dark(href='#readme')
Expand Down

0 comments on commit 5f41aff

Please sign in to comment.