convert bluesky scraper to docker

This commit is contained in:
Travis Shears 2025-05-22 14:45:33 +02:00
parent 28470e0eba
commit 5788151840
4 changed files with 35 additions and 40 deletions

View file

@ -1,9 +1,19 @@
import * as esbuild from "esbuild"; import * as esbuild from "esbuild";
await esbuild.build({ const commonProps = {
entryPoints: ["src/nostr.ts"],
bundle: true, bundle: true,
outfile: "dist/nostr.js",
platform: "node", platform: "node",
target: "node22", target: "node22",
};
await esbuild.build({
...commonProps,
entryPoints: ["src/nostr.ts"],
outfile: "dist/nostr.js",
});
await esbuild.build({
...commonProps,
entryPoints: ["src/bluesky.ts"],
outfile: "dist/bluesky.js",
}); });

View file

@ -1,6 +1,6 @@
{ {
"name": "micro_blog_fetchers", "name": "micro_blog_fetchers",
"version": "1.0.0", "version": "1.1.0",
"scripts": { "scripts": {
"dev:nostr": "node build.mjs && node ./dist/nostr.js | pino-pretty" "dev:nostr": "node build.mjs && node ./dist/nostr.js | pino-pretty"
}, },
@ -12,7 +12,6 @@
}, },
"dependencies": { "dependencies": {
"pino": "^9.2.0", "pino": "^9.2.0",
"pino-lambda": "^4.4.0",
"pino-pretty": "^13.0.0", "pino-pretty": "^13.0.0",
"pocketbase": "^0.21.3", "pocketbase": "^0.21.3",
"ws": "^8.18.0" "ws": "^8.18.0"

View file

@ -1,11 +1,8 @@
import pino from "pino"; import pino from "pino";
import { lambdaRequestTracker, pinoLambdaDestination } from "pino-lambda";
import { MicroBlogBackend } from "./pocketbase"; import { MicroBlogBackend } from "./pocketbase";
// logger // logger
const destination = pinoLambdaDestination(); const logger = pino();
const logger = pino({}, destination);
const withRequest = lambdaRequestTracker();
// pocketbase // pocketbase
const pb = new MicroBlogBackend(logger); const pb = new MicroBlogBackend(logger);
@ -59,7 +56,7 @@ const getPostsUntilID = async (
session: Session, session: Session,
id: string, id: string,
cursor: string | null = null, cursor: string | null = null,
oldFeed: BlueSkyPost[] = [] oldFeed: BlueSkyPost[] = [],
): Promise<BlueSkyPost[]> => { ): Promise<BlueSkyPost[]> => {
const params = new URLSearchParams(); const params = new URLSearchParams();
params.append("actor", session.did); params.append("actor", session.did);
@ -69,7 +66,7 @@ const getPostsUntilID = async (
} }
const urlWithParams = new URL( const urlWithParams = new URL(
"https://bsky.social/xrpc/app.bsky.feed.getAuthorFeed" "https://bsky.social/xrpc/app.bsky.feed.getAuthorFeed",
); );
urlWithParams.search = params.toString(); urlWithParams.search = params.toString();
@ -136,13 +133,12 @@ const saveImages = async (post: BlueSkyPost, postId: string) => {
for (const image of images) { for (const image of images) {
await pb.saveAndSetImage( await pb.saveAndSetImage(
{ remoteURL: image.fullsize, alt: image.alt }, { remoteURL: image.fullsize, alt: image.alt },
postId postId,
); );
} }
}; };
exports.run = async (event: any, context: any) => { (async () => {
withRequest(event, context);
const session = await createSession(); const session = await createSession();
const lastSavedPostId = await pb.getLatestPostRemoteIDBySource("blue_sky"); const lastSavedPostId = await pb.getLatestPostRemoteIDBySource("blue_sky");
const posts = await getPostsUntilID(session, lastSavedPostId ?? ""); const posts = await getPostsUntilID(session, lastSavedPostId ?? "");
@ -156,4 +152,4 @@ exports.run = async (event: any, context: any) => {
await saveTags(post, savedNewPost.id); await saveTags(post, savedNewPost.id);
await saveImages(post, savedNewPost.id); await saveImages(post, savedNewPost.id);
} }
}; })();

View file

@ -358,6 +358,21 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"micro_blog_fetchers@workspace:.":
version: 0.0.0-use.local
resolution: "micro_blog_fetchers@workspace:."
dependencies:
"@types/node": "npm:^20.14.8"
"@types/ws": "npm:^8"
esbuild: "npm:^0.25.4"
pino: "npm:^9.2.0"
pino-pretty: "npm:^13.0.0"
pocketbase: "npm:^0.21.3"
prettier: "npm:^3.3.2"
ws: "npm:^8.18.0"
languageName: unknown
linkType: soft
"minimist@npm:^1.2.6": "minimist@npm:^1.2.6":
version: 1.2.8 version: 1.2.8
resolution: "minimist@npm:1.2.8" resolution: "minimist@npm:1.2.8"
@ -390,15 +405,6 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"pino-lambda@npm:^4.4.0":
version: 4.4.1
resolution: "pino-lambda@npm:4.4.1"
peerDependencies:
pino: ">=6.0.0"
checksum: 10c0/6835b1f51bd022f5196f79c90adfb84128689da5aa490ff13722630f7c681d73fc1ccb72df8b5ccf0569f6ae16fd0fdadb114aff423e21df834fc21f38ba6e84
languageName: node
linkType: hard
"pino-pretty@npm:^13.0.0": "pino-pretty@npm:^13.0.0":
version: 13.0.0 version: 13.0.0
resolution: "pino-pretty@npm:13.0.0" resolution: "pino-pretty@npm:13.0.0"
@ -497,22 +503,6 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"root-workspace-0b6124@workspace:.":
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
"@types/node": "npm:^20.14.8"
"@types/ws": "npm:^8"
esbuild: "npm:^0.25.4"
pino: "npm:^9.2.0"
pino-lambda: "npm:^4.4.0"
pino-pretty: "npm:^13.0.0"
pocketbase: "npm:^0.21.3"
prettier: "npm:^3.3.2"
ws: "npm:^8.18.0"
languageName: unknown
linkType: soft
"safe-stable-stringify@npm:^2.3.1": "safe-stable-stringify@npm:^2.3.1":
version: 2.5.0 version: 2.5.0
resolution: "safe-stable-stringify@npm:2.5.0" resolution: "safe-stable-stringify@npm:2.5.0"