解决发布测试bug
This commit is contained in:
1 parent
7f66d6f20c
commit
a148f76217
3 files changed
+23
-49
No files matched your search
+10
-4
@@ -466,10 +466,16 @@ def _convert_excel_to_xlsx(content: bytes, ext: str) -> bytes:
|
||||
stderr = process.stderr.decode('utf-8', errors='ignore').strip()
|
||||
errors.append(f"{cmd}: {stderr or f'code={process.returncode}'}")
|
||||
|
||||
if _convert_excel_via_windows_office(input_path, output_path):
|
||||
with open(output_path, 'rb') as f:
|
||||
return f.read()
|
||||
errors.append("windows-office: failed to convert xls via WPS/MS Excel")
|
||||
allow_windows_excel_preview = (
|
||||
os.getenv('ENABLE_WINDOWS_EXCEL_PREVIEW_CONVERSION', '').strip().lower() in ('1', 'true', 'yes', 'on')
|
||||
)
|
||||
if allow_windows_excel_preview:
|
||||
if _convert_excel_via_windows_office(input_path, output_path):
|
||||
with open(output_path, 'rb') as f:
|
||||
return f.read()
|
||||
errors.append("windows-office: failed to convert xls via WPS/MS Excel")
|
||||
else:
|
||||
errors.append("windows-office: disabled for preview to avoid interactive Office dialogs")
|
||||
|
||||
joined = "; ".join(errors) if errors else "no converter attempted"
|
||||
raise RuntimeError(f"failed to convert xls to xlsx: {joined}")
|
||||
|
||||
@@ -12,7 +12,6 @@ import { computed, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { marked } from 'marked';
|
||||
import * as XLSX from 'xlsx';
|
||||
import { useMessage } from '../composables/useMessage';
|
||||
import VueOfficeDocx from '@vue-office/docx';
|
||||
import VueOfficeExcel from '@vue-office/excel';
|
||||
import '@vue-office/docx/lib/index.css';
|
||||
@@ -33,6 +32,7 @@ interface ExcelPreviewData {
|
||||
}
|
||||
|
||||
type OfficeKind = 'docx' | 'excel' | null;
|
||||
type PreviewMode = 'markdown' | 'image' | 'iframe' | 'sheet' | 'office';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean;
|
||||
@@ -44,7 +44,6 @@ const props = defineProps<{
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: boolean): void;
|
||||
}>();
|
||||
const msg = useMessage();
|
||||
const { t } = useI18n();
|
||||
|
||||
const isLoading = ref(false);
|
||||
@@ -76,7 +75,7 @@ const ext = computed(() => {
|
||||
return getExt(props.file?.url || '');
|
||||
});
|
||||
|
||||
const preferredMode = computed<'markdown' | 'image' | 'iframe' | 'sheet' | 'office'>(() => {
|
||||
const preferredMode = computed<PreviewMode>(() => {
|
||||
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp'].includes(ext.value)) return 'image';
|
||||
if (['md', 'markdown', 'txt', 'csv', 'vtt', 'properties', 'html', 'htm'].includes(ext.value)) return 'markdown';
|
||||
if (['xlsx', 'xls'].includes(ext.value)) return 'sheet';
|
||||
@@ -85,7 +84,7 @@ const preferredMode = computed<'markdown' | 'image' | 'iframe' | 'sheet' | 'offi
|
||||
return 'iframe';
|
||||
});
|
||||
|
||||
const resolvedMode = ref<'markdown' | 'image' | 'iframe' | 'sheet' | 'office'>('iframe');
|
||||
const resolvedMode = ref<PreviewMode>('iframe');
|
||||
|
||||
const needsOfficeFallback = computed(() => {
|
||||
// We no longer need fallback for doc/ppt/pptx because they are converted to PDF by the backend
|
||||
@@ -111,50 +110,12 @@ const iframeSrc = computed(() => {
|
||||
});
|
||||
|
||||
const imageSrc = computed(() => officeObjectUrl.value || props.file?.url || '');
|
||||
const officePreviewExts = new Set(['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx']);
|
||||
|
||||
const close = () => emit('update:modelValue', false);
|
||||
|
||||
const isDownloading = ref(false);
|
||||
const previewTooLarge = computed(() => /file too large for online preview/i.test(error.value));
|
||||
|
||||
const downloadFile = async () => {
|
||||
if (!props.file?.url || !props.agentId) return;
|
||||
isDownloading.value = true;
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
agent_id: String(props.agentId),
|
||||
url: props.file.url,
|
||||
name: props.file.name || '',
|
||||
download: '1'
|
||||
});
|
||||
|
||||
const res = await fetch(`/api/chat/preview-file-raw?${params.toString()}`, {
|
||||
headers: props.authHeaders || {},
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({}));
|
||||
throw new Error(err?.error || `HTTP ${res.status}`);
|
||||
}
|
||||
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = props.file.name || 'download';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (err: any) {
|
||||
console.error('Download failed:', err);
|
||||
msg.error(t('filePreview.msg.downloadFailed', { reason: err.message || t('filePreview.msg.unknownError') }));
|
||||
} finally {
|
||||
isDownloading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const clearOfficeObjectUrl = () => {
|
||||
if (officeObjectUrl.value) {
|
||||
URL.revokeObjectURL(officeObjectUrl.value);
|
||||
@@ -252,7 +213,7 @@ const loadOfficeContent = async () => {
|
||||
};
|
||||
|
||||
const loadPdfContent = async (): Promise<'iframe' | 'office' | 'sheet'> => {
|
||||
if (!props.file?.url) return;
|
||||
if (!props.file?.url) return 'iframe';
|
||||
if (!props.agentId) throw new Error('agent_id is required for pdf preview');
|
||||
|
||||
if (ext.value === 'doc') {
|
||||
@@ -282,9 +243,13 @@ const loadPdfContent = async (): Promise<'iframe' | 'office' | 'sheet'> => {
|
||||
const buffer = await blob.arrayBuffer();
|
||||
const actualExt = (res.headers.get('X-Preview-Actual-Ext') || '').toLowerCase();
|
||||
const blobType = (blob.type || '').toLowerCase();
|
||||
const effectiveExt = actualExt || ext.value;
|
||||
const isDocxPayload = actualExt === 'docx' || blobType.includes('wordprocessingml.document');
|
||||
const isExcelPayload = ['xlsx', 'xls'].includes(actualExt) || blobType.includes('spreadsheetml.sheet') || blobType.includes('application/vnd.ms-excel');
|
||||
if (isExcelPayload) {
|
||||
if (tryApplyExcelPreview(buffer)) {
|
||||
return 'sheet';
|
||||
}
|
||||
await loadSheetPreview();
|
||||
return 'sheet';
|
||||
}
|
||||
@@ -297,6 +262,9 @@ const loadPdfContent = async (): Promise<'iframe' | 'office' | 'sheet'> => {
|
||||
officeKind.value = 'docx';
|
||||
return 'office';
|
||||
}
|
||||
if (!blobType.includes('pdf') && officePreviewExts.has(effectiveExt)) {
|
||||
throw new Error('当前原始文件暂不支持直接预览,已阻止浏览器自动下载');
|
||||
}
|
||||
let fallbackType = 'application/octet-stream';
|
||||
if (ext.value === 'pdf' || ['doc', 'ppt', 'pptx'].includes(ext.value)) fallbackType = 'application/pdf';
|
||||
else if (ext.value === 'docx') fallbackType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script setup lang="ts">
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* WorkspaceView.vue
|
||||
* 文件用途:用户工作台,支持自定义布局、收藏、嵌入 Agent
|
||||
|
||||
Reference in new issue
Block a user