mirror of
https://github.com/open-webui/open-webui
synced 2025-05-02 20:11:56 +00:00
refactor: Remove debug logs and streamline Google Drive picker code
This commit is contained in:
parent
1cc4eb241a
commit
7699db0666
@ -116,7 +116,6 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Adding file to upload queue:', fileItem);
|
|
||||||
files = [...files, fileItem];
|
files = [...files, fileItem];
|
||||||
// Check if the file is an audio file and transcribe/convert it to text file
|
// Check if the file is an audio file and transcribe/convert it to text file
|
||||||
if (['audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/x-m4a'].includes(file['type'])) {
|
if (['audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/x-m4a'].includes(file['type'])) {
|
||||||
|
@ -109,31 +109,19 @@ export const createPicker = () => {
|
|||||||
.setDeveloperKey(API_KEY)
|
.setDeveloperKey(API_KEY)
|
||||||
// Remove app ID setting as it's not needed and can cause 404 errors
|
// Remove app ID setting as it's not needed and can cause 404 errors
|
||||||
.setCallback(async (data: any) => {
|
.setCallback(async (data: any) => {
|
||||||
console.log('Picker callback received:', data);
|
|
||||||
if (data[google.picker.Response.ACTION] === google.picker.Action.PICKED) {
|
if (data[google.picker.Response.ACTION] === google.picker.Action.PICKED) {
|
||||||
try {
|
try {
|
||||||
console.log('File picked from Google Drive');
|
|
||||||
const doc = data[google.picker.Response.DOCUMENTS][0];
|
const doc = data[google.picker.Response.DOCUMENTS][0];
|
||||||
console.log('Document object:', doc);
|
|
||||||
|
|
||||||
const fileId = doc[google.picker.Document.ID];
|
const fileId = doc[google.picker.Document.ID];
|
||||||
const fileName = doc[google.picker.Document.NAME];
|
const fileName = doc[google.picker.Document.NAME];
|
||||||
const fileUrl = doc[google.picker.Document.URL];
|
const fileUrl = doc[google.picker.Document.URL];
|
||||||
|
|
||||||
console.log('Extracted file details:', {
|
|
||||||
id: fileId,
|
|
||||||
name: fileName,
|
|
||||||
url: fileUrl
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!fileId || !fileName) {
|
if (!fileId || !fileName) {
|
||||||
throw new Error('Required file details missing');
|
throw new Error('Required file details missing');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct download URL based on MIME type
|
// Construct download URL based on MIME type
|
||||||
console.log('Constructing download URL for fileId:', fileId);
|
|
||||||
const mimeType = doc[google.picker.Document.MIME_TYPE];
|
const mimeType = doc[google.picker.Document.MIME_TYPE];
|
||||||
console.log('File MIME type:', mimeType);
|
|
||||||
|
|
||||||
let downloadUrl;
|
let downloadUrl;
|
||||||
let exportFormat;
|
let exportFormat;
|
||||||
@ -154,11 +142,7 @@ export const createPicker = () => {
|
|||||||
// Regular files use direct download URL
|
// Regular files use direct download URL
|
||||||
downloadUrl = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`;
|
downloadUrl = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`;
|
||||||
}
|
}
|
||||||
console.log('Download URL constructed:', downloadUrl);
|
|
||||||
|
|
||||||
console.log('Current token value:', token ? 'Token exists' : 'No token');
|
|
||||||
// Create a Blob from the file download
|
// Create a Blob from the file download
|
||||||
console.log('Fetching file content...');
|
|
||||||
const response = await fetch(downloadUrl, {
|
const response = await fetch(downloadUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`,
|
'Authorization': `Bearer ${token}`,
|
||||||
@ -177,8 +161,6 @@ export const createPicker = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
console.log('File downloaded, size:', blob.size);
|
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
id: fileId,
|
id: fileId,
|
||||||
name: fileName,
|
name: fileName,
|
||||||
@ -189,10 +171,8 @@ export const createPicker = () => {
|
|||||||
'Accept': '*/*'
|
'Accept': '*/*'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log('Created result object with blob');
|
|
||||||
resolve(result);
|
resolve(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in picker callback:', error);
|
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
} else if (data[google.picker.Response.ACTION] === google.picker.Action.CANCEL) {
|
} else if (data[google.picker.Response.ACTION] === google.picker.Action.CANCEL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user