diff --git a/index.js b/index.js index 78b9976..fef09cf 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,11 @@ app.set('port', process.env.PORT || PORT) app.set('port-https', process.env.PORT_HTTPS || PORT_HTTPS) app.use(morgan('combined')) app.use(history({ - index: '/web/index.html' + index: '/web/index.html', + rewrites: [ + // do not redirect webfinger et c. + { from: /^\/\.well-known\//, to: context => context.request.originalUrl } + ] })) app.use(bodyParser.json({ type: pub.consts.jsonldTypes diff --git a/package-lock.json b/package-lock.json index 38e5a99..d73baf9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2645,8 +2645,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -3061,8 +3060,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -3118,7 +3116,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3162,14 +3159,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, diff --git a/package.json b/package.json index 18cfdc3..7c73b90 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "guppe", "version": "0.0.1", - "description": "Decentralized social groups with ActivityPub, NodeJS, Express, and Mongodb", + "description": "Decentralized social groups with ActivityPub, NodeJS, Express, Vue, and Mongodb", "main": "index.js", "dependencies": { "body-parser": "^1.18.3", diff --git a/routes/user.js b/routes/user.js index ff4a3a3..9dab8bd 100644 --- a/routes/user.js +++ b/routes/user.js @@ -4,6 +4,30 @@ const router = express.Router() const pub = require('../pub') const net = require('../net') +// list active groups +router.get('/', net.validators.jsonld, function (req, res) { + const db = req.app.get('db') + db.collection('streams') + .aggregate([ + { $limit: 10000 }, // don't traverse the entire history + { $match: { type: 'Announce' } }, + { $group: { _id: '$actor', postCount: { $sum: 1 } } }, + { $lookup: { from: 'objects', localField: '_id', foreignField: 'id', as: 'actor' } }, + // merge joined actor up + { $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ['$actor', 0] }, '$$ROOT'] } } }, + { $project: { postCount: 1, preferredUsername: 1 } } + ]) + .sort({ postCount: -1 }) + .limit(Number.parseInt(req.query.n) || 20) + .toArray() + .then(groups => { console.log(JSON.stringify(groups)); return groups }) + .then(groups => res.json(groups)) + .catch(err => { + console.log(err.message) + return res.status(500).send() + }) +}) + router.get('/:name', net.validators.jsonld, function (req, res) { const name = req.params.name if (!name) { diff --git a/web/package-lock.json b/web/package-lock.json index d2a956f..b0f350c 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -3026,8 +3026,7 @@ "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", - "dev": true, - "optional": true + "dev": true }, "coa": { "version": "2.0.2", @@ -5634,8 +5633,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -5656,14 +5654,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5678,20 +5674,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -5808,8 +5801,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -5821,7 +5813,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5836,7 +5827,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -5844,14 +5834,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -5870,7 +5858,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -5951,8 +5938,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -5964,7 +5950,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -6050,8 +6035,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -6087,7 +6071,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -6107,7 +6090,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -6151,14 +6133,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -10214,8 +10194,7 @@ "version": "4.0.8", "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz", "integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=", - "dev": true, - "optional": true + "dev": true }, "rx-lite-aggregates": { "version": "4.0.8", diff --git a/web/src/App.vue b/web/src/App.vue index 82953c4..4f57d8f 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -6,11 +6,11 @@ -->