1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-11 00:10:06 +00:00

feat(log): added download chunk and entire log

This commit is contained in:
Yury Shkoda
2023-04-21 17:21:09 +03:00
parent 57b7f954a1
commit a38a9f9c3d
3 changed files with 126 additions and 54 deletions

View File

@@ -1,3 +1,4 @@
import { SyntheticEvent } from 'react'
import { LogInstance } from './'
export const parseErrorsAndWarnings = (log: string) => {
@@ -100,3 +101,25 @@ 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'
) => {
evt.stopPropagation()
const file = new Blob([log])
const url = URL.createObjectURL(file)
const a = document.createElement('a')
a.href = url
a.download = `${fileName}.log`
document.body.appendChild(a)
a.click()
setTimeout(() => {
document.body.removeChild(a)
window.URL.revokeObjectURL(url)
}, 0)
}