Schedule posts to Bluesky with Cloudflare workers. skyscheduler.work
cf tool bsky-tool cloudflare bluesky schedule bsky service social-media cloudflare-workers

turn on rate limits

for #96

+5 -3
+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 + 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 - post.post("/create", async (c: Context) => { 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 - post.post("/create/repost", async (c: Context) => { 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 - export const rateLimit = async (prop: RateLimitProps) => { 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 + console.warn("cannot apply rate limits, oh no"); 15 16 await next(); 16 17 return; 17 18 }