move wm token to a parameter

This commit is contained in:
Wouter Groeneveld 2022-04-25 09:26:26 +02:00
parent 886f610e1c
commit 47a905747d
7 changed files with 38 additions and 28 deletions

View File

@ -158,19 +158,26 @@ Working example: https://jefklakscodex.com/articles/reviews/diablo-3/ (on the le
### 5. Webmentions
In cooperation with https://github.com/wgroeneveld/serve-my-jams
In cooperation with https://github.com/wgroeneveld/go-jamming
#### 5.1 `getWebmentions`
Calls the get webmention endpoint, sorts by date, adds metadata such as relative date (`relativeTarget`, property), and returns data. Could be written in a `data` folder for Hugo to parse, for example.
Parameters: just one, the `domain`.
Parameters: first `domain`, second the config for the endpoint and token. Usage example:
```js
await getWebmentions("brainbaking.com", {
endpoint: 'https://jam.brainbaking.com',
token: 'lol'
})
````
#### 5.1 `send`
Calls the set webmention endpoint using a `PUT`. Based on the RSS feed located at `/index.xml`, see the [go-jamming](github.com/wgroeneveld/go-jamming) README.
Calls the set webmention endpoint using a `PUT`. Based on the RSS feed, see the [go-jamming](github.com/wgroeneveld/go-jamming) README.
Parameters: just one, the `domain`.
Same as `getWebmentions`.
### 6. YouTube

View File

@ -1,11 +0,0 @@
const serveMyJamToken = "miauwkes"
const serveMyJamEndpoint = "https://jam.brainbaking.com"
// see https://github.com/wgroeneveld/serve-my-jams
// don't care if token is visible, just an extra security-by-obscurity step, everything is public anyway
module.exports = {
serveMyJamEndpoint,
serveMyJamToken
}

View File

@ -1,13 +1,12 @@
const got = require('got')
const config = require('../config')
const dayjs = require('dayjs')
const relativeTime = require('dayjs/plugin/relativeTime')
dayjs.extend(relativeTime)
async function getWebmentions(domain) {
const url = `${config.serveMyJamEndpoint}/webmention/${domain}/${config.serveMyJamToken}`
async function getWebmentions(domain, config) {
const url = `${config.endpoint}/webmention/${domain}/${config.token}`
const result = await got(url)
if(!result.body || !result.body) {

View File

@ -1,12 +1,11 @@
const got = require('got')
const config = require('../config')
const fsp = require('fs').promises
const dayjs = require('dayjs')
async function sendWebmentions(domain) {
const url = `${config.serveMyJamEndpoint}/webmention/${domain}/${config.serveMyJamToken}`
async function sendWebmentions(domain, config) {
const url = `${config.endpoint}/webmention/${domain}/${config.token}`
// this is an async call and will return 202 to say "started sending them out".
const result = await got.put(url)

View File

@ -7,9 +7,13 @@ const domain = "brainbaking.com"
describe("webmention receive scenario test", () => {
// this tests against the real endpoint, meaning the token has to be correct.
test("getWebmentions fetches anything at all", async () => {
const result = await getWebmentions(domain)
expect(result.length).toBeGreaterThan(-1)
const result = await getWebmentions(domain, {
token: 'miauwkes',
endpoint: 'https://jam.brainbaking.com'
})
//expect(result.length).toBeGreaterThan(-1)
})
})

View File

@ -9,12 +9,18 @@ describe("webmention receive serve-my-jam tests", () => {
MockDate.set(dayjs('2021-03-11T19:00:00').toDate())
test("getWebmentions fetches from serve-my-jam depending on config", async () => {
const result = await getWebmentions(domain)
const result = await getWebmentions(domain, {
token: 'miauwkes',
endpoint: 'https://jam.brainbaking.com'
})
expect(result.length).toBe(4)
})
test("getWebmentions enriches data with relatiave url", async () => {
const result = await getWebmentions(domain)
const result = await getWebmentions(domain, {
token: 'miauwkes',
endpoint: 'https://jam.brainbaking.com/'
})
const mention = result[0]
expect(mention.relativeTarget).toEqual("/post/2021/02/my-retro-desktop-setup/")
@ -22,7 +28,10 @@ describe("webmention receive serve-my-jam tests", () => {
})
test("getWebmentions are sorted by published date descending", async() => {
const result = await getWebmentions(domain)
const result = await getWebmentions(domain, {
token: 'miauwkes',
endpoint: 'https://jam.brainbaking.com'
})
expect(result[0].published).toEqual("2021-03-08T18:35:24")
expect(result[1].published).toEqual("2021-03-08T17:14:25")

View File

@ -14,8 +14,11 @@ describe("webmention send serve-my-jam tests", () => {
test("sendWebmentions", async() => {
await sendWebmentions('brainbaking.com')
expect(calledPut).toBe("https://jam.brainbaking.com/webmention/brainbaking.com/miauwkes")
await sendWebmentions('brainbaking.com', {
token: 'lol',
endpoint: 'https://jam.brainbaking.com'
})
expect(calledPut).toBe("https://jam.brainbaking.com/webmention/brainbaking.com/lol")
})
})