openvibers/openvibe.live Commits
Screenshot paste fallbacks link the screenshot directly, without the /raw hop; pasteRawUrl removed (#27)
Changes
@@@ -220,7 +220,7 @@ router.post('/avatar', requireAuth, avatarUpload.single('avatar'), async (req, rcontentType: req.file.mimetype || 'image/png',},});-- const screenshotUrl = media.publicUrl(paste.screenshot_url) || media.pasteRawUrl(paste.slug);++ const screenshotUrl = media.publicUrl(paste.screenshot_url) || media.pasteScreenshotUrl(paste.slug);db.updateUserAvatar(req.user.id, screenshotUrl, paste.id || null);const updated = db.getUserById(req.user.id);@@@ -67,7 +67,7 @@ async function _mediaContent() {function _pasteThumb(p) {if (p.screenshot_url) return media.publicUrl(p.screenshot_url);-- if (p.type === 'screenshot' && p.slug) return media.pasteRawUrl(p.slug);++ if (p.type === 'screenshot' && p.slug) return media.pasteScreenshotUrl(p.slug);return null;}@@@ -305,7 +305,6 @@ function generateThumbnail(kind, id, opts = {}) {function vodPlaybackUrl(id) { return `${MEDIA_PUBLIC_URL}/v/${id}`; }function clipUrl(id) { return `${MEDIA_PUBLIC_URL}/c/${id}`; }function pasteScreenshotUrl(slug) { return `${MEDIA_PUBLIC_URL}/p/${encodeURIComponent(slug)}/screenshot`; }--function pasteRawUrl(slug) { return `${MEDIA_PUBLIC_URL}/p/${encodeURIComponent(slug)}/raw`; }function thumbUrl(id) { return `${MEDIA_PUBLIC_URL}/t/${id}`; }function fileUrl(key) { return `${MEDIA_PUBLIC_URL}/f/${key}`; }// TODO(contract): paste screenshots have no explicit public route in the contract;@@@ -417,5 +416,5 @@ module.exports = {uploadFile, getFileMeta, deleteFile,uploadThumbnail, generateThumbnail,// URL builders-- vodPlaybackUrl, clipUrl, pasteScreenshotUrl, pasteRawUrl, thumbUrl, fileUrl, screenshotUrl, publicUrl,++ vodPlaybackUrl, clipUrl, pasteScreenshotUrl, thumbUrl, fileUrl, screenshotUrl, publicUrl,};@@@ -104,6 +104,16 @@ const server = http.createServer(app).listen(0, '127.0.0.1', async () => {assert.ok(/MEDIA_PUBLIC_URL\}\/p\/\$\{encodeURIComponent\(req\.params\.slug\)\}\/screenshot/.test(src), 'screenshot bytes still on Media');});++ await check('screenshot fallbacks use Media\'s screenshot URL, not the /raw hop', () => {++ assert.strictEqual(typeof media.pasteRawUrl, 'undefined', 'the /raw URL builder is gone');++ assert.strictEqual(media.pasteScreenshotUrl('a b'), `${media.MEDIA_PUBLIC_URL}/p/a%20b/screenshot`);++ for (const rel of ['server/home/routes.js', 'server/auth/routes.js']) {++ const src = fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');++ assert.ok(/pasteScreenshotUrl\(/.test(src), `${rel} falls back to the screenshot URL`);++ assert.ok(!/pasteRawUrl/.test(src), `${rel} no longer takes the /raw hop`);++ }++ });++await check('Live\'s sitemap lists no paste', async () => {const xml = await seo.buildSitemap();assert.ok(!/<loc>[^<]*\/p\//.test(xml), 'a /p/ URL in the sitemap');
@@ -220,7 +220,7 @@ router.post('/avatar', requireAuth, avatarUpload.single('avatar'), async (req, r
@@ -220,7 +220,7 @@ router.post('/avatar', requireAuth, avatarUpload.single('avatar'), async (req, r
contentType: req.file.mimetype || 'image/png',
contentType: req.file.mimetype || 'image/png',
},
},
});
});
- const screenshotUrl = media.publicUrl(paste.screenshot_url) || media.pasteRawUrl(paste.slug);
+ const screenshotUrl = media.publicUrl(paste.screenshot_url) || media.pasteScreenshotUrl(paste.slug);
db.updateUserAvatar(req.user.id, screenshotUrl, paste.id || null);
db.updateUserAvatar(req.user.id, screenshotUrl, paste.id || null);
const updated = db.getUserById(req.user.id);
const updated = db.getUserById(req.user.id);
@@ -67,7 +67,7 @@ async function _mediaContent() {
@@ -67,7 +67,7 @@ async function _mediaContent() {
function _pasteThumb(p) {
function _pasteThumb(p) {
if (p.screenshot_url) return media.publicUrl(p.screenshot_url);
if (p.screenshot_url) return media.publicUrl(p.screenshot_url);
- if (p.type === 'screenshot' && p.slug) return media.pasteRawUrl(p.slug);
+ if (p.type === 'screenshot' && p.slug) return media.pasteScreenshotUrl(p.slug);
return null;
return null;
}
}
@@ -305,7 +305,6 @@ function generateThumbnail(kind, id, opts = {}) {
@@ -305,7 +305,6 @@ function generateThumbnail(kind, id, opts = {}) {
function vodPlaybackUrl(id) { return `${MEDIA_PUBLIC_URL}/v/${id}`; }
function vodPlaybackUrl(id) { return `${MEDIA_PUBLIC_URL}/v/${id}`; }
function clipUrl(id) { return `${MEDIA_PUBLIC_URL}/c/${id}`; }
function clipUrl(id) { return `${MEDIA_PUBLIC_URL}/c/${id}`; }
function pasteScreenshotUrl(slug) { return `${MEDIA_PUBLIC_URL}/p/${encodeURIComponent(slug)}/screenshot`; }
function pasteScreenshotUrl(slug) { return `${MEDIA_PUBLIC_URL}/p/${encodeURIComponent(slug)}/screenshot`; }
-function pasteRawUrl(slug) { return `${MEDIA_PUBLIC_URL}/p/${encodeURIComponent(slug)}/raw`; }
function thumbUrl(id) { return `${MEDIA_PUBLIC_URL}/t/${id}`; }
function thumbUrl(id) { return `${MEDIA_PUBLIC_URL}/t/${id}`; }
function fileUrl(key) { return `${MEDIA_PUBLIC_URL}/f/${key}`; }
function fileUrl(key) { return `${MEDIA_PUBLIC_URL}/f/${key}`; }
// TODO(contract): paste screenshots have no explicit public route in the contract;
// TODO(contract): paste screenshots have no explicit public route in the contract;
@@ -417,5 +416,5 @@ module.exports = {
@@ -417,5 +416,5 @@ module.exports = {
uploadFile, getFileMeta, deleteFile,
uploadFile, getFileMeta, deleteFile,
uploadThumbnail, generateThumbnail,
uploadThumbnail, generateThumbnail,
// URL builders
// URL builders
- vodPlaybackUrl, clipUrl, pasteScreenshotUrl, pasteRawUrl, thumbUrl, fileUrl, screenshotUrl, publicUrl,
+ vodPlaybackUrl, clipUrl, pasteScreenshotUrl, thumbUrl, fileUrl, screenshotUrl, publicUrl,
};
};
@@ -104,6 +104,16 @@ const server = http.createServer(app).listen(0, '127.0.0.1', async () => {
@@ -104,6 +104,16 @@ const server = http.createServer(app).listen(0, '127.0.0.1', async () => {
assert.ok(/MEDIA_PUBLIC_URL\}\/p\/\$\{encodeURIComponent\(req\.params\.slug\)\}\/screenshot/.test(src), 'screenshot bytes still on Media');
assert.ok(/MEDIA_PUBLIC_URL\}\/p\/\$\{encodeURIComponent\(req\.params\.slug\)\}\/screenshot/.test(src), 'screenshot bytes still on Media');
});
});
+ await check('screenshot fallbacks use Media\'s screenshot URL, not the /raw hop', () => {
+ assert.strictEqual(typeof media.pasteRawUrl, 'undefined', 'the /raw URL builder is gone');
+ assert.strictEqual(media.pasteScreenshotUrl('a b'), `${media.MEDIA_PUBLIC_URL}/p/a%20b/screenshot`);
+ for (const rel of ['server/home/routes.js', 'server/auth/routes.js']) {
+ const src = fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
+ assert.ok(/pasteScreenshotUrl\(/.test(src), `${rel} falls back to the screenshot URL`);
+ assert.ok(!/pasteRawUrl/.test(src), `${rel} no longer takes the /raw hop`);
+ }
+ });
+
await check('Live\'s sitemap lists no paste', async () => {
await check('Live\'s sitemap lists no paste', async () => {
const xml = await seo.buildSitemap();
const xml = await seo.buildSitemap();
assert.ok(!/<loc>[^<]*\/p\//.test(xml), 'a /p/ URL in the sitemap');
assert.ok(!/<loc>[^<]*\/p\//.test(xml), 'a /p/ URL in the sitemap');