Upstream/server/routes/sharedReports.js
jvanvik b18645dca1 Phase 2: client military/social screens, WebSocket push, trade + endgame, review findings pending
Built: units/movements/reports/send/expansion screens, alliance/messages/rankings screens, ws client + server /ws push
(docs/PROTOCOL.md), Internet exchange trade, backbone endgame + world end, shared reports, buildDone relative levels.
Tested: npm test 175/175. Two adversarial reviews found issues (trade-leg recall exploit, __proto__ via validate.js,
rankings DoS, static headers, ...): fixes follow in the next commit.
NOT done: bots/balance, e2e suite, real-device checks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
2026-10-11 19:05:03 +02:00

30 lines
1.9 KiB
JavaScript

'use strict';
/* The alliance's shared report folder: share one of your reports, list and read the folder, take one out. */
const { createSharedReportQueries } = require('../sharedReports');
function register(router, services) {
const { commands } = services;
const folder = createSharedReportQueries(services);
const errs = ['unauthorized', 'not_found', 'validation_failed'];
router.post('/reports/:id/share', {
summary: 'Put one of your reports into your alliance\'s shared folder (needs shareReport; keeps the report for another 14 days)', tag: 'reports',
response: { $ref: 'ReportShared' }, errors: errs.concat(['not_in_alliance', 'forbidden', 'world_ended']),
}, ({ user, params }) => commands.run('reportShare', { userId: user.id, reportId: params.id }));
router.del('/reports/:id/share', {
summary: 'Take a report out of the alliance folder (whoever shared it, or leader/officer)', tag: 'reports',
response: { $ref: 'ReportShared' }, errors: errs.concat(['forbidden', 'world_ended']),
}, ({ user, params }) => commands.run('reportUnshare', { userId: user.id, reportId: params.id }));
router.get('/alliances/:id/reports', {
summary: 'The alliance\'s shared reports, newest first (cursor: after = id of the last report seen; members only)', tag: 'reports',
query: { type: 'object', properties: { after: { type: 'integer', minimum: 1 }, limit: { type: 'integer', minimum: 1, maximum: 100 } } },
response: { $ref: 'SharedReportList' }, errors: errs.concat(['forbidden']),
}, ({ user, params, query }) => folder.list(user.id, params.id, query));
router.get('/alliances/:id/reports/:reportId', {
summary: 'One shared report with its full data (members only)', tag: 'reports', response: { $ref: 'SharedReportResponse' }, errors: errs.concat(['forbidden']),
}, ({ user, params }) => folder.get(user.id, params.id, params.reportId));
}
module.exports = { register };