mirror of https://github.com/Siphonay/mastodon
Add check for missing tag param in streaming API (#8955)
* Add check for missing tag param in streaming API Fixes error: ``` TypeError: Cannot read property 'toLowerCase' of undefined at app.get (.../streaming/index.js:493:50) ``` * Fix code style issues
This commit is contained in:
parent
e6c01171de
commit
18e7ef6eda
|
@ -449,6 +449,11 @@ const startWorker = (workerId) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const httpNotFound = res => {
|
||||||
|
res.writeHead(404, { 'Content-Type': 'application/json' });
|
||||||
|
res.end(JSON.stringify({ error: 'Not found' }));
|
||||||
|
};
|
||||||
|
|
||||||
app.use(setRequestId);
|
app.use(setRequestId);
|
||||||
app.use(setRemoteAddress);
|
app.use(setRemoteAddress);
|
||||||
app.use(allowCrossDomain);
|
app.use(allowCrossDomain);
|
||||||
|
@ -490,11 +495,25 @@ const startWorker = (workerId) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/v1/streaming/hashtag', (req, res) => {
|
app.get('/api/v1/streaming/hashtag', (req, res) => {
|
||||||
streamFrom(`timeline:hashtag:${req.query.tag.toLowerCase()}`, req, streamToHttp(req, res), streamHttpEnd(req), true);
|
const { tag } = req.query;
|
||||||
|
|
||||||
|
if (!tag || tag.length === 0) {
|
||||||
|
httpNotFound(res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
streamFrom(`timeline:hashtag:${tag.toLowerCase()}`, req, streamToHttp(req, res), streamHttpEnd(req), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/v1/streaming/hashtag/local', (req, res) => {
|
app.get('/api/v1/streaming/hashtag/local', (req, res) => {
|
||||||
streamFrom(`timeline:hashtag:${req.query.tag.toLowerCase()}:local`, req, streamToHttp(req, res), streamHttpEnd(req), true);
|
const { tag } = req.query;
|
||||||
|
|
||||||
|
if (!tag || tag.length === 0) {
|
||||||
|
httpNotFound(res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
streamFrom(`timeline:hashtag:${tag.toLowerCase()}:local`, req, streamToHttp(req, res), streamHttpEnd(req), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/v1/streaming/list', (req, res) => {
|
app.get('/api/v1/streaming/list', (req, res) => {
|
||||||
|
@ -502,8 +521,7 @@ const startWorker = (workerId) => {
|
||||||
|
|
||||||
authorizeListAccess(listId, req, authorized => {
|
authorizeListAccess(listId, req, authorized => {
|
||||||
if (!authorized) {
|
if (!authorized) {
|
||||||
res.writeHead(404, { 'Content-Type': 'application/json' });
|
httpNotFound(res);
|
||||||
res.end(JSON.stringify({ error: 'Not found' }));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,9 +571,19 @@ const startWorker = (workerId) => {
|
||||||
streamFrom(channel, req, streamToWs(req, ws), streamWsEnd(req, ws, subscriptionHeartbeat(channel)), true);
|
streamFrom(channel, req, streamToWs(req, ws), streamWsEnd(req, ws, subscriptionHeartbeat(channel)), true);
|
||||||
break;
|
break;
|
||||||
case 'hashtag':
|
case 'hashtag':
|
||||||
|
if (!location.query.tag || location.query.tag.length === 0) {
|
||||||
|
ws.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
streamFrom(`timeline:hashtag:${location.query.tag.toLowerCase()}`, req, streamToWs(req, ws), streamWsEnd(req, ws), true);
|
streamFrom(`timeline:hashtag:${location.query.tag.toLowerCase()}`, req, streamToWs(req, ws), streamWsEnd(req, ws), true);
|
||||||
break;
|
break;
|
||||||
case 'hashtag:local':
|
case 'hashtag:local':
|
||||||
|
if (!location.query.tag || location.query.tag.length === 0) {
|
||||||
|
ws.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
streamFrom(`timeline:hashtag:${location.query.tag.toLowerCase()}:local`, req, streamToWs(req, ws), streamWsEnd(req, ws), true);
|
streamFrom(`timeline:hashtag:${location.query.tag.toLowerCase()}:local`, req, streamToWs(req, ws), streamWsEnd(req, ws), true);
|
||||||
break;
|
break;
|
||||||
case 'list':
|
case 'list':
|
||||||
|
|
Loading…
Reference in New Issue