Skip to content

Commit

Permalink
this could be consider premium dogshit
Browse files Browse the repository at this point in the history
  • Loading branch information
jongan69 committed Jan 13, 2025
1 parent e480294 commit 30a7a38
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { TwitterClient } from './twitterAuth';
import { TwitterClient } from '../../../../archive/twitterAuth';
import { Tweet } from 'agent-twitter-client';
import { TRACKED_ACCOUNTS } from '@utils/trackedAccounts';
import { checkApiKey } from '@utils/checkApiKey';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { TwitterClient } from './twitterAuth';
import { TwitterClient } from '../../../../archive/twitterAuth';
import { checkApiKey } from '@utils/checkApiKey';

export default async function handler(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { TwitterClient } from './twitterAuth';
import { TwitterClient } from '../../../../archive/twitterAuth';
import { Tweet } from 'agent-twitter-client';
import { TRACKED_ACCOUNTS } from '@utils/trackedAccounts';
import { checkApiKey } from '@utils/checkApiKey';

// Add error handling wrapper for client initialization
async function getTwitterClient() {
try {
// Skip WebRTC initialization in development
if (process.env.NODE_ENV === 'development') {
console.warn('WebRTC initialization skipped in development environment');
// Skip WebRTC in production
if (process.env.NODE_ENV === 'production') {
console.warn('WebRTC functionality disabled in production environment');
return {
isReady: () => true,
initialize: async () => {},
getUserTweets: async (username: string) => []
};
}

const client = TwitterClient.getInstance();
Expand All @@ -19,7 +24,12 @@ async function getTwitterClient() {
return client;
} catch (error) {
console.error('Failed to initialize Twitter client:', error);
throw new Error('Twitter service temporarily unavailable');
// Return mock client when real client fails
return {
isReady: () => true,
initialize: async () => {},
getUserTweets: async (username: string) => []
};
}
}

Expand Down
38 changes: 38 additions & 0 deletions src/pages/api/premium/twitter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { checkApiKey } from '@utils/checkApiKey';

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}

if (!process.env.Local_Node_Api) {
return res.status(500).json({ error: 'Local Node API is not set' });
}

const apiKey = req.headers['x-api-key'];
if (!apiKey) {
return res.status(401).json({ error: 'API key is required' });
}

try {
const isValid = await checkApiKey(apiKey as string);
if (!isValid) {
return res.status(401).json({ error: 'Invalid API key' });
}
const response = await fetch(process.env.Local_Node_Api as string)
const data = await response.json()
console.log(data)
return res.status(200).json(data)

} catch (error) {
console.error('Twitter fetch error:', error);
return res.status(500).json({
success: false,
error: 'Failed to fetch tweets'
});
}
}
2 changes: 1 addition & 1 deletion src/utils/topTickers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getTopTickers = async (): Promise<TickerCount[] | null> => {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);

const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/premium/twitterTrending`, {
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/premium/twitter`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down
5 changes: 1 addition & 4 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
}],
"builds": [{
"src": "package.json",
"use": "@vercel/next",
"config": {
"installCommand": "yarn && SKIP_DOWNLOAD=true npm install node-webrtc --build-from-source --legacy-peer-deps"
}
"use": "@vercel/next"
}]
}

0 comments on commit 30a7a38

Please sign in to comment.