Skip to content

Commit

Permalink
πŸ”₯ Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario-SO committed Jan 21, 2025
1 parent 03361b3 commit 4c96f8e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 154 deletions.
51 changes: 4 additions & 47 deletions packages/app/components/misc/form/videoUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
eVisibilty,
} from 'streameth-new-server/src/interfaces/session.interface';
import { videoUpload } from '@/lib/services/videoUploadService';
import { apiUrl } from '@/lib/utils/utils';

function getVideoData(file: File) {
const dataTransfer = new DataTransfer();
Expand Down Expand Up @@ -108,57 +107,31 @@ const VideoUpload = forwardRef<HTMLInputElement, VideoUploadProps>(
if (!file) return '';

try {
console.log('πŸ“¦ Preparing animation video for upload:', {
fileName: file.name,
fileSize: file.size,
fileType: file.type,
lastModified: new Date(file.lastModified).toISOString()
});

const data = new FormData();
const sanitizedFileName = file.name.replace(/[^a-zA-Z0-9.]/g, '_');
console.log('πŸ”„ Sanitized file name:', sanitizedFileName);

const uploadFile = new File([file], sanitizedFileName, {
type: file.type,
});
data.set('file', uploadFile);
data.set('directory', path);

console.log('πŸš€ Starting animation upload to path:', {
path,
fileDetails: {
name: uploadFile.name,
size: uploadFile.size,
type: uploadFile.type
}
});

const videoUrl = await videoUpload({
data,
headers: {} // Let the browser handle Content-Type header with boundary
headers: {}
}).catch(async (error) => {
console.error('πŸ”₯ Video upload failed:', {
error,
message: error instanceof Error ? error.message : 'Unknown error',
stack: error instanceof Error ? error.stack : undefined,
response: error.response ? await error.response.text() : undefined
});
console.error('❌ Upload failed:', error instanceof Error ? error.message : 'Unknown error');
throw error;
});

if (!videoUrl) {
console.error('⚠️ No video URL returned from upload');
throw new Error('Error uploading animation: No URL returned');
throw new Error('No URL returned from upload');
}

console.log('βœ… Animation upload successful! URL:', videoUrl);
setPreview(videoUrl);

// Create session for animation if path includes 'animations'
const organizationId = path.split('/')[1]; // Extract org ID from path
try {
console.log('🎯 Creating animation session for organization:', organizationId);
await createSessionAction({
session: {
name: file.name.replace(/\.[^/.]+$/, ''), // Remove file extension
Expand All @@ -175,30 +148,14 @@ const VideoUpload = forwardRef<HTMLInputElement, VideoUploadProps>(
processingStatus: ProcessingStatus.completed,
},
});
console.log('✨ Animation session created successfully');
toast.success('Animation uploaded');
} catch (error) {
console.error('❌ Failed to create animation session:', {
error,
message: error instanceof Error ? error.message : 'Unknown error',
stack: error instanceof Error ? error.stack : undefined,
organizationId,
videoUrl
});
console.error('❌ Session creation failed:', error instanceof Error ? error.message : 'Unknown error');
toast.error('Failed to create animation session');
// Continue even if session creation fails, as we still have the video URL
}

return videoUrl;
} catch (e) {
console.error('❌ Animation upload failed:', {
error: e,
message: e instanceof Error ? e.message : 'Unknown error',
stack: e instanceof Error ? e.stack : undefined,
fileName: file.name,
fileSize: file.size,
path
});
setPreview('');
throw e;
} finally {
Expand Down
69 changes: 0 additions & 69 deletions packages/app/lib/actions/videoUpload.ts

This file was deleted.

41 changes: 3 additions & 38 deletions packages/app/lib/services/videoUploadService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { apiUrl } from '../utils/utils';
import { fetchClient } from './fetch-client';

export const videoUpload = async ({
data,
Expand All @@ -11,62 +10,28 @@ export const videoUpload = async ({
const uploadUrl = `${apiUrl()}/upload`;

try {
console.log('πŸŽ₯ Starting video upload service call:', {
url: uploadUrl,
fileSize: (data.get('file') as File)?.size,
fileName: (data.get('file') as File)?.name,
fileType: (data.get('file') as File)?.type,
directory: data.get('directory'),
apiEndpoint: apiUrl()
});

console.log('πŸ”‘ Checking auth headers and preparing request...');
const response = await fetch(uploadUrl, {
method: 'POST',
cache: 'no-cache',
headers: {
...headers,
// Remove Content-Type header to let the browser set it with the correct boundary
},
body: data,
});

if (!response.ok) {
const errorText = await response.text();
console.error('❌ Video upload service failed:', {
console.error('❌ Upload failed:', {
status: response.status,
statusText: response.statusText,
error: errorText,
headers: Object.fromEntries(response.headers.entries()),
url: uploadUrl
error: errorText
});
throw new Error(`Error uploading video: ${errorText}`);
}

const result = await response.json();
console.log('βœ… Video upload service successful:', {
result,
responseHeaders: Object.fromEntries(response.headers.entries()),
uploadedUrl: result.data,
status: response.status,
statusText: response.statusText
});

console.log('🎬 Video processing status:', {
url: result.data,
status: 'completed',
timestamp: new Date().toISOString()
});

return result.data;
} catch (e) {
console.error('πŸ’₯ Error in video upload service:', {
error: e,
message: e instanceof Error ? e.message : 'Unknown error',
stack: e instanceof Error ? e.stack : undefined,
url: uploadUrl,
timestamp: new Date().toISOString()
});
console.error('❌ Upload error:', e instanceof Error ? e.message : 'Unknown error');
throw e;
}
};

0 comments on commit 4c96f8e

Please sign in to comment.