fix: hash overly long query strings/paths to avoid ENAMETOOLONG
This commit is contained in:
@@ -8,6 +8,7 @@ const { chromium } = require('playwright');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { URL } = require('url');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const CHAT_OVERLAY = `
|
||||
<style>
|
||||
@@ -45,9 +46,20 @@ function urlToSafePath(u) {
|
||||
const parsed = new URL(u);
|
||||
let p = parsed.pathname;
|
||||
if (parsed.search) {
|
||||
const safe = parsed.search.slice(1).replace(/[^a-zA-Z0-9._-]/g, '_');
|
||||
let safe = parsed.search.slice(1).replace(/[^a-zA-Z0-9._-]/g, '_');
|
||||
// Hash overly long query strings to avoid ENAMETOOLONG
|
||||
if (safe.length > 80) {
|
||||
safe = crypto.createHash('md5').update(parsed.search).digest('hex').slice(0, 12);
|
||||
}
|
||||
p += '_q_' + safe;
|
||||
}
|
||||
// also hash if path itself is way too long
|
||||
const basename = path.basename(p);
|
||||
if (basename.length > 200) {
|
||||
const ext = path.extname(p);
|
||||
const dir = path.dirname(p);
|
||||
p = dir + '/' + crypto.createHash('md5').update(basename).digest('hex').slice(0, 16) + ext;
|
||||
}
|
||||
return p.replace(/^\/+/, '');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user