mirror of
https://github.com/open-webui/open-webui
synced 2025-06-15 02:41:30 +00:00
chore: format
This commit is contained in:
parent
c2eada36f1
commit
e2d60bd92e
@ -65,7 +65,6 @@ async def process_filter_functions(
|
|||||||
**(valves if valves else {})
|
**(valves if valves else {})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Prepare parameters
|
# Prepare parameters
|
||||||
sig = inspect.signature(handler)
|
sig = inspect.signature(handler)
|
||||||
|
@ -6,7 +6,7 @@ let CLIENT_ID = '';
|
|||||||
|
|
||||||
async function getCredentials() {
|
async function getCredentials() {
|
||||||
if (CLIENT_ID) return;
|
if (CLIENT_ID) return;
|
||||||
|
|
||||||
const response = await fetch('/api/config');
|
const response = await fetch('/api/config');
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch OneDrive credentials');
|
throw new Error('Failed to fetch OneDrive credentials');
|
||||||
@ -18,7 +18,6 @@ async function getCredentials() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let msalInstance: PublicClientApplication | null = null;
|
let msalInstance: PublicClientApplication | null = null;
|
||||||
|
|
||||||
// Initialize MSAL authentication
|
// Initialize MSAL authentication
|
||||||
@ -27,24 +26,26 @@ async function initializeMsal() {
|
|||||||
if (!CLIENT_ID) {
|
if (!CLIENT_ID) {
|
||||||
await getCredentials();
|
await getCredentials();
|
||||||
}
|
}
|
||||||
|
|
||||||
const msalParams = {
|
const msalParams = {
|
||||||
auth: {
|
auth: {
|
||||||
authority: 'https://login.microsoftonline.com/consumers',
|
authority: 'https://login.microsoftonline.com/consumers',
|
||||||
clientId: CLIENT_ID
|
clientId: CLIENT_ID
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!msalInstance) {
|
if (!msalInstance) {
|
||||||
msalInstance = new PublicClientApplication(msalParams);
|
msalInstance = new PublicClientApplication(msalParams);
|
||||||
if (msalInstance.initialize) {
|
if (msalInstance.initialize) {
|
||||||
await msalInstance.initialize();
|
await msalInstance.initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return msalInstance;
|
return msalInstance;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error('MSAL initialization failed: ' + (error instanceof Error ? error.message : String(error)));
|
throw new Error(
|
||||||
|
'MSAL initialization failed: ' + (error instanceof Error ? error.message : String(error))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,14 +58,14 @@ async function getToken(): Promise<string> {
|
|||||||
if (!msalInstance) {
|
if (!msalInstance) {
|
||||||
throw new Error('MSAL not initialized');
|
throw new Error('MSAL not initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
const resp = await msalInstance.acquireTokenSilent(authParams);
|
const resp = await msalInstance.acquireTokenSilent(authParams);
|
||||||
accessToken = resp.accessToken;
|
accessToken = resp.accessToken;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!msalInstance) {
|
if (!msalInstance) {
|
||||||
throw new Error('MSAL not initialized');
|
throw new Error('MSAL not initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await msalInstance.loginPopup(authParams);
|
const resp = await msalInstance.loginPopup(authParams);
|
||||||
msalInstance.setActiveAccount(resp.account);
|
msalInstance.setActiveAccount(resp.account);
|
||||||
@ -73,14 +74,17 @@ async function getToken(): Promise<string> {
|
|||||||
accessToken = resp2.accessToken;
|
accessToken = resp2.accessToken;
|
||||||
}
|
}
|
||||||
} catch (popupError) {
|
} catch (popupError) {
|
||||||
throw new Error('Failed to login: ' + (popupError instanceof Error ? popupError.message : String(popupError)));
|
throw new Error(
|
||||||
|
'Failed to login: ' +
|
||||||
|
(popupError instanceof Error ? popupError.message : String(popupError))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
throw new Error('Failed to acquire access token');
|
throw new Error('Failed to acquire access token');
|
||||||
}
|
}
|
||||||
|
|
||||||
return accessToken;
|
return accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +110,6 @@ const params = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Download file from OneDrive
|
// Download file from OneDrive
|
||||||
async function downloadOneDriveFile(fileInfo: any): Promise<Blob> {
|
async function downloadOneDriveFile(fileInfo: any): Promise<Blob> {
|
||||||
const accessToken = await getToken();
|
const accessToken = await getToken();
|
||||||
@ -228,17 +231,17 @@ export async function openOneDrivePicker(): Promise<any | null> {
|
|||||||
if (!authToken) {
|
if (!authToken) {
|
||||||
return reject(new Error('Failed to acquire access token'));
|
return reject(new Error('Failed to acquire access token'));
|
||||||
}
|
}
|
||||||
|
|
||||||
pickerWindow = window.open('', 'OneDrivePicker', 'width=800,height=600');
|
pickerWindow = window.open('', 'OneDrivePicker', 'width=800,height=600');
|
||||||
if (!pickerWindow) {
|
if (!pickerWindow) {
|
||||||
return reject(new Error('Failed to open OneDrive picker window'));
|
return reject(new Error('Failed to open OneDrive picker window'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryString = new URLSearchParams({
|
const queryString = new URLSearchParams({
|
||||||
filePicker: JSON.stringify(params)
|
filePicker: JSON.stringify(params)
|
||||||
});
|
});
|
||||||
const url = `${baseUrl}?${queryString.toString()}`;
|
const url = `${baseUrl}?${queryString.toString()}`;
|
||||||
|
|
||||||
const form = pickerWindow.document.createElement('form');
|
const form = pickerWindow.document.createElement('form');
|
||||||
form.setAttribute('action', url);
|
form.setAttribute('action', url);
|
||||||
form.setAttribute('method', 'POST');
|
form.setAttribute('method', 'POST');
|
||||||
@ -247,10 +250,10 @@ export async function openOneDrivePicker(): Promise<any | null> {
|
|||||||
input.setAttribute('name', 'access_token');
|
input.setAttribute('name', 'access_token');
|
||||||
input.setAttribute('value', authToken);
|
input.setAttribute('value', authToken);
|
||||||
form.appendChild(input);
|
form.appendChild(input);
|
||||||
|
|
||||||
pickerWindow.document.body.appendChild(form);
|
pickerWindow.document.body.appendChild(form);
|
||||||
form.submit();
|
form.submit();
|
||||||
|
|
||||||
window.addEventListener('message', handleWindowMessage);
|
window.addEventListener('message', handleWindowMessage);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (pickerWindow) {
|
if (pickerWindow) {
|
||||||
@ -267,14 +270,14 @@ export async function openOneDrivePicker(): Promise<any | null> {
|
|||||||
// Pick and download file from OneDrive
|
// Pick and download file from OneDrive
|
||||||
export async function pickAndDownloadFile(): Promise<{ blob: Blob; name: string } | null> {
|
export async function pickAndDownloadFile(): Promise<{ blob: Blob; name: string } | null> {
|
||||||
const pickerResult = await openOneDrivePicker();
|
const pickerResult = await openOneDrivePicker();
|
||||||
|
|
||||||
if (!pickerResult || !pickerResult.items || pickerResult.items.length === 0) {
|
if (!pickerResult || !pickerResult.items || pickerResult.items.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedFile = pickerResult.items[0];
|
const selectedFile = pickerResult.items[0];
|
||||||
const blob = await downloadOneDriveFile(selectedFile);
|
const blob = await downloadOneDriveFile(selectedFile);
|
||||||
|
|
||||||
return { blob, name: selectedFile.name };
|
return { blob, name: selectedFile.name };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user