Skip to content

Commit 27a6ef7

Browse files
committed
Security | Removed Deprecated Packages
1 parent efe92dc commit 27a6ef7

8 files changed

Lines changed: 37 additions & 255 deletions

File tree

.github/workflows/deploy-tomoribot.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,17 @@ jobs:
277277
with:
278278
fetch-depth: 0 # Fetch full history for TruffleHog
279279

280+
# TODO: Before merging to main, restore branch comparison mode:
281+
# - name: Fetch main branch for comparison
282+
# run: git fetch origin main:main
283+
280284
- name: Run TruffleHog secret scan
281285
uses: trufflesecurity/trufflehog@main
282286
with:
283287
path: ./
284-
base: ${{ github.event.repository.default_branch }}
285-
head: HEAD
288+
# TODO: Before merging to main, uncomment these lines to scan only new commits:
289+
# base: ${{ github.event.repository.default_branch }}
290+
# head: HEAD
286291
extra_args: --only-verified
287292
continue-on-error: true
288293
id: trufflehog

bun.lock

Lines changed: 5 additions & 151 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@
3838
"axios": "^1.13.2",
3939
"bing-translate-api": "^4.1.0",
4040
"bun-types": "^1.3.2",
41-
"deepl": "^1.0.13",
4241
"discord.js": "14.25.0",
4342
"dotenv": "^17.2.3",
44-
"gif-frames": "^1.0.1",
43+
"gifuct-js": "^2.1.2",
4544
"google-translate-api-x": "^10.7.2",
4645
"libsodium-wrappers": "^0.7.15",
4746
"pg": "^8.16.3",
4847
"sharp": "^0.34.5",
49-
"sql": "^0.78.0",
5048
"zod": "^4.1.12"
5149
},
5250
"devDependencies": {

src/events/messageCreate/jpTrans.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { translate } from "bing-translate-api";
22
import type { Client, Message } from "discord.js";
3-
import deepl from "deepl";
43
import { translate as googleTranslate } from "google-translate-api-x";
54
import { log } from "../../utils/misc/logger";
65
import { sendTranslationEmbed } from "../../utils/discord/embedHelper";
76
import type {
87
BingResponse,
9-
DeeplResponse,
108
GoogleResponse,
119
} from "../../types/misc/translation";
1210
import { TranslationProvider } from "../../types/discord/embed";
@@ -44,14 +42,8 @@ const handler = async (_client: Client, message: Message): Promise<void> => {
4442
log.info("Japanese message detected, translating...");
4543

4644
// Get translations from each provider
47-
const [bingResult, deeplResult, googleResult] = await Promise.all([
45+
const [bingResult, googleResult] = await Promise.all([
4846
translate(message.content, undefined, "en") as Promise<BingResponse>,
49-
deepl({
50-
free_api: true,
51-
text: message.content,
52-
target_lang: "EN",
53-
auth_key: process.env.DEEPL_KEY || "",
54-
}) as Promise<DeeplResponse>,
5547
googleTranslate(message.content, {
5648
to: "en",
5749
forceBatch: false,
@@ -63,7 +55,6 @@ const handler = async (_client: Client, message: Message): Promise<void> => {
6355
text: message.content,
6456
translations: {
6557
[TranslationProvider.GOOGLE]: googleResult.text,
66-
[TranslationProvider.DEEPL]: deeplResult.data.translations[0].text,
6758
[TranslationProvider.BING]: bingResult.translation,
6859
},
6960
initialProvider: TranslationProvider.GOOGLE,

src/types/discord/embed.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export type ConfirmationResult = {
6161
*/
6262
export enum TranslationProvider {
6363
GOOGLE = "google",
64-
DEEPL = "deepl",
6564
BING = "bing",
6665
}
6766

@@ -70,7 +69,6 @@ export enum TranslationProvider {
7069
*/
7170
export const TRANSLATOR_COLORS = {
7271
[TranslationProvider.GOOGLE]: "#DE3163", // Google red
73-
[TranslationProvider.DEEPL]: "#09B1CE", // DeepL blue
7472
[TranslationProvider.BING]: "#7DDA58", // Bing green
7573
} as const satisfies Record<TranslationProvider, ColorResolvable>;
7674

@@ -79,7 +77,6 @@ export const TRANSLATOR_COLORS = {
7977
*/
8078
export const TRANSLATOR_STYLES = {
8179
[TranslationProvider.GOOGLE]: ButtonStyle.Danger,
82-
[TranslationProvider.DEEPL]: ButtonStyle.Primary,
8380
[TranslationProvider.BING]: ButtonStyle.Success,
8481
} as const satisfies Record<TranslationProvider, ButtonStyle>;
8582

src/types/external/gif-frames.d.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/types/misc/translation.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
/**
2-
* Response type for DeepL API
3-
*/
4-
export interface DeeplResponse {
5-
data: {
6-
translations: Array<{
7-
text: string;
8-
detected_source_language: string;
9-
}>;
10-
};
11-
}
12-
131
/**
142
* Response type for Bing Translate API
153
*/

src/utils/media/gifProcessor.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* for use with LLM providers that don't support GIF format
55
*/
66

7-
import gifFrames from "gif-frames";
7+
import { parseGIF, decompressFrames } from "gifuct-js";
88
import sharp from "sharp";
99
import { log } from "../misc/logger";
1010

@@ -168,13 +168,11 @@ async function extractFramesInternal(
168168
gifBuffer = gifSource;
169169
}
170170

171-
// 2. Get frame metadata to determine total frame count
172-
// Extract all frames first to get accurate count
173-
const allFramesData = await gifFrames({
174-
url: gifBuffer,
175-
frames: "all",
176-
cumulative: true, // Important: composite frames for GIFs with delta encoding
177-
});
171+
// 2. Parse and decompress the GIF
172+
// parseGIF expects ArrayBuffer, convert Buffer to ArrayBuffer
173+
const uint8Array = new Uint8Array(gifBuffer);
174+
const gif = parseGIF(uint8Array.buffer);
175+
const allFramesData = decompressFrames(gif, true); // buildPatch=true for RGBA data
178176

179177
const totalFrames = allFramesData.length;
180178
log.info(`GIF Processor: Total frames in GIF: ${totalFrames}`);
@@ -276,7 +274,7 @@ function calculateKeyframeIndices(
276274
/**
277275
* Process a single GIF frame: convert to JPEG and compress
278276
*
279-
* @param frameData - Frame data from gif-frames
277+
* @param frameData - Frame data from gifuct-js
280278
* @param frameNumber - Sequential frame number in the output (0-indexed)
281279
* @param totalOutputFrames - Total number of frames in the output (keyframes)
282280
* @param originalFrameIndex - Original frame index in the source GIF
@@ -285,28 +283,30 @@ function calculateKeyframeIndices(
285283
* @returns Processed frame with base64 data
286284
*/
287285
async function processFrame(
288-
frameData: { getImage: () => NodeJS.ReadableStream },
286+
frameData: {
287+
patch: Uint8ClampedArray;
288+
dims: { width: number; height: number; top: number; left: number };
289+
},
289290
frameNumber: number,
290291
totalOutputFrames: number,
291292
originalFrameIndex: number,
292293
totalSourceFrames: number,
293294
config: Required<GifProcessorConfig>,
294295
): Promise<ProcessedGifFrame> {
295-
// 1. Get the frame as a buffer
296-
const frameStream = frameData.getImage();
297-
const chunks: Buffer[] = [];
298-
299-
// Convert stream to buffer
300-
await new Promise<void>((resolve, reject) => {
301-
frameStream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
302-
frameStream.on("end", () => resolve());
303-
frameStream.on("error", (error) => reject(error));
304-
});
305-
306-
const frameBuffer = Buffer.concat(chunks);
296+
// 1. Convert RGBA pixel data to raw buffer
297+
// gifuct-js provides patch as Uint8ClampedArray with RGBA pixel data
298+
const { patch, dims } = frameData;
299+
const frameBuffer = Buffer.from(patch.buffer);
307300

308301
// 2. Process with sharp: resize and convert to JPEG
309-
const processedBuffer = await sharp(frameBuffer)
302+
// Create Sharp instance from raw RGBA pixel data
303+
const processedBuffer = await sharp(frameBuffer, {
304+
raw: {
305+
width: dims.width,
306+
height: dims.height,
307+
channels: 4, // RGBA
308+
},
309+
})
310310
.resize(config.maxWidth, undefined, {
311311
fit: "inside", // Maintain aspect ratio
312312
withoutEnlargement: true, // Don't upscale small images

0 commit comments

Comments
 (0)