From a66982a00db59e460a1e063606521855aab77266 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Mon, 20 Jul 2026 14:57:19 -0400 Subject: [PATCH] Fallback to magnet info-hash when Transmission omits hashString Transmission addUrl sometimes returns a response without a hashString (e.g. duplicate or malformed response). Extract the info hash from the magnet link as a fallback, and log the response if neither works. Signed-off-by: William Mantly --- models/sql/torrent.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/models/sql/torrent.js b/models/sql/torrent.js index a2e49c9..3df71ae 100644 --- a/models/sql/torrent.js +++ b/models/sql/torrent.js @@ -74,11 +74,26 @@ module.exports = (sequelize, DataTypes, Model) => { let res = await trClient.addUrl(data.magnetLink, options); + // Transmission usually returns hashString, but if it doesn't (duplicate, malformed + // response, etc.), fall back to parsing the info hash from the magnet link. + let hashString = res && (res.hashString || res.id); + if(!hashString){ + let match = data.magnetLink.match(/urn:btih:([A-Fa-f0-9]{40})/i); + if(match) hashString = match[1].toLowerCase(); + } + + if(!hashString){ + console.error('Transmission addUrl response missing hashString:', res); + let error = new Error('TorrentCreateError'); + error.message = 'Transmission did not return a hash for this torrent'; + throw error; + } + return await super.create({ magnetLink: data.magnetLink, - hashString: res.hashString, + hashString, isPrivate: data.isPrivate, - name: res.name, + name: res && res.name, added_by: data.added_by, category: this.categoryFromTPB(data.category), status: 0,