-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (34 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require("express");
const app = express();
let statuses;
let tags = [];
const { Transform } = require("stream");
app.listen(3001, () => console.log("Listening at port 3001"));
require("dotenv").config();
const Mastodon = require("mastodon-api");
const mastoStream = new Mastodon({
access_token: process.env.AUTH_TOKEN,
api_url: "https://hachyderm.io/api/v1/",
});
const datastore = require("nedb");
const db = new datastore("./database.db");
db.loadDatabase();
const listener = mastoStream.stream("streaming/public");
app.get("/", function (req, res) {
listener.on("message", (msg) => {
if (msg.event === "update" && msg.data.tags !== []) {
console.log(msg.event, msg.data.uri, msg.data.tags);
// if (msg.data.tags.length > 1) {
// msg.data.tags = msg.data.tags.flat();
// }
db.insert(msg.data.tags);
// statuses += msg.data.tags;
// // console.log(statuses);
// db.insert(msg.data.tags);
// db.insert(",");
// tags.push(JSON.stringify(msg.data.tags));
}
// console.log(tags);
});
});
listener.on("error", (err) => console.log(err));