updates to most features
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 28s
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 28s
This commit is contained in:
@@ -32,6 +32,33 @@ router.get('/leaderboard', (req, res) => {
|
||||
res.render('leaderboard/global', { title: 'Global Leaderboard', leaderboard });
|
||||
});
|
||||
|
||||
// ─── Package profile (by card number — no secret code exposed) ────
|
||||
router.get('/hunt/:shortName/:cardNumber', (req, res) => {
|
||||
const { shortName, cardNumber } = req.params;
|
||||
if (!/^\d+$/.test(cardNumber)) {
|
||||
return res.status(404).render('error', { title: 'Not Found', message: 'Package not found.' });
|
||||
}
|
||||
|
||||
const pkg = Packages.findByHuntAndCardNumber(shortName, cardNumber);
|
||||
if (!pkg) {
|
||||
return res.status(404).render('error', { title: 'Not Found', message: 'Package not found.' });
|
||||
}
|
||||
|
||||
const fullPkg = Packages.getProfile(pkg.id);
|
||||
const scanHistory = Packages.getScanHistory(pkg.id);
|
||||
const isFirstScanner = req.session && req.session.userId && fullPkg.first_scanned_by === req.session.userId;
|
||||
const isLastScanner = req.session && req.session.userId && fullPkg.last_scanned_by === req.session.userId;
|
||||
|
||||
res.render('loot/profile', {
|
||||
title: `Package ${fullPkg.card_number} of ${pkg.package_count} - ${fullPkg.hunt_name}`,
|
||||
pkg: fullPkg,
|
||||
scanHistory,
|
||||
isFirstScanner,
|
||||
isLastScanner,
|
||||
packages_total: pkg.package_count
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Browse all hunts ─────────────────────────────────────
|
||||
router.get('/hunts', (req, res) => {
|
||||
const hunts = Hunts.getAll();
|
||||
|
||||
@@ -61,40 +61,29 @@ router.get('/:shortName/:code', (req, res) => {
|
||||
// Reload package with full profile
|
||||
const fullPkg = Packages.getProfile(pkg.id);
|
||||
const scanHistory = Packages.getScanHistory(pkg.id);
|
||||
const hunt = Hunts.findById(fullPkg.hunt_id);
|
||||
const isFirstScanner = fullPkg.first_scanned_by === req.session.userId;
|
||||
const isLastScanner = fullPkg.last_scanned_by === req.session.userId;
|
||||
|
||||
res.render('loot/scanned', {
|
||||
title: `Package #${fullPkg.card_number} - ${fullPkg.hunt_name}`,
|
||||
title: `Package ${fullPkg.card_number} of ${hunt.package_count} - ${fullPkg.hunt_name}`,
|
||||
pkg: fullPkg,
|
||||
scanResult: result,
|
||||
scanHistory,
|
||||
isFirstScanner,
|
||||
isLastScanner
|
||||
isLastScanner,
|
||||
packages_total: hunt.package_count
|
||||
});
|
||||
});
|
||||
|
||||
// ─── View package profile (non-scan view) ─────────────────
|
||||
// ─── Redirect old profile URLs to new route ──────────────
|
||||
router.get('/:shortName/:code/profile', (req, res) => {
|
||||
const { shortName, code } = req.params;
|
||||
const pkg = Packages.findByHuntAndCode(shortName, code);
|
||||
|
||||
if (!pkg) {
|
||||
return res.status(404).render('error', { title: 'Not Found', message: 'This loot package was not found.' });
|
||||
return res.status(404).render('error', { title: 'Not Found', message: 'Package not found.' });
|
||||
}
|
||||
|
||||
const fullPkg = Packages.getProfile(pkg.id);
|
||||
const scanHistory = Packages.getScanHistory(pkg.id);
|
||||
const isFirstScanner = req.session.userId && fullPkg.first_scanned_by === req.session.userId;
|
||||
const isLastScanner = req.session.userId && fullPkg.last_scanned_by === req.session.userId;
|
||||
|
||||
res.render('loot/profile', {
|
||||
title: `Package #${fullPkg.card_number} - ${fullPkg.hunt_name}`,
|
||||
pkg: fullPkg,
|
||||
scanHistory,
|
||||
isFirstScanner,
|
||||
isLastScanner
|
||||
});
|
||||
res.redirect(`/hunt/${shortName}/${pkg.card_number}`);
|
||||
});
|
||||
|
||||
// ─── Upload first-scan image ──────────────────────────────
|
||||
@@ -111,12 +100,12 @@ router.post('/:shortName/:code/image', requireAuth, upload.single('image'), (req
|
||||
}
|
||||
|
||||
if (!req.file) {
|
||||
return res.redirect(`/loot/${shortName}/${code}/profile`);
|
||||
return res.redirect(`/hunt/${shortName}/${pkg.card_number}`);
|
||||
}
|
||||
|
||||
const imagePath = `/uploads/${req.file.filename}`;
|
||||
Packages.updateFirstScanImage(pkg.id, imagePath);
|
||||
res.redirect(`/loot/${shortName}/${code}/profile`);
|
||||
res.redirect(`/hunt/${shortName}/${pkg.card_number}`);
|
||||
});
|
||||
|
||||
// ─── Update hint/message ──────────────────────────────────
|
||||
@@ -134,7 +123,7 @@ router.post('/:shortName/:code/hint', requireAuth, (req, res) => {
|
||||
|
||||
const hint = (req.body.hint || '').trim().substring(0, 500);
|
||||
Packages.updateLastScanHint(pkg.id, req.session.userId, hint);
|
||||
res.redirect(`/loot/${shortName}/${code}/profile`);
|
||||
res.redirect(`/hunt/${shortName}/${pkg.card_number}`);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user