main
Some checks failed
Backend Deploy 🚀 / build-and-deploy (push) Has been cancelled

This commit is contained in:
Harun CAN
2026-03-22 23:34:00 +03:00
parent dee6e29cfd
commit c3d2413003
5 changed files with 56 additions and 56 deletions

View File

@@ -81,7 +81,7 @@ export class NewsService {
): Promise<NewsArticle[]> {
if (!this.apiKey) {
this.logger.warn('NewsAPI key not configured');
return this.getMockArticles();
return [];
}
try {
@@ -100,7 +100,7 @@ export class NewsService {
return data.articles || [];
} catch (error) {
this.logger.error(`Failed to fetch headlines: ${error.message}`);
return this.getMockArticles();
return [];
}
}
@@ -192,18 +192,4 @@ export class NewsService {
return [...new Set(keywords)].slice(0, 5);
}
/**
* Get mock articles for development
*/
private getMockArticles(): NewsArticle[] {
return [
{
title: 'Breaking: Technology Trends Shaping 2026',
description: 'Latest technology trends analysis',
url: 'https://example.com/tech-trends',
source: { name: 'Tech News' },
publishedAt: new Date().toISOString(),
},
];
}
}

View File

@@ -6,6 +6,8 @@ import { ConfigService } from '@nestjs/config';
import { TrendSource } from '@prisma/client';
interface TrendScanOptions {
country?: string;
language?: string;
limit?: number;
}
@@ -105,7 +107,7 @@ export class RedditTrendsService {
return data.data.children.map((child: any) => child.data);
} catch (error) {
this.logger.error(`Reddit search error: ${error.message}`);
return this.getMockPosts(keyword);
return [];
}
}
@@ -247,21 +249,4 @@ export class RedditTrendsService {
this.tokenExpiry = Date.now() + data.expires_in * 1000 - 60000;
}
/**
* Get mock posts for development
*/
private getMockPosts(keyword: string): RedditPost[] {
return [
{
id: `mock-${Date.now()}`,
title: `Trending discussion about ${keyword}`,
selftext: `This is a trending post about ${keyword}`,
score: Math.floor(Math.random() * 1000),
num_comments: Math.floor(Math.random() * 100),
url: `/r/trending/comments/mock`,
subreddit: 'trending',
created_utc: Date.now() / 1000,
},
];
}
}

View File

@@ -71,7 +71,7 @@ export class TwitterTrendsService {
if (!this.bearerToken) {
this.logger.warn('Twitter API token not configured');
return this.getMockTrends();
return [];
}
try {
@@ -92,7 +92,7 @@ export class TwitterTrendsService {
return this.transformTwitterTrends(data[0]?.trends || []);
} catch (error) {
this.logger.error(`Failed to fetch Twitter trends: ${error.message}`);
return this.getMockTrends();
return [];
}
}
@@ -219,22 +219,4 @@ export class TwitterTrendsService {
.filter((word) => word.length > 2);
}
/**
* Get mock trends for development
*/
private getMockTrends(): TrendResult[] {
return [
{
id: `twitter-mock-${Date.now()}`,
title: '#TrendingNow',
description: 'Mock trending topic',
source: TrendSource.TWITTER,
score: 75,
volume: 50000,
keywords: ['trending', 'now'],
relatedTopics: [],
timestamp: new Date(),
},
];
}
}

View File

@@ -83,11 +83,11 @@ export class TrendsService {
case TrendSource.GOOGLE_TRENDS:
return this.googleTrends.fetchTrends(niche.keywords, options);
case TrendSource.TWITTER:
return this.googleNewsRss.fetchNews(niche.keywords, { ...options, allLanguages: options?.allLanguages });
return this.twitterTrends.fetchTrends(niche.keywords, options);
case TrendSource.REDDIT:
return this.redditTrends.fetchTrends(niche.keywords, options);
case TrendSource.NEWSAPI:
return this.googleNewsRss.fetchNews(niche.keywords, { ...options, allLanguages: options?.allLanguages });
return this.news.fetchTrends(niche.keywords, options);
default:
return [];
}
@@ -144,6 +144,30 @@ export class TrendsService {
this.logger.error(`Google News RSS error: ${error.message}`);
}
try {
// Fetch from Reddit (Real data if keys exist, else empty)
const redditResults = await this.redditTrends.fetchTrends(keywords, scanOptions);
allTrends.push(...redditResults);
} catch (error) {
this.logger.error(`Reddit error: ${error.message}`);
}
try {
// Fetch from Twitter (Real data if keys exist, else empty)
const twitterResults = await this.twitterTrends.fetchTrends(keywords, scanOptions);
allTrends.push(...twitterResults);
} catch (error) {
this.logger.error(`Twitter error: ${error.message}`);
}
try {
// Fetch from NewsAPI (Real data if keys exist, else empty)
const newsApiResults = await this.news.fetchTrends(keywords, scanOptions);
allTrends.push(...newsApiResults);
} catch (error) {
this.logger.error(`NewsAPI error: ${error.message}`);
}
try {
// Fetch from Hacker News for Tech (FREE)
if (keywords.some(k => k.toLowerCase().match(/ai|tech|yapay|google|openai/))) {

23
test-query.ts Normal file
View File

@@ -0,0 +1,23 @@
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
const masterContents = await prisma.masterContent.findMany({
orderBy: { createdAt: 'desc' },
take: 5,
include: {
contents: true
}
});
console.log(JSON.stringify(masterContents, null, 2));
}
main()
.then(() => prisma.$disconnect())
.catch(e => {
console.error(e);
prisma.$disconnect();
process.exit(1);
});