Skip to content

Commit

Permalink
πŸ”Š Latest logs of the day
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario-SO committed Jan 20, 2025
1 parent f0a741e commit eb57a47
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 15 deletions.
52 changes: 46 additions & 6 deletions packages/app/lib/actions/videoUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,65 @@ import { videoUpload } from '../services/videoUploadService';

export const videoUploadAction = async ({ data }: { data: FormData }) => {
try {
console.log('πŸ“€ Starting video upload action');
console.log('πŸ“ FormData contents:', {
console.log('πŸ“€ Starting video upload action with details:', {
fileName: (data.get('file') as File)?.name,
fileSize: `${((data.get('file') as File)?.size / 1024 / 1024).toFixed(2)}MB`,
fileType: (data.get('file') as File)?.type,
directory: data.get('directory'),
fileSize: (data.get('file') as File)?.size,
formDataKeys: Array.from(data.keys()),
timestamp: new Date().toISOString()
});

// Validate form data
const file = data.get('file') as File;
const directory = data.get('directory');

if (!file) {
console.error('❌ Video upload validation failed: No file in FormData');
throw new Error('No file provided');
}

if (!directory) {
console.error('❌ Video upload validation failed: No directory in FormData');
throw new Error('No directory provided');
}

console.log('βœ… FormData validation passed, calling video upload service');

const res = await videoUpload({
data,
}).catch(error => {
console.error('❌ Video upload service failed:', {
error,
message: error instanceof Error ? error.message : 'Unknown error',
stack: error instanceof Error ? error.stack : undefined,
fileName: file.name,
fileSize: file.size,
directory
});
throw error;
});
console.log('✨ Video upload action completed successfully');
revalidatePath('/studio');

if (!res) {
console.error('❌ Video upload failed: No response from upload service');
throw new Error('No response from upload service');
}

console.log('✨ Video upload action completed successfully:', {
result: res,
fileName: file.name,
directory
});

revalidatePath('/studio');
return res;
} catch (e) {
console.error('πŸ’₯ Error in video upload action:', {
error: e,
message: e instanceof Error ? e.message : 'Unknown error',
stack: e instanceof Error ? e.stack : undefined
stack: e instanceof Error ? e.stack : undefined,
formDataKeys: Array.from(data.keys()),
timestamp: new Date().toISOString()
});
throw e;
}
Expand Down
39 changes: 30 additions & 9 deletions packages/app/lib/services/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@
import { auth } from '@/auth';

export const fetchClient = async (url: string, options: RequestInit = {}) => {
const requestId = Math.random().toString(36).substring(7);
try {
console.log('🌐 Fetch client starting request:', {
console.log(`🌐 [${requestId}] Fetch client starting request:`, {
url,
method: options.method || 'GET',
hasBody: !!options.body,
bodyType: options.body instanceof FormData ? 'FormData' : typeof options.body,
bodySize: options.body instanceof FormData ?
`${((options.body.get('file') as File)?.size || 0) / 1024 / 1024}MB` :
undefined,
timestamp: new Date().toISOString()
});

const session = await auth();
const headers = new Headers(options.headers);

if (session?.accessToken) {
console.log('πŸ” Adding auth token to request');
console.log(`πŸ” [${requestId}] Adding auth token to request`);
headers.set('Authorization', `Bearer ${session.accessToken}`);
} else {
console.warn('⚠️ No auth token available for request:', {
console.warn(`⚠️ [${requestId}] No auth token available for request:`, {
url,
method: options.method,
timestamp: new Date().toISOString()
});
}

console.log('πŸ“‘ Making request with headers:', {
console.log(`πŸ“‘ [${requestId}] Making request with headers:`, {
method: options.method,
headers: Object.fromEntries(headers.entries()),
hasBody: !!options.body,
Expand All @@ -41,20 +45,37 @@ export const fetchClient = async (url: string, options: RequestInit = {}) => {
});
const endTime = Date.now();

console.log('πŸ“₯ Received response:', {
const responseHeaders = Object.fromEntries(response.headers.entries());
const contentType = responseHeaders['content-type'] || '';

console.log(`πŸ“₯ [${requestId}] Received response:`, {
status: response.status,
statusText: response.statusText,
headers: Object.fromEntries(response.headers.entries()),
headers: responseHeaders,
timeToComplete: `${endTime - startTime}ms`,
contentType,
url,
timestamp: new Date().toISOString()
});

if (!response.ok) {
console.error('❌ Request failed:', {
let errorDetails;
try {
// Try to parse error response
if (contentType.includes('application/json')) {
errorDetails = await response.clone().json();
} else {
errorDetails = await response.clone().text();
}
} catch (e) {
errorDetails = 'Could not parse error response';
}

console.error(`❌ [${requestId}] Request failed:`, {
status: response.status,
statusText: response.statusText,
headers: Object.fromEntries(response.headers.entries()),
headers: responseHeaders,
error: errorDetails,
url,
method: options.method,
timestamp: new Date().toISOString()
Expand All @@ -63,7 +84,7 @@ export const fetchClient = async (url: string, options: RequestInit = {}) => {

return response;
} catch (e) {
console.error('πŸ’₯ Error in fetch client:', {
console.error(`πŸ’₯ [${requestId}] Error in fetch client:`, {
error: e,
message: e instanceof Error ? e.message : 'Unknown error',
stack: e instanceof Error ? e.stack : undefined,
Expand Down

0 comments on commit eb57a47

Please sign in to comment.