-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
66 lines (48 loc) · 1.59 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import bsky from '@atproto/api'
import * as dotenv from 'dotenv'
dotenv.config();
import { getGradientImage } from './generateGradientImage.js';
import fs from "fs";
const { BskyAgent, RichText, } = bsky;
start();
async function start() {
/* initialize BskyAgent and login */
const agent = new BskyAgent({
service: process.env.BLUESKY_SERVER
})
await agent.login({
identifier: process.env.BLUESKY_USERNAME,
password: process.env.BLUESKY_PASSWORD
});
/* call function that generates image with p5.js */
const { path: imagePath, startColor, endColor } = await getGradientImage();
/* read and upload image generated by getGradientImage() */
const file = fs.readFileSync(imagePath)
const response = await agent.uploadBlob(file, {
encoding: "image/jpeg",
})
if (!response.success) {
const msg = `Unable to upload image ${imageUrl}`;
console.error(msg, response);
throw new Error(msg);
}
const {
data: { blob: image },
} = response;
const rt = new RichText({ text: `${startColor.string} + ${endColor.string} 🤖🎨` });
await rt.detectFacets(agent);
/* create a post with Rich Text and generated image */
return agent.post({
text: rt.text,
facets: rt.facets,
embed: {
$type: "app.bsky.embed.images",
images: [
{
image: image,
alt: `a gradient from ${startColor.string} to ${endColor.string} generated by p5 code`
},
],
},
});
}