feat: enhance file upload handling with improved file detection, size limits, and response formatting
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { db, files as fileSchema } from './index';
|
||||
import type { File } from './schema';
|
||||
|
||||
export const findFileByHash = async (hash: string): Promise<File | null> => {
|
||||
const result = await db.select().from(fileSchema).where(eq(fileSchema.fileHash, hash)).limit(1);
|
||||
return result[0] || null;
|
||||
};
|
||||
|
||||
export const findFileByPublicId = async (publicId: string): Promise<File | null> => {
|
||||
const result = await db
|
||||
.select()
|
||||
.from(fileSchema)
|
||||
.where(eq(fileSchema.publicId, publicId))
|
||||
.limit(1);
|
||||
return result[0] || null;
|
||||
};
|
||||
|
||||
export const findFileByUniqueId = async (telegramFileUniqueId: string): Promise<File | null> => {
|
||||
const result = await db
|
||||
.select()
|
||||
.from(fileSchema)
|
||||
.where(eq(fileSchema.telegramFileUniqueId, telegramFileUniqueId))
|
||||
.limit(1);
|
||||
return result[0] || null;
|
||||
};
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
import postgres from 'postgres';
|
||||
import { config } from '../env';
|
||||
import { getErrorMessage } from '../utils/file';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
const schemaSql = await Bun.file('schema.sql').text();
|
||||
@@ -8,8 +9,8 @@ const sql = postgres(config.databaseUrl, { max: 1 });
|
||||
try {
|
||||
await sql.unsafe(schemaSql);
|
||||
logger.info('Database migration completed');
|
||||
} catch (error: any) {
|
||||
logger.error('Database migration failed', { error: error.message });
|
||||
} catch (error: unknown) {
|
||||
logger.error('Database migration failed', { error: getErrorMessage(error) });
|
||||
process.exitCode = 1;
|
||||
} finally {
|
||||
await sql.end();
|
||||
|
||||
Reference in New Issue
Block a user