Skip to content

Commit

Permalink
Update logging code
Browse files Browse the repository at this point in the history
No more files, logging is done with sqlite (in almond-server)
  • Loading branch information
gcampax committed Jun 22, 2021
1 parent c3b630c commit 82e85ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 59 deletions.
27 changes: 9 additions & 18 deletions public/javascripts/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $(() => {
else
to_do = 'remove';

manageSpinner(to_do)
manageSpinner(to_do);
}

function manageLostConnectionMsg(todo) {
Expand Down Expand Up @@ -458,22 +458,13 @@ $(() => {
});

$('#save-log').click(() => {
$.post(baseUrl + '/recording/save', {
id: conversationId,
_csrf: document.body.dataset.csrfToken
}).then((res) => {
if (res.status === 'ok') {
$.get(baseUrl + '/recording/log/' + conversationId).then((res) => {
if (res.status === 'ok') {
$('#recording-log').text(res.log);
const email = 'oval-bug-reports@lists.stanford.edu';
const subject = 'Almond Conversation Log';
const body = encodeURIComponent(res.log);
$('#recording-share').prop('href', `mailto:${email}?subject=${subject}&body=${body}`);
$('#recording-save').modal('toggle');
}
});
}
$.get(baseUrl + '/recording/log/' + conversationId + '.txt').then((res) => {
$('#recording-log').text(res);
const email = 'oval-bug-reports@lists.stanford.edu';
const subject = 'Almond Conversation Log';
const body = encodeURIComponent(res);
$('#recording-share').prop('href', `mailto:${email}?subject=${subject}&body=${body}`);
$('#recording-save').modal('toggle');
});
});

Expand All @@ -498,4 +489,4 @@ $(() => {
}
});
});
});
});
48 changes: 7 additions & 41 deletions src/routes/recording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//
// Author: Silei Xu <silei@cs.stanford.edu>

import * as fs from 'fs';
import express from 'express';

import * as user from '../util/user';
Expand Down Expand Up @@ -114,53 +113,20 @@ router.post('/comment', (req, res, next) => {
}).catch(next);
});

router.post('/save', (req, res, next) => {
const engine = req.app.genie;

Promise.resolve().then(() => {
return engine.assistant.getConversation(req.body.id);
}).then((conversation) => {
if (!conversation) {
res.status(404);
return res.json({ error: 'No conversation found' });
} else {
return conversation.saveLog().then(() => res.json({ status:'ok' }));
}
}).catch(next);
});

router.get('/log/:id.txt', (req, res, next) => {
const engine = req.app.genie;

Promise.resolve().then(() => {
return engine.assistant.getConversation((req.params as any).id);
}).then((conversation) => {
if (!conversation || !conversation.log) {
const conversation = engine.assistant.getConversation((req.params as any).id);
if (!conversation) {
res.status(404);
res.json({ error: 'No conversation found' });
} else {
res.set('Content-Type', 'text/plain');
res.set('Content-Disposition', `attachment; filename="log-${conversation.id}.txt"`);
fs.createReadStream(conversation.log).pipe(res);
res.send('No conversation found');
return;
}
}).catch(next);
});

router.get('/log/:id', (req, res, next) => {
const engine = req.app.genie;

Promise.resolve().then(() => {
return engine.assistant.getConversation(req.params.id);
}).then((conversation) => {
if (!conversation || !conversation.log) {
res.status(404);
res.json({ error: 'No conversation found' });
} else {
res.json({
status: 'ok',
log: fs.readFileSync(conversation.log, 'utf-8')
});
}
res.set('Content-Type', 'text/plain');
res.set('Content-Disposition', `attachment; filename="log-${conversation.id}.txt"`);
conversation.readLog().pipe(res);
}).catch(next);
});

Expand Down

0 comments on commit 82e85ef

Please sign in to comment.