style: format and lint codebase using Biome v2

This commit is contained in:
MythEclipse
2026-05-18 07:29:01 +07:00
parent 3f4e697733
commit cf79a1f195
22 changed files with 638 additions and 528 deletions
+17 -5
View File
@@ -4,7 +4,7 @@ const FILE_TYPES: Record<string, number> = {
video: 2 * 1024 * 1024 * 1024, // 2GB
audio: 200 * 1024 * 1024, // 200MB
voice: 200 * 1024 * 1024, // 200MB
animation: 2 * 1024 * 1024 * 1024 // 2GB
animation: 2 * 1024 * 1024 * 1024, // 2GB
};
export const getFileType = (mime: string | null, caption?: string): string => {
@@ -30,14 +30,26 @@ export const extractFileName = (msg: any, request: any): string => {
if (request?.headers?.['x-file-name']) {
return request.headers['x-file-name'];
}
return msg.document?.fileName || msg.photo?.slice(-1)[0]?.fileName || msg.audio?.fileName ||
msg.voice?.fileName || msg.animation?.fileName || 'file';
return (
msg.document?.fileName ||
msg.photo?.slice(-1)[0]?.fileName ||
msg.audio?.fileName ||
msg.voice?.fileName ||
msg.animation?.fileName ||
'file'
);
};
export const extractMimeType = (msg: any, request: any): string => {
if (request?.headers?.['x-mime-type']) {
return request.headers['x-mime-type'];
}
return msg.document?.mimeType || msg.photo?.slice(-1)[0]?.mimeType || msg.audio?.mimeType ||
msg.voice?.mimeType || msg.animation?.mimeType || 'application/octet-stream';
return (
msg.document?.mimeType ||
msg.photo?.slice(-1)[0]?.mimeType ||
msg.audio?.mimeType ||
msg.voice?.mimeType ||
msg.animation?.mimeType ||
'application/octet-stream'
);
};
+8 -9
View File
@@ -5,24 +5,23 @@ const logger = winston.createLogger({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.errors({ stack: true }),
winston.format.json()
winston.format.json(),
),
defaultMeta: { service: 'teleuploader' },
transports: [
// Write all logs including error logs to file
new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
new winston.transports.File({ filename: 'logs/combined.log' })
]
new winston.transports.File({ filename: 'logs/combined.log' }),
],
});
// If not production, also log to console
if (process.env.NODE_ENV !== 'production') {
logger.add(new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
)
}));
logger.add(
new winston.transports.Console({
format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
}),
);
}
export default logger;
+9 -7
View File
@@ -1,6 +1,6 @@
import { Telegraf } from 'telegraf';
import logger from './logger';
import { config } from '../env';
import logger from './logger';
const bot = new Telegraf(config.botToken);
const TELEGRAM_API_URL = `https://api.telegram.org/bot${config.botToken}/`;
@@ -20,11 +20,13 @@ interface TelegramFileInfo {
export const forwardToStorage = async (
fileChunk: any,
fileName: string,
forceDocument = false
forceDocument = false,
): Promise<ForwardResult> => {
try {
const caption = forceDocument ? `📁 ${fileName}` : fileName;
const input: any = forceDocument ? { document: fileChunk, caption } : { photo: [fileChunk], caption };
const input: any = forceDocument
? { document: fileChunk, caption }
: { photo: [fileChunk], caption };
const result = await bot.telegram.sendPhoto(config.storageChatId, input);
@@ -33,7 +35,7 @@ export const forwardToStorage = async (
return {
telegramFileId: result.photo?.slice(-1)[0]?.file_id || '',
telegramFileUniqueId: result.photo?.slice(-1)[0]?.file_unique_id || '',
storageMessageId: result.message_id
storageMessageId: result.message_id,
};
} catch (error: any) {
logger.error('Failed to forward file to storage', { fileName, error: error.message });
@@ -43,7 +45,7 @@ export const forwardToStorage = async (
export const getFileInfo = async (
telegramFileId: string,
telegramFileUniqueId: string
telegramFileUniqueId: string,
): Promise<TelegramFileInfo> => {
try {
const result = await fetch(`${TELEGRAM_API_URL}getFile`);
@@ -57,7 +59,7 @@ export const getFileInfo = async (
const fileResult = await fetch(`${TELEGRAM_API_URL}getInfo`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ file_id: fileId })
body: JSON.stringify({ file_id: fileId }),
});
const fileInfo: any = await fileResult.json();
@@ -68,7 +70,7 @@ export const getFileInfo = async (
return {
file_size: fileInfo.result.file_size,
mime_type: fileInfo.result.mime_type,
file_path: fileInfo.result.file_path
file_path: fileInfo.result.file_path,
};
} catch (error: any) {
logger.error('Failed to get file info', { error: error.message });