tangled
alpha
login
or
join now
socksthewolf.com
/
skyscheduler
1
fork
atom
Schedule posts to Bluesky with Cloudflare workers.
skyscheduler.work
cf
tool
bsky-tool
cloudflare
bluesky
schedule
bsky
service
social-media
cloudflare-workers
1
fork
atom
overview
issues
pulls
pipelines
turn on rate limits
for #96
SocksTheWolf
2 weeks ago
d71f4a3b
364f03bd
+5
-3
2 changed files
expand all
collapse all
unified
split
src
endpoints
post.tsx
middleware
rateLimit.ts
+3
-2
src/endpoints/post.tsx
···
9
9
import { ScheduledPostList } from "../layout/postList";
10
10
import { authMiddleware } from "../middleware/auth";
11
11
import { corsHelperMiddleware } from "../middleware/corsHelper";
12
12
+
import { rateLimit } from "../middleware/rateLimit";
12
13
import {
13
14
Bindings, CreateObjectResponse, CreatePostQueryResponse,
14
15
DeleteResponse, EmbedDataType, LooseObj
···
57
58
});
58
59
59
60
// Create post
60
60
-
post.post("/create", async (c: Context) => {
61
61
+
post.post("/create", rateLimit({limiter: "POST_LIMITER"}), async (c: Context) => {
61
62
const body = await c.req.json();
62
63
const response: CreatePostQueryResponse = await createPost(c, body);
63
64
if (!response.ok) {
···
77
78
});
78
79
79
80
// Create repost
80
80
-
post.post("/create/repost", async (c: Context) => {
81
81
+
post.post("/create/repost", rateLimit({limiter: "REPOST_LIMITER"}), async (c: Context) => {
81
82
const body = await c.req.json();
82
83
const response: CreateObjectResponse = await createRepost(c, body);
83
84
if (!response.ok) {
+2
-1
src/middleware/rateLimit.ts
···
7
7
limiter: string;
8
8
};
9
9
10
10
-
export const rateLimit = async (prop: RateLimitProps) => {
10
10
+
export const rateLimit = (prop: RateLimitProps) => {
11
11
return createMiddleware(async (c: Context, next: any) => {
12
12
const userId: string = c.get("userId");
13
13
const rateLimitObj: RateLimit|null = get(c.env, prop.limiter, null);
14
14
if (rateLimitObj === null || isEmpty(userId)) {
15
15
+
console.warn("cannot apply rate limits, oh no");
15
16
await next();
16
17
return;
17
18
}