This commit is contained in:
carlospolop
2025-10-04 01:46:26 +02:00
parent ab41eee8e8
commit 58f5fb17af
3 changed files with 22 additions and 29 deletions

View File

@@ -88,9 +88,8 @@ jobs:
RATIO=$(awk "BEGIN {printf \"%.1f\", ($COMPRESSED_SIZE / $ORIGINAL_SIZE) * 100}")
echo "Compression: ${ORIGINAL_SIZE} bytes -> ${COMPRESSED_SIZE} bytes (${RATIO}%)"
# Copy both versions to the searchindex repo
# Copy ONLY the .gz version to the searchindex repo (no uncompressed .js)
cd /tmp/searchindex-repo
cp "${GITHUB_WORKSPACE}/${ASSET}" "${FILENAME}"
cp "${GITHUB_WORKSPACE}/${ASSET}.gz" "${FILENAME}.gz"
# Stage all files

View File

@@ -175,10 +175,8 @@ jobs:
# Clone the searchindex repo
git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git /tmp/searchindex-repo
# Copy and compress the searchindex file
cp "$ASSET" "/tmp/searchindex-repo/${FILENAME}"
# Compress the searchindex file
gzip -9 -k -f "$ASSET"
cp "${ASSET}.gz" "/tmp/searchindex-repo/${FILENAME}.gz"
# Show compression stats
ORIGINAL_SIZE=$(wc -c < "$ASSET")
@@ -186,11 +184,14 @@ jobs:
RATIO=$(awk "BEGIN {printf \"%.1f\", ($COMPRESSED_SIZE / $ORIGINAL_SIZE) * 100}")
echo "Compression: ${ORIGINAL_SIZE} bytes -> ${COMPRESSED_SIZE} bytes (${RATIO}%)"
# Copy ONLY the .gz version to the searchindex repo (no uncompressed .js)
cp "${ASSET}.gz" "/tmp/searchindex-repo/${FILENAME}.gz"
# Commit and push with retry logic
cd /tmp/searchindex-repo
git config user.name "GitHub Actions"
git config user.email "github-actions@github.com"
git add "${FILENAME}" "${FILENAME}.gz"
git add "${FILENAME}.gz"
if git diff --staged --quiet; then
echo "No changes to commit"
@@ -223,12 +224,11 @@ jobs:
git config user.name "GitHub Actions"
git config user.email "github-actions@github.com"
# Re-copy and compress the searchindex file
cp "$ASSET" "${FILENAME}"
# Re-copy ONLY the .gz version (no uncompressed .js)
cp "${ASSET}.gz" "${FILENAME}.gz"
git add "${FILENAME}" "${FILENAME}.gz"
git commit -m "Update ${FILENAME} from hacktricks-cloud build"
git add "${FILENAME}.gz"
git commit -m "Update ${FILENAME}.gz from hacktricks-cloud build"
echo "Re-cloned and re-committed, will retry push..."
else
echo "Rebase failed for unknown reason, retrying anyway..."

View File

@@ -44,32 +44,25 @@
async function loadIndex(remote, local, isCloud=false){
let rawLoaded = false;
if(remote){
/* Try compressed version first */
/* Try ONLY compressed version from GitHub (remote already includes .js.gz) */
try {
const gzUrl = remote + '.gz';
const r = await fetch(gzUrl,{mode:'cors'});
const r = await fetch(remote,{mode:'cors'});
if (r.ok) {
const compressed = await r.arrayBuffer();
const text = await decompressGzip(compressed);
importScripts(URL.createObjectURL(new Blob([text],{type:'application/javascript'})));
rawLoaded = true;
console.log('Loaded compressed',gzUrl);
console.log('Loaded compressed from GitHub:',remote);
}
} catch(e){ console.warn('compressed',remote+'.gz','failed →',e); }
/* Fall back to uncompressed if compressed failed */
if(!rawLoaded){
try {
const r = await fetch(remote,{mode:'cors'});
if (!r.ok) throw new Error('HTTP '+r.status);
importScripts(URL.createObjectURL(new Blob([await r.text()],{type:'application/javascript'})));
rawLoaded = true;
console.log('Loaded uncompressed',remote);
} catch(e){ console.warn('remote',remote,'failed →',e); }
}
} catch(e){ console.warn('compressed GitHub',remote,'failed →',e); }
}
/* If remote (GitHub) failed, fall back to local uncompressed file */
if(!rawLoaded && local){
try { importScripts(abs(local)); rawLoaded = true; }
try {
importScripts(abs(local));
rawLoaded = true;
console.log('Loaded local fallback:',local);
}
catch(e){ console.error('local',local,'failed →',e); }
}
if(!rawLoaded) return null; /* give up on this index */
@@ -106,8 +99,9 @@
const lang = data.lang || 'en';
const searchindexBase = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-searchindex/main';
const mainFilenames = Array.from(new Set(['searchindex-' + lang + '.js', 'searchindex-en.js']));
const cloudFilenames = Array.from(new Set(['searchindex-cloud-' + lang + '.js', 'searchindex-cloud-en.js']));
/* Remote sources are .js.gz (compressed), local fallback is .js (uncompressed) */
const mainFilenames = Array.from(new Set(['searchindex-' + lang + '.js.gz', 'searchindex-en.js.gz']));
const cloudFilenames = Array.from(new Set(['searchindex-cloud-' + lang + '.js.gz', 'searchindex-cloud-en.js.gz']));
const MAIN_REMOTE_SOURCES = mainFilenames.map(function(filename) { return searchindexBase + '/' + filename; });
const CLOUD_REMOTE_SOURCES = cloudFilenames.map(function(filename) { return searchindexBase + '/' + filename; });