diff --git a/app/api/search/route.ts b/app/api/search/route.ts index 5a3a179..f7e6a4d 100644 --- a/app/api/search/route.ts +++ b/app/api/search/route.ts @@ -1,6 +1,16 @@ import { NextRequest, NextResponse } from 'next/server'; import { esClient, INDEX_NAME, initializeIndex } from '@/lib/elasticsearch'; -import { generateHashes, detectHashType, isHash } from '@/lib/hash'; +import { generateHashes, detectHashType } from '@/lib/hash'; + +interface HashDocument { + plaintext: string; + md5: string; + sha1: string; + sha256: string; + sha512: string; + bcrypt: string; + created_at?: string; +} export async function POST(request: NextRequest) { try { @@ -30,7 +40,7 @@ export async function POST(request: NextRequest) { if (hashType) { // Query is a hash - search for it in Elasticsearch - const searchResponse = await esClient.search({ + const searchResponse = await esClient.search({ index: INDEX_NAME, query: { term: { @@ -47,16 +57,19 @@ export async function POST(request: NextRequest) { found: true, hashType, hash: cleanQuery, - results: hits.map((hit: any) => ({ - plaintext: hit._source.plaintext, - hashes: { - md5: hit._source.md5, - sha1: hit._source.sha1, - sha256: hit._source.sha256, - sha512: hit._source.sha512, - bcrypt: hit._source.bcrypt, - } - })) + results: hits.map((hit) => { + const source = hit._source!; + return { + plaintext: source.plaintext, + hashes: { + md5: source.md5, + sha1: source.sha1, + sha256: source.sha256, + sha512: source.sha512, + bcrypt: source.bcrypt, + } + }; + }) }); } else { // Hash not found in database @@ -69,20 +82,20 @@ export async function POST(request: NextRequest) { } } else { // Query is plaintext - check if it already exists first - const existsResponse = await esClient.search({ + const existsResponse = await esClient.search({ index: INDEX_NAME, query: { term: { 'plaintext.keyword': cleanQuery } } - } as any); + }); let hashes; if (existsResponse.hits.hits.length > 0) { // Plaintext found, retrieve existing hashes - const existingDoc = existsResponse.hits.hits[0]._source as any; + const existingDoc = existsResponse.hits.hits[0]._source!; hashes = { md5: existingDoc.md5, sha1: existingDoc.sha1, @@ -94,7 +107,7 @@ export async function POST(request: NextRequest) { // Plaintext not found, generate hashes and check if any hash already exists hashes = await generateHashes(cleanQuery); - const hashExistsResponse = await esClient.search({ + const hashExistsResponse = await esClient.search({ index: INDEX_NAME, query: { bool: { @@ -107,7 +120,7 @@ export async function POST(request: NextRequest) { minimum_should_match: 1 } } - } as any); + }); if (hashExistsResponse.hits.hits.length === 0) { // No duplicates found, insert new document diff --git a/app/page.tsx b/app/page.tsx index bfa7ebf..5bf3c90 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -58,7 +58,7 @@ export default function Home() { const data = await response.json(); setResult(data); - } catch (err) { + } catch (_err) { setError('Failed to perform search. Please check your connection.'); } finally { setLoading(false); diff --git a/lib/elasticsearch.ts b/lib/elasticsearch.ts index f0d4efb..3c0ad0c 100644 --- a/lib/elasticsearch.ts +++ b/lib/elasticsearch.ts @@ -16,7 +16,7 @@ export const INDEX_MAPPING = { analysis: { analyzer: { lowercase_analyzer: { - type: 'custom', + type: 'custom' as const, tokenizer: 'keyword', filter: ['lowercase'] } @@ -26,31 +26,31 @@ export const INDEX_MAPPING = { mappings: { properties: { plaintext: { - type: 'text', + type: 'text' as const, analyzer: 'lowercase_analyzer', fields: { keyword: { - type: 'keyword' + type: 'keyword' as const } } }, md5: { - type: 'keyword' + type: 'keyword' as const }, sha1: { - type: 'keyword' + type: 'keyword' as const }, sha256: { - type: 'keyword' + type: 'keyword' as const }, sha512: { - type: 'keyword' + type: 'keyword' as const }, bcrypt: { - type: 'keyword' + type: 'keyword' as const }, created_at: { - type: 'date' + type: 'date' as const } } } @@ -63,8 +63,9 @@ export async function initializeIndex(): Promise { if (!indexExists) { await esClient.indices.create({ index: INDEX_NAME, - ...INDEX_MAPPING - } as any); + settings: INDEX_MAPPING.settings, + mappings: INDEX_MAPPING.mappings + }); console.log(`Index '${INDEX_NAME}' created successfully with 10 shards`); } else { console.log(`Index '${INDEX_NAME}' already exists`); diff --git a/lib/hash.ts b/lib/hash.ts index 894c304..5e1d9c8 100644 --- a/lib/hash.ts +++ b/lib/hash.ts @@ -73,7 +73,7 @@ export function isHash(input: string): boolean { export async function verifyBcrypt(plaintext: string, hash: string): Promise { try { return await bcrypt.compare(plaintext, hash); - } catch (error) { + } catch (_error) { return false; } } diff --git a/package.json b/package.json index 7c61ffc..a138ff6 100644 --- a/package.json +++ b/package.json @@ -41,9 +41,9 @@ "@types/bcrypt": "^6.0.0", "bcrypt": "^6.0.0", "lucide-react": "^0.555.0", - "next": "16.0.7", - "react": "19.2.0", - "react-dom": "19.2.0", + "next": "15.4.8", + "react": "19.1.2", + "react-dom": "19.1.2", "tsx": "^4.21.0" }, "devDependencies": { diff --git a/tsconfig.json b/tsconfig.json index 3a13f90..2627c60 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,11 @@ { "compilerOptions": { "target": "ES2017", - "lib": ["dom", "dom.iterable", "esnext"], + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], "allowJs": true, "skipLibCheck": true, "strict": true, @@ -11,7 +15,7 @@ "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, - "jsx": "react-jsx", + "jsx": "preserve", "incremental": true, "plugins": [ { @@ -19,7 +23,9 @@ } ], "paths": { - "@/*": ["./*"] + "@/*": [ + "./*" + ] } }, "include": [ @@ -30,5 +36,7 @@ ".next/dev/types/**/*.ts", "**/*.mts" ], - "exclude": ["node_modules"] + "exclude": [ + "node_modules" + ] }