Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contacts endpoint #21

Merged
merged 2 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app.arc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ categories
logs
id *String
expires TTL
contacts
nickname *String

@indexes
posts
Expand Down
31 changes: 31 additions & 0 deletions scripts/contacts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"contacts": [
{
"name": "Barry Frost",
"nickname": "barryfrost.com",
"url": "https://barryfrost.com/",
"silos": {
"twitter": "barryf"
},
"_internal_url": "https://barryfrost.com/contacts/barryfrost-com"
},
{
"name": "Jamie Tanna",
"nickname": "www.jvt.me",
"url": "https://www.jvt.me/",
"silos": {
"twitter": "jamietanna"
},
"_internal_url": "https://barryfrost.com/contacts/www-jvt-me"
},
{
"name": "Aaron Parecki",
"nickname": "aaronparecki.com",
"url": "https://aaronparecki.com/",
"silos": {
"twitter": "aaronpk"
},
"_internal_url": "https://barryfrost.com/contacts/aaronparecki-com"
}
]
}
7 changes: 6 additions & 1 deletion scripts/sandbox-startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ async function startup () {

const webmentionsRaw = fs.readFileSync(path.join(__dirname, '/webmentions.json'), 'utf8')
const webmentions = JSON.parse(webmentionsRaw)

for (const item of webmentions.items) {
const id = `${item.source} ${item.target}`
await data.webmentions.put({ ...item, id })
}

const contactsRaw = fs.readFileSync(path.join(__dirname, '/contacts.json'), 'utf8')
const contacts = JSON.parse(contactsRaw)
for (const c of contacts.contacts) {
await data.contacts.put(c)
}
}

(async () => {
Expand Down
25 changes: 25 additions & 0 deletions src/http/get-micropub/config/contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const arc = require('@architect/functions')

async function contact (filter = '') {
if (filter) {
filter = filter.toLowerCase().replace(/[^a-z0-9-]/, '')
}
const data = await arc.tables()
const results = await data.contacts.scan({})
const contacts = results.Items.map(c => {
if (filter) {
if (c.nickname.startsWith(filter)) {
return c
} else {
return null
}
Comment on lines +13 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed, as it'd return null / undefined anyway?

Suggested change
} else {
return null
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the following from Standard.js without returning the null:

Array.prototype.map() expects a value to be returned at the end of arrow function. (array-callback-return)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - fair enough!

} else {
return c
}
}).filter((el) => el != null) // remove nulls
.filter((v, i, a) => a.indexOf(v) === i) // unique
.sort()
return contacts
}

module.exports = contact
7 changes: 5 additions & 2 deletions src/http/get-micropub/config/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const syndicateTo = require('./syndicate-to')
const category = require('./category')
const postTypes = require('./post-types')
const contact = require('./contact')

const channels = [
{
Expand All @@ -19,7 +20,8 @@ const q = [
'source',
'post-types',
'category',
'channels'
'channels',
'contact'
]

const config = {
Expand All @@ -36,5 +38,6 @@ module.exports = {
postTypes,
syndicateTo,
category,
channels
channels,
contact
}
2 changes: 2 additions & 0 deletions src/http/get-micropub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ exports.handler = async function http (req) {
return await source(params, authResponse.scopes)
case 'post-types':
return await { 'post-types': config.postTypes }
case 'contact':
return await config.contact(params.filter)
}
}
return {
Expand Down