Browse Source

Version 0.0.6: New "--start" and "--end" parameters for recorder-to-html (#7)

develop
ar 2 years ago
parent
commit
c877ac287e
3 changed files with 60 additions and 11 deletions
  1. 5
    0
      CHANGELOG.md
  2. 2
    2
      package.json
  3. 53
    9
      recorder-to-html.js

+ 5
- 0
CHANGELOG.md View File

@@ -1,5 +1,10 @@
# Changelog for Matrix Recorder

## Changes in v0.0.6 (2017-10-18)

- recorder-to-html now allows to only export a time segment (thanks to dvoitsek, #7)
- Bumped matrix-js-sdk to 0.7.13 (breaking changes in 0.8 have to wait)

## Changes in v0.0.5 (2017-09-28)

- Bugfix: Homeserver URL should allow port numbers

+ 2
- 2
package.json View File

@@ -1,6 +1,6 @@
{
"name": "matrix-recorder",
"version": "0.0.3",
"version": "0.0.6",
"description": "A recorder that can record Matrix rooms you are a member of (including E2E-encrypted rooms).",
"author": "Hello Matrix <[email protected]>",
"main": "matrix-recorder.js",
@@ -13,7 +13,7 @@
},
"dependencies": {
"marked": "^0.3.6",
"matrix-js-sdk": "^0.7.10",
"matrix-js-sdk": "^0.7.13",
"mime-types": "^2.1.14",
"mustache": "^2.3.0",
"node-fetch": "^1.6.3",

+ 53
- 9
recorder-to-html.js View File

@@ -10,10 +10,29 @@ const fs = require('fs');
// Use marked
const marked = require('marked');

// Has a directory been given on the command line?
// Otherwise show information message.
// The target directory must be provided as first command line option
// All optional parameters can follow afterwards
var targetDir = process.argv[2];

var date_start;
var date_end;
for(let i = 3; i < process.argv.length; ++i) {
switch(process.argv[i]) {
case "--start":
date_start = new Date(process.argv[i+1]);
++i;
break;
case "--end":
date_end = new Date(process.argv[i+1]);
++i;
break;
default:
console.log("No reader for option %s", process.argv[i])
}
}

// Has a directory been given on the command line?
// Otherwise show information message.
if(targetDir === undefined) {
console.log('You need to give Recorder-to-HTML the name of the Matrix Recorder directory that contains the sqlite database to convert, like that:\n\n node recorder-to-html.js ./my_matrix_log\n\n');
process.exit(1);
@@ -52,8 +71,6 @@ try {
process.exit(1);
}



// Load sqlite3 module
const sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(path.join(targetDir, 'messages.sqlite'));
@@ -69,6 +86,26 @@ var roomFiles = {};
var rooms = [];
var fileNames = {};

// The WHERE query used for all events to be retrieved
var where_elements = [ "event_type IN ('m.room.member', 'm.room.message')" ];

// Limit start of the events to retrieve
if(date_start) {
where_elements.push("event_date >= $date_start");
}

// Limit end of the events to retrieve
if(date_end) {
where_elements.push("event_date <= $date_end");
}

// Combine
var where_string = where_elements.join(" AND ");

// The parameter object to be bound to the WHERE elements
var where_parameters = { $date_start: date_start, $date_end: date_end };


// Copy static files style.css, welcome.html
console.log('Copying style.css...');
copyFile('templates/style.css', path.join(targetDir, 'html', 'style.css'))
@@ -104,7 +141,7 @@ copyFile('templates/style.css', path.join(targetDir, 'html', 'style.css'))
function() {
// Note that we only show rooms with at least one message in them.
console.log('Retrieving all rooms from database...');
return promiseDbAll("SELECT DISTINCT room_id, room_name, event_date FROM events_received WHERE event_type IN ('m.room.member', 'm.room.message') ORDER BY room_id, event_date DESC");
return promiseDbAll("SELECT DISTINCT room_id, room_name, event_date FROM events_received WHERE " + where_string + " ORDER BY room_id, event_date DESC", where_parameters);
}
)
.then(
@@ -136,7 +173,8 @@ copyFile('templates/style.css', path.join(targetDir, 'html', 'style.css'))
return new Promise(function(resolve, reject) {
var prevRoom = '';
var roomTimeline = [];
db.each("SELECT * FROM events_received WHERE event_type IN ('m.room.member', 'm.room.message') ORDER BY room_id, event_date",

db.each("SELECT * FROM events_received WHERE " + where_string + " ORDER BY room_id, event_date", where_parameters,
// Called on every row
function(err, row) {
if(err) {
@@ -285,15 +323,21 @@ function copyFile(source, target) {


// Promised version of db.all
function promiseDbAll(query) {
function promiseDbAll(query, query_parameters) {
return new Promise(function(resolve, reject) {
db.all(query, function (err, rows) {
var callbackFunction = function (err, rows) {
if (err) {
reject(err);
} else {
resolve(rows);
}
});
};
if(query_parameters) {
db.all(query, query_parameters, callbackFunction);
} else {
db.all(query, callbackFunction);
}
});
}


Loading…
Cancel
Save