add logging
This commit is contained in:
parent
cf01dea155
commit
e8234e41e8
4 changed files with 230 additions and 12 deletions
|
|
@ -1,6 +1,16 @@
|
|||
import pino from "pino";
|
||||
import { lambdaRequestTracker, pinoLambdaDestination } from "pino-lambda";
|
||||
import { MicroBlogBackend } from "./pocketbase";
|
||||
|
||||
// custom destination formatter
|
||||
const destination = pinoLambdaDestination();
|
||||
const logger = pino({}, destination);
|
||||
const withRequest = lambdaRequestTracker();
|
||||
|
||||
const baseURL = `https://gram.social/api/pixelfed/v1/accounts/`;
|
||||
const accountID = `703621281309160235`;
|
||||
import { microBlogBackend as pb } from "./pocketbase";
|
||||
|
||||
const pb = new MicroBlogBackend(logger);
|
||||
|
||||
type PixelFedPost = {
|
||||
media_attachments: {
|
||||
|
|
@ -68,14 +78,14 @@ const savePost = async (post: PixelFedPost) => {
|
|||
};
|
||||
|
||||
const saveTags = async (post: PixelFedPost, postId: string) => {
|
||||
console.log({ tags: post.tags }, "saving tags");
|
||||
logger.info({ tags: post.tags }, "saving tags");
|
||||
for (const tag of post.tags) {
|
||||
await pb.setTag(tag.name, postId);
|
||||
}
|
||||
};
|
||||
|
||||
const saveImages = async (post: PixelFedPost, postId: string) => {
|
||||
console.log({ images: post.media_attachments }, "saving images");
|
||||
logger.info({ images: post.media_attachments }, "saving images");
|
||||
for (const image of post.media_attachments) {
|
||||
await pb.saveAndSetImage(
|
||||
{ remoteURL: image.url, alt: image.description },
|
||||
|
|
@ -84,12 +94,12 @@ const saveImages = async (post: PixelFedPost, postId: string) => {
|
|||
}
|
||||
};
|
||||
|
||||
exports.run = async () => {
|
||||
exports.run = async (event: any, context: any) => {
|
||||
withRequest(event, context);
|
||||
const lastSavedPostId = await pb.getLatestPostId("pixelfed");
|
||||
const posts = await getPostUntilId({ lastSavedId: lastSavedPostId });
|
||||
const post = posts[0];
|
||||
if (post) {
|
||||
console.log({ post }, "saving post");
|
||||
for (const post of posts) {
|
||||
logger.info({ post }, "saving post");
|
||||
const savedNewPost = await savePost(post);
|
||||
if (savedNewPost) {
|
||||
await saveTags(post, savedNewPost.id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue