Skip to content

Commit

Permalink
Add automatic file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
juanegiraldoa committed Apr 17, 2024
1 parent 46ddcad commit 08e68f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ This project post an image every Wednesday integrated with Cloudflare Workers

```
MASTODON_ACCESS_KEY=<mastodon-access-key>
MASTODON_WEDNESDAY_DUDE_MEDIA=<mastodon-wednesday-dude-id-media>
```
25 changes: 11 additions & 14 deletions src/WednesdayMyDudes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ import { getTimeLine, postStatus, uploadMedia } from '../Mastodon';
const DATE_FORMAT = 'YYYY-MM-DD';

const postOnWednesday = async (token: string, media_ids: string, resources: R2Bucket) => {
const image = await resources.get('wednesday.jpg');
if (image === null) return;
const response = await uploadMedia(token, await image.blob());
console.log(response);

// if (moment().day() === 3) {
// const [lastPost]: any = await getTimeLine(token);
// const lastPostDate = lastPost ? moment(lastPost.created_at).format(DATE_FORMAT) : null;
// if (!lastPostDate && lastPostDate !== moment().format(DATE_FORMAT)) {
// await postStatus(token, media_ids);
// return "It's Wednesday My Dudes";
// } else return 'Already Posted My Dude';
// } else return "It's Not Wednesday My Dudes";
return 'HELLO';
if (moment().day() === 3) {
const [lastPost]: any = await getTimeLine(token);
const lastPostDate = lastPost ? moment(lastPost.created_at).format(DATE_FORMAT) : null;
if (!lastPostDate && lastPostDate !== moment().format(DATE_FORMAT)) {
const image = await resources.get('wednesday.jpg');
if (image === null) return;
const { id }: any = await uploadMedia(token, await image.blob());
await postStatus(token, id);
return "It's Wednesday My Dudes";
} else return 'Already Posted My Dude';
} else return "It's Not Wednesday My Dudes";
};

export { postOnWednesday };
1 change: 0 additions & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ compatibility_flags = ["nodejs_compat"]

[vars]
MASTODON_TOKEN = "J_DPBhWeklP_RNirnbtFH-SIFYJtwv9CJ8Bjyog_xrY"
MASTODON_WEDNESDAY_DUDE_MEDIA = "112288098480431582"

[triggers]
crons = [ "0 8 * * wed" ]
Expand Down

0 comments on commit 08e68f0

Please sign in to comment.