cleanup
This commit is contained in:
		
							parent
							
								
									b8311e152d
								
							
						
					
					
						commit
						b1c31379b2
					
				@ -1,4 +1,3 @@
 | 
				
			|||||||
// src/pages/api/upload/media.ts - Enhanced with detailed logging and error handling
 | 
					 | 
				
			||||||
import type { APIRoute } from 'astro';
 | 
					import type { APIRoute } from 'astro';
 | 
				
			||||||
import { withAPIAuth } from '../../../utils/auth.js';
 | 
					import { withAPIAuth } from '../../../utils/auth.js';
 | 
				
			||||||
import { apiResponse, apiError, apiServerError, apiSpecial, handleAPIRequest } from '../../../utils/api.js';
 | 
					import { apiResponse, apiError, apiServerError, apiSpecial, handleAPIRequest } from '../../../utils/api.js';
 | 
				
			||||||
@ -21,13 +20,10 @@ interface UploadResult {
 | 
				
			|||||||
const UPLOAD_CONFIG = {
 | 
					const UPLOAD_CONFIG = {
 | 
				
			||||||
  maxFileSize: 50 * 1024 * 1024, // 50MB
 | 
					  maxFileSize: 50 * 1024 * 1024, // 50MB
 | 
				
			||||||
  allowedTypes: new Set([
 | 
					  allowedTypes: new Set([
 | 
				
			||||||
    // Images
 | 
					 | 
				
			||||||
    'image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp', 'image/svg+xml',
 | 
					    'image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp', 'image/svg+xml',
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Videos
 | 
					 | 
				
			||||||
    'video/mp4', 'video/webm', 'video/ogg', 'video/avi', 'video/mov',
 | 
					    'video/mp4', 'video/webm', 'video/ogg', 'video/avi', 'video/mov',
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Documents
 | 
					 | 
				
			||||||
    'application/pdf',
 | 
					    'application/pdf',
 | 
				
			||||||
    'application/msword',
 | 
					    'application/msword',
 | 
				
			||||||
    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
 | 
					    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
 | 
				
			||||||
@ -36,17 +32,15 @@ const UPLOAD_CONFIG = {
 | 
				
			|||||||
    'application/vnd.ms-powerpoint',
 | 
					    'application/vnd.ms-powerpoint',
 | 
				
			||||||
    'application/vnd.openxmlformats-officedocument.presentationml.presentation',
 | 
					    'application/vnd.openxmlformats-officedocument.presentationml.presentation',
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Text files
 | 
					 | 
				
			||||||
    'text/plain', 
 | 
					    'text/plain', 
 | 
				
			||||||
    'text/csv', 
 | 
					    'text/csv', 
 | 
				
			||||||
    'text/markdown',           // Added markdown
 | 
					    'text/markdown',          
 | 
				
			||||||
    'text/x-markdown',         // Alternative markdown MIME type
 | 
					    'text/x-markdown',         
 | 
				
			||||||
    'application/json',
 | 
					    'application/json',
 | 
				
			||||||
    'application/xml',
 | 
					    'application/xml',
 | 
				
			||||||
    'text/xml',
 | 
					    'text/xml',
 | 
				
			||||||
    'text/html',
 | 
					    'text/html',
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Archives
 | 
					 | 
				
			||||||
    'application/zip', 
 | 
					    'application/zip', 
 | 
				
			||||||
    'application/x-tar', 
 | 
					    'application/x-tar', 
 | 
				
			||||||
    'application/gzip',
 | 
					    'application/gzip',
 | 
				
			||||||
@ -55,10 +49,9 @@ const UPLOAD_CONFIG = {
 | 
				
			|||||||
    'application/x-rar-compressed',
 | 
					    'application/x-rar-compressed',
 | 
				
			||||||
    'application/x-7z-compressed',
 | 
					    'application/x-7z-compressed',
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Additional useful formats
 | 
					    'application/rtf',
 | 
				
			||||||
    'application/rtf',         // Rich Text Format
 | 
					 | 
				
			||||||
    'text/richtext',
 | 
					    'text/richtext',
 | 
				
			||||||
    'application/x-yaml',      // YAML files
 | 
					    'application/x-yaml',
 | 
				
			||||||
    'text/yaml',
 | 
					    'text/yaml',
 | 
				
			||||||
    'application/yaml'
 | 
					    'application/yaml'
 | 
				
			||||||
  ]),
 | 
					  ]),
 | 
				
			||||||
@ -185,7 +178,6 @@ export const POST: APIRoute = async ({ request }) => {
 | 
				
			|||||||
  return await handleAPIRequest(async () => {
 | 
					  return await handleAPIRequest(async () => {
 | 
				
			||||||
    console.log('[UPLOAD] Processing upload request');
 | 
					    console.log('[UPLOAD] Processing upload request');
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Enhanced auth logging
 | 
					 | 
				
			||||||
    const authResult = await withAPIAuth(request, 'contributions');
 | 
					    const authResult = await withAPIAuth(request, 'contributions');
 | 
				
			||||||
    console.log('[UPLOAD] Auth result:', {
 | 
					    console.log('[UPLOAD] Auth result:', {
 | 
				
			||||||
      authenticated: authResult.authenticated,
 | 
					      authenticated: authResult.authenticated,
 | 
				
			||||||
@ -230,7 +222,6 @@ export const POST: APIRoute = async ({ request }) => {
 | 
				
			|||||||
      return apiError.badRequest(validation.error!);
 | 
					      return apiError.badRequest(validation.error!);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Enhanced environment logging
 | 
					 | 
				
			||||||
    const nextcloudConfigured = isNextcloudConfigured();
 | 
					    const nextcloudConfigured = isNextcloudConfigured();
 | 
				
			||||||
    console.log('[UPLOAD] Environment check:', {
 | 
					    console.log('[UPLOAD] Environment check:', {
 | 
				
			||||||
      nextcloudConfigured,
 | 
					      nextcloudConfigured,
 | 
				
			||||||
 | 
				
			|||||||
@ -309,7 +309,6 @@ class KnowledgebaseForm {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  private handleFiles(files: File[]) {
 | 
					  private handleFiles(files: File[]) {
 | 
				
			||||||
    files.forEach(file => {
 | 
					    files.forEach(file => {
 | 
				
			||||||
      // Client-side validation before upload
 | 
					 | 
				
			||||||
      const validation = this.validateFileBeforeUpload(file);
 | 
					      const validation = this.validateFileBeforeUpload(file);
 | 
				
			||||||
      if (!validation.valid) {
 | 
					      if (!validation.valid) {
 | 
				
			||||||
        console.log('[UPLOAD]Cannot upload ', file.name, ' Error: ', validation.error);
 | 
					        console.log('[UPLOAD]Cannot upload ', file.name, ' Error: ', validation.error);
 | 
				
			||||||
@ -340,7 +339,6 @@ class KnowledgebaseForm {
 | 
				
			|||||||
      };
 | 
					      };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Check file type
 | 
					 | 
				
			||||||
    const allowedExtensions = [
 | 
					    const allowedExtensions = [
 | 
				
			||||||
      '.pdf', '.doc', '.docx', '.txt', '.md', '.markdown', '.csv', '.json', 
 | 
					      '.pdf', '.doc', '.docx', '.txt', '.md', '.markdown', '.csv', '.json', 
 | 
				
			||||||
      '.xml', '.html', '.rtf', '.yaml', '.yml', '.zip', '.tar', '.gz', 
 | 
					      '.xml', '.html', '.rtf', '.yaml', '.yml', '.zip', '.tar', '.gz', 
 | 
				
			||||||
 | 
				
			|||||||
@ -12,7 +12,6 @@ const data = await getToolsData();
 | 
				
			|||||||
const tools = data.tools;
 | 
					const tools = data.tools;
 | 
				
			||||||
const phases = data.phases;
 | 
					const phases = data.phases;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Check AI authentication requirements
 | 
					 | 
				
			||||||
const aiAuthRequired = getAuthRequirementForContext('ai');
 | 
					const aiAuthRequired = getAuthRequirementForContext('ai');
 | 
				
			||||||
let aiAuthContext: { authenticated: boolean; userId: string; session?: any; authRequired: boolean; } | null = null;
 | 
					let aiAuthContext: { authenticated: boolean; userId: string; session?: any; authRequired: boolean; } | null = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -332,7 +331,6 @@ if (aiAuthRequired) {
 | 
				
			|||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Handle AI authentication button click
 | 
					 | 
				
			||||||
    if (aiLoginBtn) {
 | 
					    if (aiLoginBtn) {
 | 
				
			||||||
      aiLoginBtn.addEventListener('click', () => {
 | 
					      aiLoginBtn.addEventListener('click', () => {
 | 
				
			||||||
        const currentUrl = encodeURIComponent(window.location.href);
 | 
					        const currentUrl = encodeURIComponent(window.location.href);
 | 
				
			||||||
@ -385,7 +383,6 @@ if (aiAuthRequired) {
 | 
				
			|||||||
          if (filtersSection) filtersSection.style.display = 'block';
 | 
					          if (filtersSection) filtersSection.style.display = 'block';
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        case 'ai':
 | 
					        case 'ai':
 | 
				
			||||||
          // Only show AI interface if authentication allows it
 | 
					 | 
				
			||||||
          if (aiAuthRequired && !aiAuthenticated) {
 | 
					          if (aiAuthRequired && !aiAuthenticated) {
 | 
				
			||||||
            console.log('[AUTH] AI access denied, redirecting to login');
 | 
					            console.log('[AUTH] AI access denied, redirecting to login');
 | 
				
			||||||
            const currentUrl = encodeURIComponent(window.location.href);
 | 
					            const currentUrl = encodeURIComponent(window.location.href);
 | 
				
			||||||
 | 
				
			|||||||
@ -91,7 +91,6 @@ class AuditService {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private loadConfig(): AuditConfig {
 | 
					  private loadConfig(): AuditConfig {
 | 
				
			||||||
    // Use the env() helper function that handles both server and client contexts
 | 
					 | 
				
			||||||
    const enabledFlag = env('FORENSIC_AUDIT_ENABLED', 'false');
 | 
					    const enabledFlag = env('FORENSIC_AUDIT_ENABLED', 'false');
 | 
				
			||||||
    const detailLevel = env('FORENSIC_AUDIT_DETAIL_LEVEL', 'standard') as 'minimal' | 'standard' | 'verbose';
 | 
					    const detailLevel = env('FORENSIC_AUDIT_DETAIL_LEVEL', 'standard') as 'minimal' | 'standard' | 'verbose';
 | 
				
			||||||
    const retentionHours = parseInt(env('FORENSIC_AUDIT_RETENTION_HOURS', '72') || '72', 10);
 | 
					    const retentionHours = parseInt(env('FORENSIC_AUDIT_RETENTION_HOURS', '72') || '72', 10);
 | 
				
			||||||
@ -398,9 +397,7 @@ class AuditService {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const auditService = new AuditService();
 | 
					export const auditService = new AuditService();
 | 
				
			||||||
export type { ProcessedAuditTrail, CompressedAuditEntry };
 | 
					export type { ProcessedAuditTrail, CompressedAuditEntry };
 | 
				
			||||||
// Add this at the bottom of auditService.ts (after the existing exports)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Export debug utilities for troubleshooting
 | 
					 | 
				
			||||||
export const debugAuditService = {
 | 
					export const debugAuditService = {
 | 
				
			||||||
  getDebugInfo() {
 | 
					  getDebugInfo() {
 | 
				
			||||||
    return auditService.getDebugInfo();
 | 
					    return auditService.getDebugInfo();
 | 
				
			||||||
 | 
				
			|||||||
@ -467,7 +467,6 @@ const embeddingsService = new EmbeddingsService();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export { embeddingsService, type EmbeddingData, type SimilarityResult };
 | 
					export { embeddingsService, type EmbeddingData, type SimilarityResult };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Export utility functions for debugging
 | 
					 | 
				
			||||||
export const debugEmbeddings = {
 | 
					export const debugEmbeddings = {
 | 
				
			||||||
  async recheckEnvironment() {
 | 
					  async recheckEnvironment() {
 | 
				
			||||||
    return embeddingsService.forceRecheckEnvironment();
 | 
					    return embeddingsService.forceRecheckEnvironment();
 | 
				
			||||||
@ -475,6 +474,4 @@ export const debugEmbeddings = {
 | 
				
			|||||||
  getStatus() {
 | 
					  getStatus() {
 | 
				
			||||||
    return embeddingsService.getStats();
 | 
					    return embeddingsService.getStats();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					 | 
				
			||||||
// Remove auto-initialization - let it initialize lazily when first needed
 | 
					 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user