Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions backend/src/__tests__/mocks/distribution-service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export class MockDistributionService {
submissionId: string;
}> = [];

async processStreamOutput(
feedId: string,
submissionId: string,
): Promise<void> {
this.processedSubmissions.push({ feedId, submissionId });
async processStreamOutput(feedId: string, submission: any): Promise<void> {
this.processedSubmissions.push({
feedId,
submissionId: submission.tweetId,
});
}

async processRecapOutput(): Promise<void> {
Expand Down
23 changes: 0 additions & 23 deletions backend/src/config/config.ts

This file was deleted.

18 changes: 9 additions & 9 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { cors } from "@elysiajs/cors";
import { staticPlugin } from "@elysiajs/static";
import { swagger } from "@elysiajs/swagger";
import dotenv from "dotenv";
import "dotenv/config";
import { Elysia } from "elysia";
import { helmet } from "elysia-helmet";
import path from "path";
import configService, { validateEnv } from "./config/config";
import RssPlugin from "./external/rss";
import { mockTwitterService, testRoutes } from "./routes/test";
import { ConfigService } from "./services/config/config.service";
import { db } from "./services/db";
import { DistributionService } from "./services/distribution/distribution.service";
import { SubmissionService } from "./services/submissions/submission.service";
Expand Down Expand Up @@ -37,17 +37,17 @@ export async function main() {
let distributionService: DistributionService | null = null;

try {
// Load environment variables and config
startSpinner("env", "Loading environment variables and config...");
dotenv.config();
validateEnv();
// Load config
startSpinner("config", "Loading config...");
const configService = ConfigService.getInstance();
await configService.loadConfig();
succeedSpinner("env", "Environment variables and config loaded");
const config = configService.getConfig();
succeedSpinner("config", "Config loaded");

// Initialize distribution service
startSpinner("distribution-init", "Initializing distribution service...");
distributionService = new DistributionService();
const config = configService.getConfig();

await distributionService.initialize(config.plugins);
succeedSpinner("distribution-init", "distribution service initialized");

Expand Down Expand Up @@ -319,7 +319,7 @@ export async function main() {
} catch (error) {
// Handle any initialization errors
[
"env",
"config",
"twitter-init",
"distribution-init",
"submission-monitor",
Expand Down
6 changes: 3 additions & 3 deletions backend/src/services/submissions/submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class SubmissionService {
if (feed.outputs.stream?.enabled) {
await this.DistributionService.processStreamOutput(
feed.id,
submission!,
existingSubmission || submission!,
);
}
}
Expand Down Expand Up @@ -331,7 +331,7 @@ export class SubmissionService {
if (feed.outputs.stream?.enabled) {
await this.DistributionService.processStreamOutput(
feed.id,
submission!,
existingSubmission || submission!,
);
}
}
Expand All @@ -350,7 +350,7 @@ export class SubmissionService {

private async handleAcknowledgement(tweet: Tweet): Promise<void> {
// Like the tweet
await this.twitterService.likeTweet(tweet.id);
await this.twitterService.likeTweet(tweet.id!);

// // Reply to curator's tweet confirming submission
// await this.twitterService.replyToTweet(
Expand Down
19 changes: 15 additions & 4 deletions backend/src/services/twitter/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ export class TwitterService {
}

async initialize() {
// Validate required Twitter credentials
if (
!process.env.TWITTER_USERNAME ||
!process.env.TWITTER_PASSWORD ||
!process.env.TWITTER_EMAIL
) {
throw new Error(
"Missing required Twitter credentials. Please ensure TWITTER_USERNAME, TWITTER_PASSWORD, and TWITTER_EMAIL are set in your environment variables.",
);
}

try {
// First try to use cached cookies
if (await this.loadCachedCookies()) {
Expand Down Expand Up @@ -193,24 +204,24 @@ export class TwitterService {

// Filter out tweets we've already processed
for (const tweet of batch) {
const tweetId = BigInt(tweet.id);
const tweetId = BigInt(tweet.id!);
if (!lastCheckedId || tweetId > lastCheckedId) {
allNewTweets.push(tweet);
}
}

// Sort chronologically (oldest to newest)
allNewTweets.sort((a, b) => {
const aId = BigInt(a.id);
const bId = BigInt(b.id);
const aId = BigInt(a.id!);
const bId = BigInt(b.id!);
return aId > bId ? 1 : aId < bId ? -1 : 0;
});

// Only update last checked ID if we found new tweets
if (allNewTweets.length > 0) {
// Use the first tweet from the batch since it's the newest (batch comes in newest first)
const highestId = batch[0].id;
await this.setLastCheckedTweetId(highestId);
await this.setLastCheckedTweetId(highestId!);
}

return allNewTweets;
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,5 @@
"devDependencies": {
"turbo": "latest",
"prettier": "^3.3.3"
},
"dependencies": {
"@curatedotfun/supabase": "^0.0.5",
"elysia-rate-limit": "^4.1.0"
}
}