Allow to execute locally on macOS

Small fixes were necessary to run today on macOS. I've also added some
debugging `console.log` around to understand better what is going on.
This commit is contained in:
Rafael Caricio 2022-06-26 20:27:05 +02:00
parent 8c2349ade6
commit 0a1d84b753
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
5 changed files with 10 additions and 5 deletions

View file

@ -18,7 +18,7 @@ This requires Node.js v10.10.0 or above.
Clone the repository, then `cd` into its root directory. Install dependencies: Clone the repository, then `cd` into its root directory. Install dependencies:
`npm i` `CXXFLAGS="--std=c++17" npm i`
Copy `config-template.json` to `config.json`. Copy `config-template.json` to `config.json`.

View file

@ -4,7 +4,7 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"better-sqlite3": "^5.4.0", "better-sqlite3": "^7.5.3",
"body-parser": "^1.18.3", "body-parser": "^1.18.3",
"cors": "^2.8.4", "cors": "^2.8.4",
"express": "^4.16.3", "express": "^4.16.3",

View file

@ -103,7 +103,7 @@ function sendCreateMessage(text, name, domain, req, res) {
console.log(followers); console.log(followers);
console.log('type',typeof followers); console.log('type',typeof followers);
if (followers === null) { if (followers === null) {
console.log('aaaa'); console.log(`warn: No followers for account ${name}@${domain}`);
res.status(400).json({msg: `No followers for account ${name}@${domain}`}); res.status(400).json({msg: `No followers for account ${name}@${domain}`});
} }
else { else {

View file

@ -71,16 +71,19 @@ function parseJSON(text) {
router.post('/', function (req, res) { router.post('/', function (req, res) {
// pass in a name for an account, if the account doesn't exist, create it! // pass in a name for an account, if the account doesn't exist, create it!
let domain = req.app.get('domain'); let domain = req.app.get('domain');
console.log(`Received ${JSON.stringify(req.body)}`);
const myURL = new URL(req.body.actor); const myURL = new URL(req.body.actor);
let targetDomain = myURL.hostname; let targetDomain = myURL.hostname;
// TODO: add "Undo" follow event // TODO: add "Undo" follow event
if (typeof req.body.object === 'string' && req.body.type === 'Follow') { if (typeof req.body.object === 'string' && req.body.type === 'Follow') {
let name = req.body.object.replace(`https://${domain}/u/`,''); let name = req.body.object.replace(`http://${domain}/u/`,'');
sendAcceptMessage(req.body, name, domain, req, res, targetDomain); sendAcceptMessage(req.body, name, domain, req, res, targetDomain);
// Add the user to the DB of accounts that follow the account // Add the user to the DB of accounts that follow the account
let db = req.app.get('db'); let db = req.app.get('db');
// get the followers JSON for the user // get the followers JSON for the user
let result = db.prepare('select followers from accounts where name = ?').get(`${name}@${domain}`); const username = `${name}@${domain}`;
console.log(`Trying to find name in db = ${username}`);
let result = db.prepare('select followers from accounts where name = ?').get(username);
if (result === undefined) { if (result === undefined) {
console.log(`No record found for ${name}.`); console.log(`No record found for ${name}.`);
} }

View file

@ -3,8 +3,10 @@ const express = require('express'),
router = express.Router(); router = express.Router();
router.get('/', function (req, res) { router.get('/', function (req, res) {
console.log("here....");
let resource = req.query.resource; let resource = req.query.resource;
if (!resource || !resource.includes('acct:')) { if (!resource || !resource.includes('acct:')) {
console.log("nothing in the query");
return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.'); return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.');
} }
else { else {