Commit fceb94f4 authored by les's avatar les
Browse files

following from other node

parent c8e6e421
......@@ -6,10 +6,11 @@ const get = require('lodash/get')
const crypto = require('crypto')
const request = require('request')
function signAndSend(message, usre, domain, req, res, targetOrigin) {
function signAndSend(message, user, domain, req, res, targetOrigin) {
// get the URI of the actor object and append 'inbox' to it
let inbox = message.object.actor+'/inbox'
let inboxFragment = inbox.replace(targetOrigin,'')
const targetDomain = new URL(targetOrigin).host
// get the private key
const privkey = user.rsa.privateKey
const signer = crypto.createSign('sha256')
......@@ -19,12 +20,11 @@ function signAndSend(message, usre, domain, req, res, targetOrigin) {
signer.end()
const signature = signer.sign(privkey)
const signature_b64 = signature.toString('base64')
let header = `keyId="${config.baseurl}/federation/u/${name}",headers="(request-target) host date",signature="${signature_b64}"`
console.error('vado di request accept !')
let header = `keyId="${config.baseurl}/federation/u/${user.username}",headers="(request-target) host date",signature="${signature_b64}"`
request({
url: inbox,
headers: {
'Host': new URL(targetOrigin).host,
'Host': targetDomain,
'Date': d.toUTCString(),
'Signature': header
},
......@@ -42,7 +42,7 @@ function signAndSend(message, usre, domain, req, res, targetOrigin) {
return res.status(200);
}
function sendAcceptMessage (body, user, req, res, targetOrigin) {
function sendAcceptMessage (body, user, domain, req, res, targetOrigin) {
const guid = crypto.randomBytes(16).toString('hex')
let message = {
'@context': 'https://www.w3.org/ns/activitystreams',
......@@ -73,8 +73,7 @@ router.post('/inbox', async (req, res) => {
console.error('FOLLOWERS ', user.followers)
if (user.followers.indexOf(b.actor) === -1) {
console.error('ok this is a new follower: ', b.actor)
user.followers.push(b.actor)
await user.save()
await user.update({ followers: [...user.followers, b.actor] })
}
break
......
const express = require('express')
const router = express.Router()
const { user: User } = require('../api/models')
const settingsController = require('../api/controllers/settings')
const settingsController = require('../api/controller/settings')
const config = require('config')
const version = require('../../package.json').version
......@@ -15,7 +15,7 @@ router.get('/', async (req, res) => {
version
},
protocols: ['activitypub'],
openRegistrations: settingsControllers.settings.allow_registration,
openRegistrations: settingsController.settings.allow_registration,
usage:{
users: {
total: 10
......
......@@ -14,7 +14,7 @@ router.get('/', async (req, res) => {
const user = await User.findOne({where: { username: name } })
if (!user) return res.status(404).send(`No record found for ${name}`)
const ret = {
subject: `acct:${name}@${host}`,
subject: `acct:${name}@${domain}`,
links: [
{
rel: 'self',
......
......@@ -3,6 +3,7 @@ const path = require('path')
const express = require('express')
const consola = require('consola')
const morgan = require('morgan')
const bodyParser = require('body-parser')
const cors = require('cors')
const { Nuxt, Builder } = require('nuxt')
......@@ -29,11 +30,14 @@ async function start() {
app.use(morgan('dev'))
app.use('/media/', express.static(config.upload_path))
// gancio standard api
app.use('/api', require('./api/index'))
// federation api / activitypub / webfinger / nodeinfo
app.use('/.well-known/webfinger', cors(), require('./federation/webfinger'))
app.use('/.well-known/x-nodeinfo2', cors(), require('./federation/nodeinfo'))
app.use('/federation', cors(), require('./federation'))
app.use('/federation', cors(), bodyParser.join({type: 'applicatoin/activity+json'}), require('./federation'))
// Give nuxt middleware to express
app.use(nuxt.render)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment