refactor: add JSDoc examples and log helper tracing in titleMatches (#73)
Build and Push Docker Image / build (push) Successful in 1m42s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 2m8s
CI / Security audit (push) Successful in 2m34s
CI / Swagger Validation & Coverage (push) Successful in 2m47s
CI / Tests & coverage (push) Failing after 2m51s
Build and Push Docker Image / build (push) Successful in 1m42s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 2m8s
CI / Security audit (push) Successful in 2m34s
CI / Swagger Validation & Coverage (push) Successful in 2m47s
CI / Tests & coverage (push) Failing after 2m51s
This commit is contained in:
@@ -35,7 +35,7 @@ function normalizeTitle(str) {
|
||||
* and normalized (dots/dashes/underscores to spaces) forms bidirectionally.
|
||||
* Only logs on title fallback matches (when isFallback=true) to keep logs clean.
|
||||
*/
|
||||
function titleMatches(clientName, arrTitle, { isFallback = true } = {}) {
|
||||
function titleMatches(clientName, arrTitle, { isFallback = true, caller = 'DownloadMatcher' } = {}) {
|
||||
if (!clientName || !arrTitle) return false;
|
||||
const a = clientName.toLowerCase();
|
||||
const b = arrTitle.toLowerCase();
|
||||
@@ -48,7 +48,7 @@ function titleMatches(clientName, arrTitle, { isFallback = true } = {}) {
|
||||
a.includes(bNorm) || bNorm.includes(a);
|
||||
|
||||
if (matched && isFallback) {
|
||||
logger.debug(`[DownloadMatcher] Title fallback match after normalization: "${clientName}" <-> "${arrTitle}"`);
|
||||
logger.debug(`[DownloadMatcher] Title fallback match in ${caller} after normalization: "${clientName}" <-> "${arrTitle}"`);
|
||||
}
|
||||
return matched;
|
||||
}
|
||||
@@ -56,6 +56,9 @@ function titleMatches(clientName, arrTitle, { isFallback = true } = {}) {
|
||||
/**
|
||||
* All callers (matchers + orphan path) must supply client, instanceId, and instanceName via options.
|
||||
* Defaults exist only as a last-resort safety net.
|
||||
*
|
||||
* @example
|
||||
* buildArrDownload(sonarrMatch, context, { client: 'sabnzbd', instanceId: 'sabnzbd-default', instanceName: 'SABnzbd' })
|
||||
*/
|
||||
function buildArrDownload(record, context, options = {}) {
|
||||
const {
|
||||
@@ -251,13 +254,13 @@ async function matchSabSlots(slots, context) {
|
||||
if (!sonarrMatch) {
|
||||
sonarrMatch = sonarrQueueRecords.find(r => {
|
||||
const rTitle = r.title || r.sourceTitle;
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true });
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true, caller: 'matchSabSlots' });
|
||||
});
|
||||
}
|
||||
if (!radarrMatch) {
|
||||
radarrMatch = radarrQueueRecords.find(r => {
|
||||
const rTitle = r.title || r.sourceTitle;
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true });
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true, caller: 'matchSabSlots' });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -265,13 +268,13 @@ async function matchSabSlots(slots, context) {
|
||||
if (!sonarrMatch) {
|
||||
sonarrMatch = sonarrHistoryRecords.find(r => {
|
||||
const rTitle = r.title || r.sourceTitle;
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true });
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true, caller: 'matchSabSlots' });
|
||||
});
|
||||
}
|
||||
if (!radarrMatch) {
|
||||
radarrMatch = radarrHistoryRecords.find(r => {
|
||||
const rTitle = r.title || r.sourceTitle;
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true });
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true, caller: 'matchSabSlots' });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -362,13 +365,13 @@ async function matchSabHistory(slots, context) {
|
||||
if (!sonarrMatch) {
|
||||
sonarrMatch = sonarrHistoryRecords.find(r => {
|
||||
const rTitle = r.title || r.sourceTitle;
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true });
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true, caller: 'matchSabHistory' });
|
||||
});
|
||||
}
|
||||
if (!radarrMatch) {
|
||||
radarrMatch = radarrHistoryRecords.find(r => {
|
||||
const rTitle = r.title || r.sourceTitle;
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true });
|
||||
return rTitle && titleMatches(nzbName, rTitle, { isFallback: true, caller: 'matchSabHistory' });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -441,13 +444,13 @@ async function matchTorrents(torrents, context) {
|
||||
if (!sonarrMatch) {
|
||||
sonarrMatch = sonarrQueueRecords.find(r => {
|
||||
const rTitle = r.title || r.sourceTitle;
|
||||
return rTitle && titleMatches(torrentName, rTitle, { isFallback: true });
|
||||
return rTitle && titleMatches(torrentName, rTitle, { isFallback: true, caller: 'matchTorrents' });
|
||||
});
|
||||
}
|
||||
if (!radarrMatch) {
|
||||
radarrMatch = radarrQueueRecords.find(r => {
|
||||
const rTitle = r.title || r.sourceTitle;
|
||||
return rTitle && titleMatches(torrentName, rTitle, { isFallback: true });
|
||||
return rTitle && titleMatches(torrentName, rTitle, { isFallback: true, caller: 'matchTorrents' });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -458,13 +461,13 @@ async function matchTorrents(torrents, context) {
|
||||
if (!sonarrHistoryMatch) {
|
||||
sonarrHistoryMatch = sonarrHistoryRecords.find(r => {
|
||||
const rTitle = r.title || r.sourceTitle;
|
||||
return rTitle && titleMatches(torrentName, rTitle, { isFallback: true });
|
||||
return rTitle && titleMatches(torrentName, rTitle, { isFallback: true, caller: 'matchTorrents' });
|
||||
});
|
||||
}
|
||||
if (!radarrHistoryMatch) {
|
||||
radarrHistoryMatch = radarrHistoryRecords.find(r => {
|
||||
const rTitle = r.title || r.sourceTitle;
|
||||
return rTitle && titleMatches(torrentName, rTitle, { isFallback: true });
|
||||
return rTitle && titleMatches(torrentName, rTitle, { isFallback: true, caller: 'matchTorrents' });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user