fix: display image correctly in recognition history when input from URL
This commit is contained in:
parent
b38a40911b
commit
7da3c8e81b
23
worker.js
23
worker.js
@ -1638,6 +1638,20 @@ function getHTML() {
|
|||||||
' loading.style.display = \'block\';',
|
' loading.style.display = \'block\';',
|
||||||
' resultContainer.classList.remove(\'show\');',
|
' resultContainer.classList.remove(\'show\');',
|
||||||
|
|
||||||
|
' // 先获取图片并转换为base64',
|
||||||
|
' let imageData;',
|
||||||
|
' try {',
|
||||||
|
' const imgResponse = await fetch(imageUrl);',
|
||||||
|
' const blob = await imgResponse.blob();',
|
||||||
|
' imageData = await new Promise((resolve) => {',
|
||||||
|
' const reader = new FileReader();',
|
||||||
|
' reader.onloadend = () => resolve(reader.result);',
|
||||||
|
' reader.readAsDataURL(blob);',
|
||||||
|
' });',
|
||||||
|
' } catch (error) {',
|
||||||
|
' throw new Error(\'图片URL无法访问或格式不正确\');',
|
||||||
|
' }',
|
||||||
|
|
||||||
' // 调用URL识别API',
|
' // 调用URL识别API',
|
||||||
' const response = await fetch(\'/api/recognize/url\', {',
|
' const response = await fetch(\'/api/recognize/url\', {',
|
||||||
' method: \'POST\',',
|
' method: \'POST\',',
|
||||||
@ -1654,7 +1668,7 @@ function getHTML() {
|
|||||||
' }',
|
' }',
|
||||||
|
|
||||||
' // 显示预览图',
|
' // 显示预览图',
|
||||||
' previewImage.src = imageUrl;',
|
' previewImage.src = imageData; // 使用base64数据',
|
||||||
' previewImage.style.display = \'block\';',
|
' previewImage.style.display = \'block\';',
|
||||||
|
|
||||||
' // 显示结果',
|
' // 显示结果',
|
||||||
@ -1677,8 +1691,9 @@ function getHTML() {
|
|||||||
' }',
|
' }',
|
||||||
' });',
|
' });',
|
||||||
|
|
||||||
' // 添加到历史记录',
|
' // 添加到历史记录 - 使用base64图片数据而不是URL',
|
||||||
' historyManager.addHistory(currentToken, imageUrl, result);',
|
' historyManager.addHistory(currentToken, imageData, result);',
|
||||||
|
|
||||||
' } catch (error) {',
|
' } catch (error) {',
|
||||||
' resultDiv.textContent = \'处理失败: \' + error.message;',
|
' resultDiv.textContent = \'处理失败: \' + error.message;',
|
||||||
' resultContainer.classList.add(\'show\');',
|
' resultContainer.classList.add(\'show\');',
|
||||||
@ -1687,7 +1702,7 @@ function getHTML() {
|
|||||||
' loading.style.display = \'none\';',
|
' loading.style.display = \'none\';',
|
||||||
' }',
|
' }',
|
||||||
' }',
|
' }',
|
||||||
' }, 1000));', // 1秒防抖',
|
' }, 1000)); // 1秒防抖',
|
||||||
|
|
||||||
' // 防抖函数',
|
' // 防抖函数',
|
||||||
' function debounce(func, wait) {',
|
' function debounce(func, wait) {',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user