forked from open-webui/open-webui
		
	fix: cors & #281
This commit is contained in:
		
							parent
							
								
									0c30a08596
								
							
						
					
					
						commit
						0ae57b5ae1
					
				
					 5 changed files with 20 additions and 49 deletions
				
			
		|  | @ -83,7 +83,7 @@ | |||
| 		blocks.forEach((block) => { | ||||
| 			// only add button if browser supports Clipboard API | ||||
| 
 | ||||
| 			if (navigator.clipboard && block.childNodes.length < 2 && block.id !== 'user-message') { | ||||
| 			if (block.childNodes.length < 2 && block.id !== 'user-message') { | ||||
| 				let code = block.querySelector('code'); | ||||
| 				code.style.borderTopRightRadius = 0; | ||||
| 				code.style.borderTopLeftRadius = 0; | ||||
|  | @ -121,10 +121,6 @@ | |||
| 				topBarDiv.appendChild(button); | ||||
| 
 | ||||
| 				block.prepend(topBarDiv); | ||||
| 
 | ||||
| 				// button.addEventListener('click', async () => { | ||||
| 				// 	await copyCode(block, button); | ||||
| 				// }); | ||||
| 			} | ||||
| 		}); | ||||
| 
 | ||||
|  | @ -132,7 +128,7 @@ | |||
| 			let code = block.querySelector('code'); | ||||
| 			let text = code.innerText; | ||||
| 
 | ||||
| 			await navigator.clipboard.writeText(text); | ||||
| 			await copyToClipboard(text); | ||||
| 
 | ||||
| 			// visual feedback that task is completed | ||||
| 			button.innerText = 'Copied!'; | ||||
|  |  | |||
|  | @ -1,12 +1,13 @@ | |||
| import { dev, browser } from '$app/environment'; | ||||
| import { PUBLIC_API_BASE_URL } from '$env/static/public'; | ||||
| 
 | ||||
| export const OLLAMA_API_BASE_URL = | ||||
| 	PUBLIC_API_BASE_URL === '' | ||||
| 		? browser | ||||
| 			? `http://${location.hostname}:11434/api` | ||||
| 			: `http://localhost:11434/api` | ||||
| 		: PUBLIC_API_BASE_URL; | ||||
| export const OLLAMA_API_BASE_URL = dev | ||||
| 	? `http://${location.hostname}:8080/ollama/api` | ||||
| 	: PUBLIC_API_BASE_URL === '' | ||||
| 	? browser | ||||
| 		? `http://${location.hostname}:11434/api` | ||||
| 		: `http://localhost:11434/api` | ||||
| 	: PUBLIC_API_BASE_URL; | ||||
| 
 | ||||
| export const WEBUI_BASE_URL = dev ? `http://${location.hostname}:8080` : ``; | ||||
| export const WEBUI_API_BASE_URL = `${WEBUI_BASE_URL}/api/v1`; | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ | |||
| 
 | ||||
| 	import { OLLAMA_API_BASE_URL } from '$lib/constants'; | ||||
| 	import { onMount, tick } from 'svelte'; | ||||
| 	import { convertMessagesToHistory, splitStream } from '$lib/utils'; | ||||
| 	import { convertMessagesToHistory, copyToClipboard, splitStream } from '$lib/utils'; | ||||
| 	import { goto } from '$app/navigation'; | ||||
| 	import { config, models, modelfiles, user, settings, db, chats, chatId } from '$lib/stores'; | ||||
| 
 | ||||
|  | @ -113,41 +113,6 @@ | |||
| 		} | ||||
| 	}; | ||||
| 
 | ||||
| 	const copyToClipboard = (text) => { | ||||
| 		if (!navigator.clipboard) { | ||||
| 			var textArea = document.createElement('textarea'); | ||||
| 			textArea.value = text; | ||||
| 
 | ||||
| 			// Avoid scrolling to bottom | ||||
| 			textArea.style.top = '0'; | ||||
| 			textArea.style.left = '0'; | ||||
| 			textArea.style.position = 'fixed'; | ||||
| 
 | ||||
| 			document.body.appendChild(textArea); | ||||
| 			textArea.focus(); | ||||
| 			textArea.select(); | ||||
| 
 | ||||
| 			try { | ||||
| 				var successful = document.execCommand('copy'); | ||||
| 				var msg = successful ? 'successful' : 'unsuccessful'; | ||||
| 				console.log('Fallback: Copying text command was ' + msg); | ||||
| 			} catch (err) { | ||||
| 				console.error('Fallback: Oops, unable to copy', err); | ||||
| 			} | ||||
| 
 | ||||
| 			document.body.removeChild(textArea); | ||||
| 			return; | ||||
| 		} | ||||
| 		navigator.clipboard.writeText(text).then( | ||||
| 			function () { | ||||
| 				console.log('Async: Copying to clipboard was successful!'); | ||||
| 			}, | ||||
| 			function (err) { | ||||
| 				console.error('Async: Could not copy text: ', err); | ||||
| 			} | ||||
| 		); | ||||
| 	}; | ||||
| 
 | ||||
| 	////////////////////////// | ||||
| 	// Ollama functions | ||||
| 	////////////////////////// | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek