-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move blob & numChunks to LogExportManager; Move downloadDecompressedL…
…ogs to utils folder
- Loading branch information
Showing
4 changed files
with
81 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import downloadDecompressedLogs from "../utils/downloadDecompressedLogs"; | ||
|
||
|
||
class LogExportManager { | ||
private blob: Blob; | ||
|
||
private numChunks: number; | ||
|
||
constructor (numChunks?: number) { | ||
this.blob = new Blob(); | ||
this.numChunks = numChunks ?? 0; | ||
} | ||
|
||
getBlob (): Blob { | ||
return this.blob; | ||
} | ||
|
||
appendChunkData (chunkData: string) { | ||
this.blob = new Blob([this.blob, | ||
chunkData], {type: "text/plain"}); | ||
} | ||
|
||
getNumChunks (): number { | ||
return this.numChunks; | ||
} | ||
|
||
setNumChunks (numChunks: number) { | ||
this.numChunks = numChunks; | ||
} | ||
|
||
download (fileName: string) { | ||
// FIXME: eslint complains about this format | ||
downloadDecompressedLogs({blob: this.blob, fileName}); | ||
} | ||
|
||
reset (numChunks?: number) { | ||
this.blob = new Blob(); | ||
this.numChunks = numChunks ?? 0; | ||
} | ||
} | ||
|
||
export default LogExportManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
interface downloadDecompressedLogsProps { | ||
blob: Blob, | ||
fileName: string, | ||
} | ||
|
||
/** | ||
* | ||
* @param blob.blob | ||
* @param blob | ||
* @param fileName | ||
Check warning on line 10 in new-log-viewer/src/utils/downloadDecompressedLogs.ts GitHub Actions / lint-check
|
||
* @param blob.fileName | ||
*/ | ||
const downloadDecompressedLogs = ({blob, fileName}: downloadDecompressedLogsProps) => { | ||
const url = URL.createObjectURL(blob); | ||
const link = document.createElement("a"); | ||
link.href = url; | ||
link.download = `${fileName}-exported-${new Date().toISOString() | ||
.replace(/[:.]/g, "-")}.log`; | ||
link.click(); | ||
URL.revokeObjectURL(url); | ||
}; | ||
|
||
export default downloadDecompressedLogs; |