forked from wgroeneveld/go-jamming
pingback receiving equals webmention receiving
This commit is contained in:
parent
a7a4714ea0
commit
7d4408080c
|
@ -1,8 +1,11 @@
|
|||
|
||||
const webmentionReceiver = require('./../webmention/receive')
|
||||
const config = require('./../config')
|
||||
const parser = require("fast-xml-parser")
|
||||
|
||||
/**
|
||||
See https://www.hixie.ch/specs/pingback/pingback#refsXMLRPC
|
||||
---
|
||||
Sample XML:
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<methodCall>
|
||||
|
@ -33,8 +36,14 @@ function validate(body) {
|
|||
return true
|
||||
}
|
||||
|
||||
// we treat a pingback as a webmention.
|
||||
// Wordpress pingback processing source: https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/pingback_ping/
|
||||
async function receive(body) {
|
||||
|
||||
const xml = parser.parse(body)
|
||||
await webmentionReceiver.receive({
|
||||
source: xml.methodCall.params.param[0].value.string,
|
||||
target: xml.methodCall.params.param[1].value.string
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -67,6 +67,10 @@ function route(router) {
|
|||
ctx.body = err(e)
|
||||
}
|
||||
});
|
||||
|
||||
router.put("pingback send endpoint", "/pingback/:domain/:token", async (ctx) => {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
describe("e2e tests", () => {
|
||||
|
||||
jest.disableAutomock()
|
||||
jest.unmock('got')
|
||||
|
||||
|
||||
const { mf2 } = require("microformats-parser");
|
||||
const got = require("got");
|
||||
|
||||
test.skip("microformat fiddling for non-indieweb sites", async () => {
|
||||
const html = (await got("https://kristienthoelen.be/2021/03/22/de-stadia-van-een-burn-out-in-welk-stadium-zit-jij/")).body
|
||||
const mf = mf2(html, {
|
||||
baseUrl: "https://kristienthoelen.be/"
|
||||
})
|
||||
|
||||
//console.log(mf)
|
||||
|
||||
const url = "https://kristienthoelen.be/wp-content/uploads/2021/03/burnoutbarometer.jpg"
|
||||
const occ = html.indexOf(url)
|
||||
const len = 100
|
||||
console.log(html.substring(occ - len, occ + url.length + len))
|
||||
|
||||
<a[^>]+?' . $preg_target . '[^>]*>([^>]+?)</a>
|
||||
})
|
||||
|
||||
})
|
|
@ -0,0 +1,52 @@
|
|||
|
||||
const fs = require('fs');
|
||||
const fsp = require('fs').promises;
|
||||
const { rmdir } = require('./../utils')
|
||||
|
||||
jest.mock('got');
|
||||
const md5 = require('md5')
|
||||
const { receive } = require('../../src/pingback/receive')
|
||||
const dumpdir = 'data/brainbaking.com'
|
||||
|
||||
describe("receive pingback process tests happy path", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
if(fs.existsSync(dumpdir)) {
|
||||
rmdir(dumpdir)
|
||||
}
|
||||
fs.mkdirSync(dumpdir, {
|
||||
recursive: true
|
||||
})
|
||||
})
|
||||
|
||||
function asFilename(body) {
|
||||
return `${dumpdir}/` + md5(`source=${body.source},target=${body.target}`)
|
||||
}
|
||||
|
||||
test("receive a pingback processes it just like a webmention", async () => {
|
||||
const body = {
|
||||
source: "https://brainbaking.com/valid-bridgy-twitter-source.html",
|
||||
target: "https://brainbaking.com/post/2021/03/the-indieweb-mixed-bag"
|
||||
}
|
||||
|
||||
await receive(`
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<methodCall>
|
||||
<methodName>pingback.ping</methodName>
|
||||
<params>
|
||||
<param>
|
||||
<value><string>${body.source}</string></value>
|
||||
</param>
|
||||
<param>
|
||||
<value><string>${body.target}</string></value>
|
||||
</param>
|
||||
</params>
|
||||
</methodCall>
|
||||
`)
|
||||
|
||||
const result = await fsp.readFile(`${asFilename(body)}.json`, 'utf-8')
|
||||
const data = JSON.parse(result)
|
||||
expect(data.content).toContain("Recommended read:")
|
||||
})
|
||||
|
||||
})
|
Loading…
Reference in New Issue