|
152 | 152 | // extract and parse interesting entries
|
153 | 153 | let harents = [];
|
154 | 154 | let skipped = [];
|
| 155 | + let commonpath = null; |
155 | 156 | for ([id,ent] of har.log.entries.entries()) {
|
156 | 157 | let harent = { id: id };
|
157 | 158 | let fullpath = new URL(ent.request.url).pathname.split('/');
|
|
165 | 166 | harent.error = "Can't decode.";
|
166 | 167 | if (harent.error) {
|
167 | 168 | console.log(`harextract: skipped ${harent.name} (${id}): ${harent.error}`);
|
168 |
| - harent.path = harent.pathcomps.join('/'); // TODO: fix me! kludge to get paths into skipped. |
169 | 169 | skipped.push(harent);
|
170 | 170 | } else {
|
171 |
| - harents.push(harent); |
| 171 | + commonpath = fullpath.slice(0, [...fullpath,null].findIndex((p, n) => p !== (commonpath||fullpath)[n])); // ;) |
| 172 | + harents.push(harent); // note: we can now guarantee that if harents has items, commonpath is set. |
172 | 173 | }
|
173 | 174 | }
|
174 | 175 |
|
175 |
| - // now make a few passes to strip common path prefixes |
176 |
| - // todo: code can be simplified by maintaining common components above then |
177 |
| - // doing a single second pass to slice + join. |
178 |
| - if (harents.length > 0) { |
179 |
| - for (var ncommon = 0, allsame = true; allsame && ncommon < harents[0].pathcomps.length; ++ ncommon) { |
180 |
| - allsame = true; |
181 |
| - let refpart = harents[0].pathcomps[ncommon]; |
182 |
| - for (ent of harents) { |
183 |
| - if (ent.pathcomps[ncommon] != refpart) { |
184 |
| - allsame = false; |
185 |
| - break; |
186 |
| - } |
187 |
| - } |
188 |
| - } |
189 |
| - for (ent of harents) { |
190 |
| - ent.path = (ncommon < 0 ? '' : ent.pathcomps.slice(ncommon - 1).join('/')); |
191 |
| - } |
192 |
| - } |
193 |
| - |
| 176 | + // set path strings for all files; for non-skipped files, also strip common path prefixes. |
| 177 | + harents.forEach(ent => ent.path = ent.pathcomps.slice(commonpath.length).join('/')); |
| 178 | + skipped.forEach(ent => ent.path = ent.pathcomps.join('/')); |
| 179 | + |
194 | 180 | let entsort = function (a,b) {
|
195 | 181 | let p = strCompare(a.path, b.path);
|
196 | 182 | return (p != 0) ? p : strCompare(a.name, b.name);
|
|
0 commit comments