Accept Announce, handle content-not-included, correct DB inserts.
This commit is contained in:
parent
053f1e6fa1
commit
c4bd237051
1 changed files with 8 additions and 8 deletions
|
@ -3,6 +3,7 @@
|
|||
var db = require('../lib/db');
|
||||
var express = require('express');
|
||||
var jsonld = require('jsonld');
|
||||
const http_agent = require('../lib/http_agent');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
|
@ -12,12 +13,15 @@ module.exports = {
|
|||
routeObj.post(async (req, res, _next) => {
|
||||
if ( req.body ) {
|
||||
var bodyParsed = await jsonld.compact(req.body, 'https://www.w3.org/ns/activitystreams');
|
||||
if ( bodyParsed.type === 'Create') {
|
||||
if ( bodyParsed.type === 'Create' || bodyParsed.type === 'Announce' ) {
|
||||
var to;
|
||||
var cc;
|
||||
if ( typeof bodyParsed.object === 'string' ) {
|
||||
res.status(422);
|
||||
res.body('Unimplemented');
|
||||
bodyParsed.object = await jsonld.compact(await http_agent.request(bodyParsed.object, {actor: `https://${req.hostname}/actor`}), 'https://www.w3.org/ns/activitystreams');
|
||||
}
|
||||
var result = await db("inbox").where({origin: bodyParsed.object.id});
|
||||
if ( result[0] ) {
|
||||
res.status(204);
|
||||
return res.end();
|
||||
}
|
||||
if ( typeof bodyParsed.object.to === 'string' ) {
|
||||
|
@ -31,7 +35,7 @@ module.exports = {
|
|||
cc = bodyParsed.object.cc;
|
||||
}
|
||||
await db('inbox').insert({
|
||||
origin: bodyParsed.object.attributedTo,
|
||||
origin: bodyParsed.object.id,
|
||||
to: JSON.stringify(to),
|
||||
cc: JSON.stringify(cc),
|
||||
object: JSON.stringify(
|
||||
|
@ -42,10 +46,6 @@ module.exports = {
|
|||
});
|
||||
res.status(204);
|
||||
return res.end();
|
||||
} else if ( bodyParsed.type === 'Announce' ) {
|
||||
res.status(422);
|
||||
res.body('Unimplemented');
|
||||
return res.end();
|
||||
} else {
|
||||
res.status(422);
|
||||
res.body('Unimplemented');
|
||||
|
|
Loading…
Add table
Reference in a new issue