mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-18 05:12:21 +01:00
174 lines
2.8 KiB
JavaScript
174 lines
2.8 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Module dependencies
|
|
*/
|
|
var mongoose = require('mongoose'),
|
|
Schema = mongoose.Schema;
|
|
|
|
/**
|
|
* Sub Comment Schema
|
|
*/
|
|
var CommentSchema = new Schema({
|
|
user: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'User'
|
|
},
|
|
comment: {
|
|
type: String,
|
|
default: '',
|
|
trim: true
|
|
},
|
|
_replies: [this],
|
|
createdat: {
|
|
type: Date,
|
|
default: Date.now
|
|
},
|
|
editedby: {
|
|
type: String,
|
|
default: '',
|
|
trim: true
|
|
},
|
|
editedat: {
|
|
type: Date,
|
|
default: ''
|
|
}
|
|
});
|
|
|
|
|
|
/**
|
|
* Torrent Schema
|
|
*/
|
|
var TorrentSchema = new Schema({
|
|
user: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'User'
|
|
},
|
|
info_hash: {
|
|
type: String,
|
|
default: '',
|
|
trim: true,
|
|
required: 'info_hash cannot be blank'
|
|
},
|
|
torrent_filename: {
|
|
type: String,
|
|
default: '',
|
|
trim: true,
|
|
required: 'filename cannot be blank'
|
|
},
|
|
torrent_type: {
|
|
type: String,
|
|
default: 'movie',
|
|
trim: true
|
|
},
|
|
torrent_tags: {
|
|
type: [String],
|
|
default: '',
|
|
trim: true
|
|
},
|
|
torrent_nfo: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
torrent_announce: {
|
|
type: String,
|
|
default: '',
|
|
trim: true
|
|
},
|
|
torrent_seasons: {
|
|
type: Number,
|
|
default: 0
|
|
},
|
|
torrent_episodes: {
|
|
type: String,
|
|
default: '0'
|
|
},
|
|
torrent_size: {
|
|
type: Number,
|
|
default: 0
|
|
},
|
|
torrent_seeds: {
|
|
type: Number,
|
|
default: 0
|
|
},
|
|
torrent_leechers: {
|
|
type: Number,
|
|
default: 0
|
|
},
|
|
torrent_finished: {
|
|
type: Number,
|
|
default: 0
|
|
},
|
|
torrent_status: {
|
|
type: String,
|
|
default: 'new',
|
|
trim: true
|
|
},
|
|
torrent_sale_status: {
|
|
type: String,
|
|
default: 'U1/D1',
|
|
trim: true
|
|
},
|
|
torrent_sale_expires: {
|
|
type: Date
|
|
},
|
|
torrent_recommended: {
|
|
type: String,
|
|
default: 'none'
|
|
},
|
|
_subtitles: [{
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'Subtitle'
|
|
}],
|
|
_peers: [{
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'Peer'
|
|
}],
|
|
_replies: [CommentSchema],
|
|
last_scrape: {
|
|
type: Date,
|
|
default: Date.now
|
|
},
|
|
_other_torrents: [],
|
|
|
|
//resource info
|
|
resource_detail_info: Object,
|
|
|
|
createdat: {
|
|
type: Date,
|
|
default: Date.now
|
|
},
|
|
orderedat: {
|
|
type: Date,
|
|
default: Date.now
|
|
}
|
|
});
|
|
|
|
/**
|
|
* overwrite toJSON
|
|
*/
|
|
TorrentSchema.methods.toJSON = function (options) {
|
|
var document = this.toObject(options);
|
|
document.isSaling = false;
|
|
|
|
if (this.torrent_sale_expires > Date.now()) {
|
|
document.isSaling = true;
|
|
}
|
|
|
|
if (!document.isSaling) {
|
|
document.torrent_sale_status = 'U1/D1';
|
|
}
|
|
if (document.torrent_sale_status === 'U1/D1') {
|
|
document.isSaling = false;
|
|
}
|
|
|
|
return document;
|
|
};
|
|
|
|
TorrentSchema.index({user: -1, createdat: -1});
|
|
TorrentSchema.index({info_hash: -1, createdat: -1});
|
|
TorrentSchema.index({torrent_tmdb_id: -1, createdat: -1});
|
|
|
|
mongoose.model('Torrent', TorrentSchema);
|
|
mongoose.model('Comment', CommentSchema);
|