Add json param to /transcript

6cb82fc21e3fc7996b5f3c4a1e480890038e47da

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +4 -1Showing whitespace changes
src/endpoints/search.js+4 -1
@@ -60,6 +60,7 @@ router.post('/transcript', jsonParser, async (request, response) => {
60 const RE_XML_TRANSCRIPT = /<text start="([^"]*)" dur="([^"]*)">([^<]*)<\/text>/g;60 const RE_XML_TRANSCRIPT = /<text start="([^"]*)" dur="([^"]*)">([^<]*)<\/text>/g;
61 const id = request.body.id;61 const id = request.body.id;
62 const lang = request.body.lang;62 const lang = request.body.lang;
63 const json = request.body.json;
6364
64 if (!id) {65 if (!id) {
65 console.log('Id is required for /transcript');66 console.log('Id is required for /transcript');
@@ -129,7 +130,9 @@ router.post('/transcript', jsonParser, async (request, response) => {
129 // The text is double-encoded130 // The text is double-encoded
130 const transcriptText = transcript.map((line) => he.decode(he.decode(line.text))).join(' ');131 const transcriptText = transcript.map((line) => he.decode(he.decode(line.text))).join(' ');
131132
132 return response.send(transcriptText);133 return json
134 ? response.json({ transcript: transcriptText, html: videoPageBody })
135 : response.send(transcriptText);
133 } catch (error) {136 } catch (error) {
134 console.log(error);137 console.log(error);
135 return response.sendStatus(500);138 return response.sendStatus(500);