Skip to content

Commit

Permalink
Convert to arc functions
Browse files Browse the repository at this point in the history
Signed-off-by: macdonst <[email protected]>
  • Loading branch information
macdonst committed Jul 30, 2024
1 parent af481ff commit b7c0793
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/http/get-robots/index.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import arc from '@architect/functions'
import data from '@begin/data'
import { readFileSync } from 'node:fs'

const { airobotstxt } = await arc.tables()

async function get () {
// Do we have an updated robots.txt in the DB?
let result = await data.get({
table: 'ai-robots-txt',
let result = await airobotstxt.get({
key: 'agents',
})
let robots = result?.robotsTxt || ''
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,12 @@ module.exports = {
},
]
},
tables () {
return {
name: 'airobotstxt',
partitionKey: 'key',
partitionKeyType: 'string',
}
},
},
}
28 changes: 13 additions & 15 deletions src/scheduled/check-robots-txt-feed/index.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

import { parseStringPromise } from 'xml2js'
import data from '@begin/data'
import arc from '@architect/functions'

const { airobotstxt } = await arc.tables()

export async function handler () {
// check the release feed from https://github.com/ai-robots-txt/ai.robots.txt
const updated = await getFeedUpdated()

// get the last time we checked
let result = await data.get({
table: 'ai-robots-txt',
const result = await airobotstxt.get({
key: 'updated',
})

Expand Down Expand Up @@ -38,15 +38,13 @@ async function getFeedUpdated () {
}

async function updateDB ({ lastUpdated, robotsTxt }) {
return await data.set([
{
table: 'ai-robots-txt',
key: 'updated',
lastUpdated,
}, {
table: 'ai-robots-txt',
key: 'agents',
robotsTxt,
},
])
await airobotstxt.put({
key: 'updated',
lastUpdated,
})
await airobotstxt.put({
key: 'agents',
robotsTxt,
})
return
}

0 comments on commit b7c0793

Please sign in to comment.