Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Resolved conflicts by taking GitHub versions for: - .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml Kept deploy.sh updated to: - Pull from GitHub (primary source) - Push to Gitea (push-mirror) - Build from site/ directory (GitHub structure) Co-Authored-By: Paperclip <noreply@paperclip.ing>
70 lines
2.7 KiB
JavaScript
70 lines
2.7 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
0 && (module.exports = {
|
|
computeCacheBustingSearchParam: null,
|
|
computeLegacyCacheBustingSearchParam: null
|
|
});
|
|
function _export(target, all) {
|
|
for(var name in all)Object.defineProperty(target, name, {
|
|
enumerable: true,
|
|
get: all[name]
|
|
});
|
|
}
|
|
_export(exports, {
|
|
computeCacheBustingSearchParam: function() {
|
|
return computeCacheBustingSearchParam;
|
|
},
|
|
computeLegacyCacheBustingSearchParam: function() {
|
|
return computeLegacyCacheBustingSearchParam;
|
|
}
|
|
});
|
|
const _hash = require("../../hash");
|
|
const CACHE_BUSTING_SEARCH_PARAM_DIGEST_BYTES = 12;
|
|
const textEncoder = new TextEncoder();
|
|
function encodeCacheBustingSearchParam(bytes) {
|
|
let binary = '';
|
|
for(let i = 0; i < bytes.length; i++){
|
|
binary += String.fromCharCode(bytes[i]);
|
|
}
|
|
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
}
|
|
function normalizeCacheBustingInput(value) {
|
|
if (value === undefined) {
|
|
return '0';
|
|
}
|
|
return Array.isArray(value) ? value.join(',') : value;
|
|
}
|
|
function createCacheBustingSearchParamInput(prefetchHeader, segmentPrefetchHeader, stateTreeHeader, nextUrlHeader) {
|
|
if ((prefetchHeader === undefined || prefetchHeader === '0') && segmentPrefetchHeader === undefined && stateTreeHeader === undefined && nextUrlHeader === undefined) {
|
|
return null;
|
|
}
|
|
return [
|
|
prefetchHeader ?? '0',
|
|
normalizeCacheBustingInput(segmentPrefetchHeader),
|
|
normalizeCacheBustingInput(stateTreeHeader),
|
|
normalizeCacheBustingInput(nextUrlHeader)
|
|
].join(',');
|
|
}
|
|
async function computeCacheBustingSearchParamFromInput(input) {
|
|
// Truncate SHA-256 to 96 bits to keep `_rsc` compact
|
|
const digest = await globalThis.crypto.subtle.digest('SHA-256', textEncoder.encode(input));
|
|
return encodeCacheBustingSearchParam(new Uint8Array(digest).subarray(0, CACHE_BUSTING_SEARCH_PARAM_DIGEST_BYTES));
|
|
}
|
|
async function computeCacheBustingSearchParam(prefetchHeader, segmentPrefetchHeader, stateTreeHeader, nextUrlHeader) {
|
|
const input = createCacheBustingSearchParamInput(prefetchHeader, segmentPrefetchHeader, stateTreeHeader, nextUrlHeader);
|
|
if (input === null) {
|
|
return '';
|
|
}
|
|
return computeCacheBustingSearchParamFromInput(input);
|
|
}
|
|
function computeLegacyCacheBustingSearchParam(prefetchHeader, segmentPrefetchHeader, stateTreeHeader, nextUrlHeader) {
|
|
const input = createCacheBustingSearchParamInput(prefetchHeader, segmentPrefetchHeader, stateTreeHeader, nextUrlHeader);
|
|
if (input === null) {
|
|
return '';
|
|
}
|
|
return (0, _hash.hexHash)(input);
|
|
}
|
|
|
|
//# sourceMappingURL=cache-busting-search-param.js.map
|