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:
+17
-2
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user