|
44 | 44 | async function loadIndex(remote, local, isCloud=false){ |
45 | 45 | let rawLoaded = false; |
46 | 46 | if(remote){ |
47 | | - /* Try compressed version first */ |
| 47 | + /* Try ONLY compressed version from GitHub (remote already includes .js.gz) */ |
48 | 48 | try { |
49 | | - const gzUrl = remote + '.gz'; |
50 | | - const r = await fetch(gzUrl,{mode:'cors'}); |
| 49 | + const r = await fetch(remote,{mode:'cors'}); |
51 | 50 | if (r.ok) { |
52 | 51 | const compressed = await r.arrayBuffer(); |
53 | 52 | const text = await decompressGzip(compressed); |
54 | 53 | importScripts(URL.createObjectURL(new Blob([text],{type:'application/javascript'}))); |
55 | 54 | rawLoaded = true; |
56 | | - console.log('Loaded compressed',gzUrl); |
| 55 | + console.log('Loaded compressed from GitHub:',remote); |
57 | 56 | } |
58 | | - } catch(e){ console.warn('compressed',remote+'.gz','failed →',e); } |
59 | | - |
60 | | - /* Fall back to uncompressed if compressed failed */ |
61 | | - if(!rawLoaded){ |
62 | | - try { |
63 | | - const r = await fetch(remote,{mode:'cors'}); |
64 | | - if (!r.ok) throw new Error('HTTP '+r.status); |
65 | | - importScripts(URL.createObjectURL(new Blob([await r.text()],{type:'application/javascript'}))); |
66 | | - rawLoaded = true; |
67 | | - console.log('Loaded uncompressed',remote); |
68 | | - } catch(e){ console.warn('remote',remote,'failed →',e); } |
69 | | - } |
| 57 | + } catch(e){ console.warn('compressed GitHub',remote,'failed →',e); } |
70 | 58 | } |
| 59 | + /* If remote (GitHub) failed, fall back to local uncompressed file */ |
71 | 60 | if(!rawLoaded && local){ |
72 | | - try { importScripts(abs(local)); rawLoaded = true; } |
| 61 | + try { |
| 62 | + importScripts(abs(local)); |
| 63 | + rawLoaded = true; |
| 64 | + console.log('Loaded local fallback:',local); |
| 65 | + } |
73 | 66 | catch(e){ console.error('local',local,'failed →',e); } |
74 | 67 | } |
75 | 68 | if(!rawLoaded) return null; /* give up on this index */ |
|
106 | 99 | const lang = data.lang || 'en'; |
107 | 100 | const searchindexBase = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-searchindex/main'; |
108 | 101 |
|
109 | | - const mainFilenames = Array.from(new Set(['searchindex-' + lang + '.js', 'searchindex-en.js'])); |
110 | | - const cloudFilenames = Array.from(new Set(['searchindex-cloud-' + lang + '.js', 'searchindex-cloud-en.js'])); |
| 102 | + /* Remote sources are .js.gz (compressed), local fallback is .js (uncompressed) */ |
| 103 | + const mainFilenames = Array.from(new Set(['searchindex-' + lang + '.js.gz', 'searchindex-en.js.gz'])); |
| 104 | + const cloudFilenames = Array.from(new Set(['searchindex-cloud-' + lang + '.js.gz', 'searchindex-cloud-en.js.gz'])); |
111 | 105 |
|
112 | 106 | const MAIN_REMOTE_SOURCES = mainFilenames.map(function(filename) { return searchindexBase + '/' + filename; }); |
113 | 107 | const CLOUD_REMOTE_SOURCES = cloudFilenames.map(function(filename) { return searchindexBase + '/' + filename; }); |
|
0 commit comments