|
| 1 | +import JSZip from 'jszip'; |
| 2 | +import uid from './uid'; |
| 3 | + |
1 | 4 | /**
|
2 | 5 | * String.prototype.indexOf, but it returns NaN not -1 on failure
|
3 | 6 | * @param {string} str The string to check in
|
@@ -143,9 +146,27 @@ const parseStack = (stack, url, line, column) => {
|
143 | 146 | return _parseChromeStack(stack);
|
144 | 147 | };
|
145 | 148 | const downloadLogs = async () => {
|
146 |
| - const str = JSON.stringify(consoleLogs); |
147 |
| - let blob = new Blob([str]); |
148 |
| - let filename = 'pm-error-download.json'; |
| 149 | + const files = new JSZip(); |
| 150 | + files.file('logs.json', JSON.stringify(consoleLogs)); |
| 151 | + const index = {}; |
| 152 | + // get files |
| 153 | + // sadly, this may just dead ass fail to get files due to blob lifecycle |
| 154 | + // and i dont want to make these files get stored at runtime, cause poopy doo doo ram |
| 155 | + for (const log of consoleLogs) { |
| 156 | + for (const trace of log.trace) { |
| 157 | + if (index[trace.url]) continue; |
| 158 | + const id = uid(); |
| 159 | + const content = await fetch(trace.url) |
| 160 | + .then(res => res.ok ? res.text() : null) |
| 161 | + .catch(() => {}); |
| 162 | + if (!content) continue; |
| 163 | + files.file(id, content); |
| 164 | + index[trace.url] = id; |
| 165 | + } |
| 166 | + } |
| 167 | + files.file('index.json', JSON.stringify(index)); |
| 168 | + let blob = await files.generateAsync({ type: 'blob', compression: 'DEFLATE' }); |
| 169 | + let filename = 'pm-error-download.pml'; |
149 | 170 | /* actually, this is a bad idea
|
150 | 171 | // if we can, include the project
|
151 | 172 | if (vm) {
|
|
0 commit comments