cr
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import * as fs from 'fs';
|
||||
import { Injectable, Logger } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import * as fs from "fs";
|
||||
|
||||
@Injectable()
|
||||
export class TwitterService {
|
||||
@@ -9,18 +9,18 @@ export class TwitterService {
|
||||
private isEnabled = false;
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
const apiKey = this.configService.get<string>('TWITTER_API_KEY');
|
||||
const apiSecret = this.configService.get<string>('TWITTER_API_SECRET');
|
||||
const accessToken = this.configService.get<string>('TWITTER_ACCESS_TOKEN');
|
||||
const apiKey = this.configService.get<string>("TWITTER_API_KEY");
|
||||
const apiSecret = this.configService.get<string>("TWITTER_API_SECRET");
|
||||
const accessToken = this.configService.get<string>("TWITTER_ACCESS_TOKEN");
|
||||
const accessSecret = this.configService.get<string>(
|
||||
'TWITTER_ACCESS_SECRET',
|
||||
"TWITTER_ACCESS_SECRET",
|
||||
);
|
||||
|
||||
if (apiKey && apiSecret && accessToken && accessSecret) {
|
||||
void this.initClient(apiKey, apiSecret, accessToken, accessSecret);
|
||||
} else {
|
||||
this.logger.warn(
|
||||
'⚠️ Twitter API keys not configured. Set TWITTER_API_KEY, TWITTER_API_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_SECRET',
|
||||
"⚠️ Twitter API keys not configured. Set TWITTER_API_KEY, TWITTER_API_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_SECRET",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ export class TwitterService {
|
||||
accessSecret: string,
|
||||
) {
|
||||
try {
|
||||
const { TwitterApi } = await import('twitter-api-v2');
|
||||
const { TwitterApi } = await import("twitter-api-v2");
|
||||
this.client = new TwitterApi({
|
||||
appKey: apiKey,
|
||||
appSecret: apiSecret,
|
||||
@@ -40,9 +40,9 @@ export class TwitterService {
|
||||
accessSecret,
|
||||
});
|
||||
this.isEnabled = true;
|
||||
this.logger.log('✅ Twitter API client initialized');
|
||||
this.logger.log("✅ Twitter API client initialized");
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to initialize Twitter client', error);
|
||||
this.logger.error("Failed to initialize Twitter client", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export class TwitterService {
|
||||
*/
|
||||
async postWithImage(text: string, imagePath: string): Promise<string | null> {
|
||||
if (!this.available) {
|
||||
this.logger.warn('Twitter not available, skipping post');
|
||||
this.logger.warn("Twitter not available, skipping post");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ export class TwitterService {
|
||||
// Step 1: Upload media via v1.1
|
||||
const mediaData = fs.readFileSync(imagePath);
|
||||
const mediaId = await this.client.v1.uploadMedia(mediaData, {
|
||||
mimeType: 'image/png',
|
||||
mimeType: "image/png",
|
||||
});
|
||||
|
||||
// Step 2: Create tweet via v2
|
||||
|
||||
Reference in New Issue
Block a user