From b7c0793e1bdfb3bb2d3033ba04fa3e85b59c79f7 Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 30 Jul 2024 14:47:08 -0400 Subject: [PATCH] Convert to arc functions Signed-off-by: macdonst --- src/http/get-robots/index.mjs | 6 ++-- src/index.js | 7 +++++ src/scheduled/check-robots-txt-feed/index.mjs | 28 +++++++++---------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/http/get-robots/index.mjs b/src/http/get-robots/index.mjs index deb9752..dfded9d 100644 --- a/src/http/get-robots/index.mjs +++ b/src/http/get-robots/index.mjs @@ -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 || '' diff --git a/src/index.js b/src/index.js index 725d40e..5aefc08 100644 --- a/src/index.js +++ b/src/index.js @@ -25,5 +25,12 @@ module.exports = { }, ] }, + tables () { + return { + name: 'airobotstxt', + partitionKey: 'key', + partitionKeyType: 'string', + } + }, }, } diff --git a/src/scheduled/check-robots-txt-feed/index.mjs b/src/scheduled/check-robots-txt-feed/index.mjs index ecedc59..0c7392f 100644 --- a/src/scheduled/check-robots-txt-feed/index.mjs +++ b/src/scheduled/check-robots-txt-feed/index.mjs @@ -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', }) @@ -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 }