MCPcopy Index your code
hub / github.com/itwanger/toBeBetterJavaer / objectKeyForUrl

Function objectKeyForUrl

scripts/convert-mdnice-images-to-cdn.js:282–289  ·  view source on GitHub ↗
(url, prefix)

Source from the content-addressed store, hash-verified

280}
281
282function objectKeyForUrl(url, prefix) {
283 const parsed = new URL(url);
284 const basename = sanitizeFileName(path.basename(parsed.pathname));
285 const extension = path.extname(basename).toLowerCase();
286 const hash = crypto.createHash("sha1").update(url).digest("hex").slice(0, 12);
287 const fileName = basename && basename.length <= 120 ? `${hash}-${basename}` : `${hash}${extension || ".img"}`;
288 return `${trimSlashes(prefix)}/${fileName}`;
289}
290
291function sanitizeFileName(fileName) {
292 const decoded = safeDecodeURIComponent(fileName);

Callers 2

plannedCdnUrlFunction · 0.85
uploadAllFunction · 0.85

Calls 2

sanitizeFileNameFunction · 0.85
trimSlashesFunction · 0.85

Tested by

no test coverage detected