works
This commit is contained in:
@ -3,13 +3,9 @@
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('Torrents', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
hashString: {
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
magnetLink: {
|
||||
|
@ -53,12 +53,47 @@ module.exports = (sequelize, DataTypes, Model) => {
|
||||
}
|
||||
}
|
||||
|
||||
static async migrate(hashString, username){
|
||||
try{
|
||||
let exists = await this.findByPk(hashString);
|
||||
|
||||
if(exists){
|
||||
console.log('torrent in DB, skipping')
|
||||
return {}
|
||||
}
|
||||
|
||||
let res = ( await tr_client.get(hashString, [
|
||||
"eta", "percentDone", "status", "rateDownload",
|
||||
"errorString", "hashString", 'name',
|
||||
'downloadDir',
|
||||
'addedDate',
|
||||
'magnetLink',
|
||||
'files', //array of files
|
||||
'filesStats', // array of files with status
|
||||
'isFinished',
|
||||
'isStalled',
|
||||
'peers',
|
||||
'peersConnected', // array of peers,
|
||||
'sizeWhenDone',
|
||||
]) ).torrents[0];
|
||||
|
||||
// console.log('date:', res.addedDate, new Date(res.addedDate*1000), 'res:', res)
|
||||
|
||||
let instance = await this.build({createdAt: new Date(res.addedDate*1000), ...res, added_by: username});
|
||||
await instance.save();
|
||||
return {...res, ...instance.dataValues};
|
||||
}catch(error){
|
||||
console.error('migrate error', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getTorrentData(noUpdate){
|
||||
try{
|
||||
let res = ( await tr_client.get(this.hashString, [
|
||||
"eta", "percentDone", "status", "rateDownload",
|
||||
"errorString", "hashString", 'name',
|
||||
'downloadDir',
|
||||
'dateCreated',
|
||||
'files', //array of files
|
||||
'filesStats', // array of files with status
|
||||
'isFinished',
|
||||
@ -100,6 +135,11 @@ module.exports = (sequelize, DataTypes, Model) => {
|
||||
}
|
||||
}
|
||||
Torrent.init({
|
||||
hashString: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
magnetLink: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
@ -112,7 +152,6 @@ module.exports = (sequelize, DataTypes, Model) => {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
hashString: DataTypes.STRING,
|
||||
name: DataTypes.STRING,
|
||||
added_by: {
|
||||
type: DataTypes.STRING,
|
||||
@ -137,6 +176,9 @@ module.exports = (sequelize, DataTypes, Model) => {
|
||||
type: DataTypes.NUMBER,
|
||||
allowNull: true,
|
||||
},
|
||||
createdAt: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'Torrent',
|
||||
|
Reference in New Issue
Block a user