1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 19:34:34 +00:00

feat(log): added time to downloaded log name

This commit is contained in:
Yury Shkoda
2023-04-27 18:53:45 +03:00
parent 56a522c07c
commit 3848bb0add
2 changed files with 15 additions and 7 deletions

View File

@@ -113,7 +113,7 @@ const LogChunk = (props: LogChunkProps) => {
)}
<FileDownloadIcon
onClick={(evt: SyntheticEvent) => {
download(evt, rowText, `log.${getLineRange('-')}`)
download(evt, rowText, `.${getLineRange('-')}`)
}}
/>
{errors && errors.length !== 0 && (

View File

@@ -102,19 +102,27 @@ export const splitIntoChunks = (log: string, chunkSize = defaultChunkSize) => {
export const clearErrorsAndWarningsHtmlWrapping = (log: string) =>
log.replace(/^<font[^>]*>/gm, '').replace(/<\/font>/gm, '')
export const download = (
evt: SyntheticEvent,
log: string,
fileName = 'log'
) => {
export const download = (evt: SyntheticEvent, log: string, fileName = '') => {
evt.stopPropagation()
const padWithZero = (num: number) => (num < 9 ? `0${num}` : `${num}`)
const date = new Date()
const datePrefix = [
date.getFullYear(),
padWithZero(date.getMonth() + 1),
padWithZero(date.getDate()),
padWithZero(date.getHours()),
padWithZero(date.getMinutes()),
padWithZero(date.getSeconds())
].join('')
const file = new Blob([log])
const url = URL.createObjectURL(file)
const a = document.createElement('a')
a.href = url
a.download = `${fileName}.log`
a.download = `${datePrefix}${fileName}.log`
document.body.appendChild(a)
a.click()