mirror of
https://github.com/tiennm99/miti99.git
synced 2026-08-03 22:24:18 +00:00
fix(mt-add-post): preserve YouTube video id in duplicate check
bareUrl() dropped the query string, collapsing every youtube.com/watch URL to the same bare key and flagging all YouTube links as duplicates. Keep host identity params (v for youtube) so distinct videos are not treated as duplicates.
This commit is contained in:
@@ -38,11 +38,26 @@ function cleanUrl(rawUrl) {
|
||||
}
|
||||
}
|
||||
|
||||
// Extract the bare URL (scheme + host + path) — used for stricter duplicate checks
|
||||
// Some sites carry the resource identity in a query param, not the path
|
||||
// (e.g. YouTube /watch?v=ID). Stripping the query for these collapses every
|
||||
// item to the same bare URL, causing false-positive duplicates. Preserve the
|
||||
// identity param for those hosts.
|
||||
const IDENTITY_PARAMS = {
|
||||
"youtube.com": "v",
|
||||
"www.youtube.com": "v",
|
||||
"m.youtube.com": "v",
|
||||
};
|
||||
|
||||
// Extract the bare URL (scheme + host + path) — used for stricter duplicate checks.
|
||||
// Keeps the host's identity query param when one is defined above.
|
||||
function bareUrl(targetUrl) {
|
||||
try {
|
||||
const p = new URL(targetUrl);
|
||||
return `${p.protocol}//${p.host}${p.pathname}`.replace(/\/$/, "");
|
||||
let bare = `${p.protocol}//${p.host}${p.pathname}`.replace(/\/$/, "");
|
||||
const idParam = IDENTITY_PARAMS[p.host.toLowerCase()];
|
||||
const idValue = idParam ? p.searchParams.get(idParam) : null;
|
||||
if (idValue) bare += `?${idParam}=${idValue}`;
|
||||
return bare;
|
||||
} catch {
|
||||
return targetUrl.split("?")[0].replace(/\/$/, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user