console.log('================================================================='); console.log('hello and welcome to the file converter from Mastodon outbox JSON'); console.log('================================================================='); const express = require('express'); const pug = require('pug'); const app = express(); var fs = require('fs'); var listenPort = 8088; var jsonParsedLikes, jsonParsedOutbox; /** * export configuration. * You can filter the export in the following vars */ const min_length = 1; // minmum character length of toots to display const max_toots = Infinity; // maximum length const filterBiggerTootsBeforeSlicing = false; // filter only long toots const filterOnlyHavingMedias = true; // filter only toots having medias const displayMedias = false; // filter only toots having medias const writeStatsJson = false; // filter only toots having medias const showMostRecentTootsOnTop = true; // filter only toots having medias const TemplateVars = { pageTitle : 'Mastodon export converter to HTML', likes : jsonParsedLikes, outbox : jsonParsedOutbox, outboxStatistics : {}, outbox_all : jsonParsedOutbox, min_length, max_toots, filterOnlyHavingMedias, filterBiggerTootsBeforeSlicing, writeStatsJson, showMostRecentTootsOnTop, displayMedias, }; const masto_converter = require('./conversion'); console.log('masto_converter', masto_converter); masto_converter.conversion.hello(); jsonParsedLikes = masto_converter.conversion.likes(); fs.readFile('source_data/outbox.json', // callback function that is called when reading file is done function (err, data) { let toots; // parse json jsonParsedOutbox = JSON.parse(data); toots = jsonParsedOutbox.orderedItems; // access elements console.log('outbox toots length', toots.length); TemplateVars.outboxTotalLength = toots.length; toots = jsonParsedOutbox.orderedItems; if (filterOnlyHavingMedias) { toots = masto_converter.conversion.filterOnlyTootsWithMedias(toots); console.log('toots.length only attachements', toots.length); } toots = masto_converter.conversion.filterToots(toots, TemplateVars); console.log('min_chars', min_length); console.log('toots min char corresponding', toots.length); TemplateVars.outbox = toots; TemplateVars.outboxStatistics = masto_converter.conversion.makeStatsForToots(toots); const example = TemplateVars.outbox[1]['object']; TemplateVars.example = example; // console.log('example', example) if (writeStatsJson) { fs.writeFile('output/statistics.json', JSON.stringify(TemplateVars.outboxStatistics), errfileHandler); } }); const errfileHandler = (err) => { if (err) console.log(err); else { console.log('File statistics written successfully\n'); } }; app.use(express.static('public')); app.set('view engine', 'pug'); app.get('/', (req, res) => { const html = pug.render('index.pug', TemplateVars); // fs.writeFile('output/my_toots.html', html, errfileHandler); res.render('index.pug', TemplateVars); masto_converter.conversion.fetchUserInfo(); }); masto_converter.conversion.fetchUserInfo(); app.listen(listenPort, () => console.log(`Server is live at http://localhost:${listenPort}`)); console.log('================================================================='); console.log('made by Tykayn from CipherBliss - https://mastodon.cipherbliss.com/@tykayn'); console.log('=================================================================');