Merge pull request #13 from derekslenk/cleanup/remove-unused-imports
Clean up unused imports and variables
This commit is contained in:
commit
6cb165a3c3
7 changed files with 11 additions and 19 deletions
|
@ -2,7 +2,6 @@ import express, { Request, Response, Router } from 'express';
|
||||||
import rateLimit from 'express-rate-limit';
|
import rateLimit from 'express-rate-limit';
|
||||||
import Location from '../models/Location';
|
import Location from '../models/Location';
|
||||||
import ProfanityFilterService from '../services/ProfanityFilterService';
|
import ProfanityFilterService from '../services/ProfanityFilterService';
|
||||||
import { LocationSubmission } from '../types';
|
|
||||||
|
|
||||||
// Define interfaces for request bodies
|
// Define interfaces for request bodies
|
||||||
interface LocationPostRequest extends Request {
|
interface LocationPostRequest extends Request {
|
||||||
|
@ -30,7 +29,7 @@ export default (locationModel: Location, profanityFilter: ProfanityFilterService
|
||||||
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
|
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
|
||||||
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
|
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
|
||||||
// Skip rate limiting in test environment
|
// Skip rate limiting in test environment
|
||||||
skip: (req) => process.env.NODE_ENV === 'test'
|
skip: () => process.env.NODE_ENV === 'test'
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,9 +214,6 @@ export default (locationModel: Location, profanityFilter: ProfanityFilterService
|
||||||
console.warn(`Submission rejected due to inappropriate language (${analysis.count} word${analysis.count > 1 ? 's' : ''}, severity: ${analysis.severity}) - Original: "${req.body.description}"`);
|
console.warn(`Submission rejected due to inappropriate language (${analysis.count} word${analysis.count > 1 ? 's' : ''}, severity: ${analysis.severity}) - Original: "${req.body.description}"`);
|
||||||
|
|
||||||
// Reject any submission with profanity
|
// Reject any submission with profanity
|
||||||
const wordText = analysis.count === 1 ? 'word' : 'words';
|
|
||||||
const detectedWords = analysis.matches.map((m: any) => m.word).join(', ');
|
|
||||||
|
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
error: 'Submission rejected',
|
error: 'Submission rejected',
|
||||||
message: 'Your description contains inappropriate language and cannot be posted. Please revise your description to focus on road conditions and keep it professional.\n\nExample: "Multiple vehicles stuck, black ice present" or "Road very slippery, saw 3 accidents"',
|
message: 'Your description contains inappropriate language and cannot be posted. Please revise your description to focus on road conditions and keep it professional.\n\nExample: "Multiple vehicles stuck, black ice present" or "Road very slippery, saw 3 accidents"',
|
||||||
|
|
|
@ -19,8 +19,6 @@ import configRoutes from './routes/config';
|
||||||
import locationRoutes from './routes/locations';
|
import locationRoutes from './routes/locations';
|
||||||
import adminRoutes from './routes/admin';
|
import adminRoutes from './routes/admin';
|
||||||
|
|
||||||
// Import types
|
|
||||||
import { Location, ProfanityWord } from './types';
|
|
||||||
|
|
||||||
const app: Application = express();
|
const app: Application = express();
|
||||||
const PORT: number = parseInt(process.env.PORT || '3000', 10);
|
const PORT: number = parseInt(process.env.PORT || '3000', 10);
|
||||||
|
@ -84,11 +82,11 @@ function createFallbackFilter(): FallbackFilter {
|
||||||
success: false,
|
success: false,
|
||||||
error: 'Profanity filter not available - please check server configuration'
|
error: 'Profanity filter not available - please check server configuration'
|
||||||
}),
|
}),
|
||||||
removeCustomWord: async (wordId: number) => ({
|
removeCustomWord: async () => ({
|
||||||
success: false,
|
success: false,
|
||||||
error: 'Profanity filter not available - please check server configuration'
|
error: 'Profanity filter not available - please check server configuration'
|
||||||
}),
|
}),
|
||||||
updateCustomWord: async (wordId: number, updates: any) => ({
|
updateCustomWord: async () => ({
|
||||||
success: false,
|
success: false,
|
||||||
error: 'Profanity filter not available - please check server configuration'
|
error: 'Profanity filter not available - please check server configuration'
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -155,8 +155,8 @@ class ProfanityFilterService {
|
||||||
.split('')
|
.split('')
|
||||||
.map(char => {
|
.map(char => {
|
||||||
const leetChars = Object.entries(this.leetMap)
|
const leetChars = Object.entries(this.leetMap)
|
||||||
.filter(([_, v]) => v === char.toLowerCase())
|
.filter(([, v]) => v === char.toLowerCase())
|
||||||
.map(([k, _]) => k);
|
.map(([k]) => k);
|
||||||
|
|
||||||
if (leetChars.length > 0) {
|
if (leetChars.length > 0) {
|
||||||
const allChars = [char, ...leetChars].map(c =>
|
const allChars = [char, ...leetChars].map(c =>
|
||||||
|
@ -234,7 +234,7 @@ class ProfanityFilterService {
|
||||||
let normalized = text.toLowerCase();
|
let normalized = text.toLowerCase();
|
||||||
|
|
||||||
// Replace multiple spaces/special chars with single space
|
// Replace multiple spaces/special chars with single space
|
||||||
normalized = normalized.replace(/[\s\-\_\*\.]+/g, ' ');
|
normalized = normalized.replace(/[\s\-_*.]+/g, ' ');
|
||||||
|
|
||||||
// Apply leet speak conversions
|
// Apply leet speak conversions
|
||||||
normalized = normalized.split('').map(char =>
|
normalized = normalized.split('').map(char =>
|
||||||
|
@ -317,7 +317,7 @@ class ProfanityFilterService {
|
||||||
/**
|
/**
|
||||||
* Filter profanity from text
|
* Filter profanity from text
|
||||||
*/
|
*/
|
||||||
filterProfanity(text: string, replacementChar: string = '*'): string {
|
filterProfanity(text: string): string {
|
||||||
const analysis = this.analyzeProfanity(text);
|
const analysis = this.analyzeProfanity(text);
|
||||||
return analysis.filtered;
|
return analysis.filtered;
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,7 +510,7 @@ describe('Admin API Routes', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle malformed JSON in request body', async () => {
|
it('should handle malformed JSON in request body', async () => {
|
||||||
const response = await request(app)
|
await request(app)
|
||||||
.post('/api/admin/profanity-words')
|
.post('/api/admin/profanity-words')
|
||||||
.set('Authorization', `Bearer ${authToken}`)
|
.set('Authorization', `Bearer ${authToken}`)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
|
@ -521,7 +521,7 @@ describe('Admin API Routes', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle missing content-type header', async () => {
|
it('should handle missing content-type header', async () => {
|
||||||
const response = await request(app)
|
await request(app)
|
||||||
.post('/api/admin/profanity-words')
|
.post('/api/admin/profanity-words')
|
||||||
.set('Authorization', `Bearer ${authToken}`)
|
.set('Authorization', `Bearer ${authToken}`)
|
||||||
.send('word=test&severity=low&category=test')
|
.send('word=test&severity=low&category=test')
|
||||||
|
|
|
@ -302,7 +302,7 @@ describe('Public API Routes', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle malformed JSON', async () => {
|
it('should handle malformed JSON', async () => {
|
||||||
const response = await request(app)
|
await request(app)
|
||||||
.post('/api/locations')
|
.post('/api/locations')
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.send('{"address": "Test Location"') // Missing closing brace
|
.send('{"address": "Test Location"') // Missing closing brace
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import { Database } from 'sqlite3';
|
import { Database } from 'sqlite3';
|
||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
// Setup test environment
|
// Setup test environment
|
||||||
process.env.NODE_ENV = 'test';
|
process.env.NODE_ENV = 'test';
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe('DatabaseService', () => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
try {
|
try {
|
||||||
databaseService.close();
|
databaseService.close();
|
||||||
} catch (e) {
|
} catch {
|
||||||
// Ignore close errors in tests
|
// Ignore close errors in tests
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue