Validate torrent after hashString is resolved
The static Torrent.create override was validating the input data before calling Transmission, but hashString isn't known until after addUrl. Move validation to the final createData object so search/fill can queue torrents without providing a hash up front. Signed-off-by: William Mantly <wmantly@gmail.com>
This commit is contained in:
@@ -61,11 +61,6 @@ module.exports = (sequelize, DataTypes, Model) => {
|
|||||||
|
|
||||||
static async create(data, ...args){
|
static async create(data, ...args){
|
||||||
try{
|
try{
|
||||||
|
|
||||||
// let instance = this.build(data);
|
|
||||||
// console.log('instance', instance)
|
|
||||||
await this.build(data).validate();
|
|
||||||
// console.log('validate', val);
|
|
||||||
data.isPrivate = data.isPrivate === 'true' ? true : false;
|
data.isPrivate = data.isPrivate === 'true' ? true : false;
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
@@ -89,7 +84,7 @@ module.exports = (sequelize, DataTypes, Model) => {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await super.create({
|
let createData = {
|
||||||
magnetLink: data.magnetLink,
|
magnetLink: data.magnetLink,
|
||||||
hashString,
|
hashString,
|
||||||
isPrivate: data.isPrivate,
|
isPrivate: data.isPrivate,
|
||||||
@@ -98,7 +93,12 @@ module.exports = (sequelize, DataTypes, Model) => {
|
|||||||
category: this.categoryFromTPB(data.category),
|
category: this.categoryFromTPB(data.category),
|
||||||
status: 0,
|
status: 0,
|
||||||
percentDone: 0,
|
percentDone: 0,
|
||||||
}, args);
|
};
|
||||||
|
|
||||||
|
// Validate only after hashString is populated.
|
||||||
|
await this.build(createData).validate();
|
||||||
|
|
||||||
|
return await super.create(createData, args);
|
||||||
}catch (error){
|
}catch (error){
|
||||||
console.log('Torrent create error', error);
|
console.log('Torrent create error', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Reference in New Issue
Block a user