название файла R!A1

This commit is contained in:
2025-07-24 05:01:44 +03:00
parent 9d07b3bab7
commit ab96a271f0
2 changed files with 26 additions and 9 deletions

View File

@@ -212,16 +212,33 @@ const ProtocolForm: FC<ProtocolFormProps> = ({ template, onSave, onBack }) => {
const a = document.createElement('a') const a = document.createElement('a')
a.href = url a.href = url
// Получаем имя файла из заголовка Content-Disposition или создаем по умолчанию // Получаем значение из ячейки R!A1 для имени файла
const contentDisposition = resp.headers.get('content-disposition') const filenameFromCell = engineRef.current.getCellValue('R', 0, 0) // R!A1
let filename = `protocol_${template.name}_${new Date().toISOString().split('T')[0]}.xlsx` console.log(filenameFromCell)
let filename = 'Измените R!A1.xlsx'
if (
filenameFromCell &&
typeof filenameFromCell === 'string' &&
filenameFromCell.trim()
) {
// Очищаем имя файла от недопустимых символов
const cleanName = filenameFromCell.trim().replace(/[<>:"/\\|?*]/g, '_')
filename = `${cleanName}.xlsx`
}
// Если сервер передал имя файла в заголовке Content-Disposition, игнорируем его
// и используем строго значение из R!A1
const contentDisposition = resp.headers.get('content-disposition')
if (contentDisposition) { if (contentDisposition) {
const matches = contentDisposition.match( // Оставляем возможность переопределения только если R!A1 пуста
/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/ if (!filenameFromCell || !filenameFromCell.toString().trim()) {
) const matches = contentDisposition.match(
if (matches && matches[1]) { /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
filename = matches[1].replace(/['"]/g, '') )
if (matches && matches[1]) {
filename = matches[1].replace(/['"]/g, '')
}
} }
} }

View File

@@ -143,7 +143,7 @@ const TemplateCard: React.FC<TemplateCardProps> = ({
}} }}
> >
<FileText className="mr-2 h-4 w-4" /> <FileText className="mr-2 h-4 w-4" />
{isConfigured ? 'Создать протокол' : 'Требует настройки'} {isConfigured ? 'Создать' : 'Требует настройки'}
</Button> </Button>
<Button <Button
size="sm" size="sm"