openvibers/openvibe.media Commits
/p/:slug/screenshot: a slug Media doesn't hold (pastes made in Community since the move) goes to Community like /p/:slug and /raw; a private one answers the same way. Hero-moment thumbnails linked here and showed broken images
Changes
@@@ -526,6 +526,13 @@ router.get('/p/:slug/raw', (req, res) => {router.get('/p/:slug/screenshot', (req, res) => {try {const paste = db.getPasteBySlug(String(req.params.slug));++ // Pastes made since the move live in Community only: send an unknown slug there, like++ // /p/:slug and /p/:slug/raw (Community answers with the image, or its own 404). Stored++ // hero-moment thumbnails pointed here and showed broken images.++ if ((!paste || paste.visibility === 'private') && movedTo()) { // private answers like missing++ res.set('Cache-Control', 'public, max-age=3600');++ return res.redirect(301, `${movedTo()}/p/${encodeURIComponent(String(req.params.slug))}/screenshot`);++ }if (!paste || !paste.screenshot_path) return res.status(404).send('Not found');if (paste.visibility === 'private') return res.status(404).send('Not found');if (!fs.existsSync(paste.screenshot_path)) return res.status(404).send('Not found');@@@ -143,6 +143,12 @@ const server = http.createServer(app);assert.deepStrictEqual([r.status, r.location], [301, 'https://community.test/p/no-such/raw'], 'moved: every slug goes to Community');r = await get('/p/priv-shot/raw');assert.deepStrictEqual([r.status, r.location], [301, 'https://community.test/p/priv-shot/raw'], 'moved: a private screenshot is not bounced to /screenshot');++ // /p/:slug/screenshot: a slug Media doesn't hold (pastes made in Community since the move, whose++ // screenshots hero moments linked here) goes to Community; a private one answers the same way.++ r = await get('/p/no-such/screenshot');++ assert.deepStrictEqual([r.status, r.location], [301, 'https://community.test/p/no-such/screenshot'], 'moved: an unknown screenshot slug goes to Community');++ r = await get('/p/priv-shot/screenshot');++ assert.deepStrictEqual([r.status, r.location], [301, 'https://community.test/p/priv-shot/screenshot'], 'moved: a private screenshot looks like an unknown one');delete process.env.PASTES_MOVED_TO;console.log('✅ /p/:slug/raw: private looks missing');
@@ -526,6 +526,13 @@ router.get('/p/:slug/raw', (req, res) => {
@@ -526,6 +526,13 @@ router.get('/p/:slug/raw', (req, res) => {
router.get('/p/:slug/screenshot', (req, res) => {
router.get('/p/:slug/screenshot', (req, res) => {
try {
try {
const paste = db.getPasteBySlug(String(req.params.slug));
const paste = db.getPasteBySlug(String(req.params.slug));
+ // Pastes made since the move live in Community only: send an unknown slug there, like
+ // /p/:slug and /p/:slug/raw (Community answers with the image, or its own 404). Stored
+ // hero-moment thumbnails pointed here and showed broken images.
+ if ((!paste || paste.visibility === 'private') && movedTo()) { // private answers like missing
+ res.set('Cache-Control', 'public, max-age=3600');
+ return res.redirect(301, `${movedTo()}/p/${encodeURIComponent(String(req.params.slug))}/screenshot`);
+ }
if (!paste || !paste.screenshot_path) return res.status(404).send('Not found');
if (!paste || !paste.screenshot_path) return res.status(404).send('Not found');
if (paste.visibility === 'private') return res.status(404).send('Not found');
if (paste.visibility === 'private') return res.status(404).send('Not found');
if (!fs.existsSync(paste.screenshot_path)) return res.status(404).send('Not found');
if (!fs.existsSync(paste.screenshot_path)) return res.status(404).send('Not found');
@@ -143,6 +143,12 @@ const server = http.createServer(app);
@@ -143,6 +143,12 @@ const server = http.createServer(app);
assert.deepStrictEqual([r.status, r.location], [301, 'https://community.test/p/no-such/raw'], 'moved: every slug goes to Community');
assert.deepStrictEqual([r.status, r.location], [301, 'https://community.test/p/no-such/raw'], 'moved: every slug goes to Community');
r = await get('/p/priv-shot/raw');
r = await get('/p/priv-shot/raw');
assert.deepStrictEqual([r.status, r.location], [301, 'https://community.test/p/priv-shot/raw'], 'moved: a private screenshot is not bounced to /screenshot');
assert.deepStrictEqual([r.status, r.location], [301, 'https://community.test/p/priv-shot/raw'], 'moved: a private screenshot is not bounced to /screenshot');
+ // /p/:slug/screenshot: a slug Media doesn't hold (pastes made in Community since the move, whose
+ // screenshots hero moments linked here) goes to Community; a private one answers the same way.
+ r = await get('/p/no-such/screenshot');
+ assert.deepStrictEqual([r.status, r.location], [301, 'https://community.test/p/no-such/screenshot'], 'moved: an unknown screenshot slug goes to Community');
+ r = await get('/p/priv-shot/screenshot');
+ assert.deepStrictEqual([r.status, r.location], [301, 'https://community.test/p/priv-shot/screenshot'], 'moved: a private screenshot looks like an unknown one');
delete process.env.PASTES_MOVED_TO;
delete process.env.PASTES_MOVED_TO;
console.log('✅ /p/:slug/raw: private looks missing');
console.log('✅ /p/:slug/raw: private looks missing');