openvibers/openvibe.live Commits
A picture alone is a comment on a recording or a clip (#863)
Changes
@@@ -255,8 +255,10 @@ router.post('/:type/:id', requireAuth, async (req, res) => {return res.status(400).json({ error: 'Invalid content type or ID' });}const message = String(req.body.message || '').trim();-- if (!message || message.length > MAX_MESSAGE) {-- return res.status(400).json({ error: `Comment must be 1-${MAX_MESSAGE} characters` });++ // A picture alone is a comment, as on any social app (the owner, 11-12): words are optional with a file attached.++ const hasFiles = Array.isArray(req.body.attachments) && req.body.attachments.length > 0;++ if ((!message && !hasFiles) || message.length > MAX_MESSAGE) {++ return res.status(400).json({ error: `Write something or attach a picture (up to ${MAX_MESSAGE} characters)` });}const parentId = req.body.parent_id ? parseInt(req.body.parent_id) : null;const target = await visibleTarget(req.user, contentType, contentId);@@@ -216,6 +216,13 @@ async function check(name, fn) {{ method: 'POST', headers: { 'x-test-user': '5' }, body: form });assert.strictEqual(other.status, 404, 'a non-owner cannot upload to a private VOD');assert.strictEqual((await call('POST', '/api/comments/vod/100', 5, { message: 'Too many', attachments: Array(5).fill(uploaded.attachment) })).status, 400);++ // A picture alone is a comment (the owner, 11-12); nothing at all is still refused.++ const quiet = await call('POST', '/api/comments/vod/100', 5, { message: '', attachments: [uploaded.attachment] });++ assert.strictEqual(quiet.status, 201, quiet.text);++ assert.strictEqual(last('POST', /\/comments$/).body.message, '', 'Community gets the picture with no words');++ const bare = await call('POST', '/api/comments/vod/100', 5, { message: ' ' });++ assert.strictEqual(bare.status, 400);++ assert.match(bare.json.error, /Write something or attach a picture/);});await check('edit: the author only (as their subject); edits show as edited', async () => {
@@ -255,8 +255,10 @@ router.post('/:type/:id', requireAuth, async (req, res) => {
@@ -255,8 +255,10 @@ router.post('/:type/:id', requireAuth, async (req, res) => {
return res.status(400).json({ error: 'Invalid content type or ID' });
return res.status(400).json({ error: 'Invalid content type or ID' });
}
}
const message = String(req.body.message || '').trim();
const message = String(req.body.message || '').trim();
- if (!message || message.length > MAX_MESSAGE) {
- return res.status(400).json({ error: `Comment must be 1-${MAX_MESSAGE} characters` });
+ // A picture alone is a comment, as on any social app (the owner, 11-12): words are optional with a file attached.
+ const hasFiles = Array.isArray(req.body.attachments) && req.body.attachments.length > 0;
+ if ((!message && !hasFiles) || message.length > MAX_MESSAGE) {
+ return res.status(400).json({ error: `Write something or attach a picture (up to ${MAX_MESSAGE} characters)` });
}
}
const parentId = req.body.parent_id ? parseInt(req.body.parent_id) : null;
const parentId = req.body.parent_id ? parseInt(req.body.parent_id) : null;
const target = await visibleTarget(req.user, contentType, contentId);
const target = await visibleTarget(req.user, contentType, contentId);
@@ -216,6 +216,13 @@ async function check(name, fn) {
@@ -216,6 +216,13 @@ async function check(name, fn) {
{ method: 'POST', headers: { 'x-test-user': '5' }, body: form });
{ method: 'POST', headers: { 'x-test-user': '5' }, body: form });
assert.strictEqual(other.status, 404, 'a non-owner cannot upload to a private VOD');
assert.strictEqual(other.status, 404, 'a non-owner cannot upload to a private VOD');
assert.strictEqual((await call('POST', '/api/comments/vod/100', 5, { message: 'Too many', attachments: Array(5).fill(uploaded.attachment) })).status, 400);
assert.strictEqual((await call('POST', '/api/comments/vod/100', 5, { message: 'Too many', attachments: Array(5).fill(uploaded.attachment) })).status, 400);
+ // A picture alone is a comment (the owner, 11-12); nothing at all is still refused.
+ const quiet = await call('POST', '/api/comments/vod/100', 5, { message: '', attachments: [uploaded.attachment] });
+ assert.strictEqual(quiet.status, 201, quiet.text);
+ assert.strictEqual(last('POST', /\/comments$/).body.message, '', 'Community gets the picture with no words');
+ const bare = await call('POST', '/api/comments/vod/100', 5, { message: ' ' });
+ assert.strictEqual(bare.status, 400);
+ assert.match(bare.json.error, /Write something or attach a picture/);
});
});
await check('edit: the author only (as their subject); edits show as edited', async () => {
await check('edit: the author only (as their subject); edits show as edited', async () => {