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 <wmantly@gmail.com>
This commit is contained in:
2026-07-20 14:57:19 -04:00
parent 51e6817393
commit a66982a00d
+17 -2
View File
@@ -74,11 +74,26 @@ module.exports = (sequelize, DataTypes, Model) => {
let res = await trClient.addUrl(data.magnetLink, options); 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({ return await super.create({
magnetLink: data.magnetLink, magnetLink: data.magnetLink,
hashString: res.hashString, hashString,
isPrivate: data.isPrivate, isPrivate: data.isPrivate,
name: res.name, name: res && res.name,
added_by: data.added_by, added_by: data.added_by,
category: this.categoryFromTPB(data.category), category: this.categoryFromTPB(data.category),
status: 0, status: 0,