| var localBase = require('./localBase'); |
| var chpurl = require('libs/chpurl'); |
| var secToMin = require('libs/secToMin'); |
| /** |
| * |
| * @param property |
| * @returns {*} |
| * @constructor |
| * @description Хранит в себе информацию о видеофайлах. |
| */ |
| var Video = function (property) { |
| // Проверка на существование параметров. |
| if (typeof property == "object") { |
| // Два свойства которые обьязательно должны быть для составления уникального ид |
| // см. геттер key. (Object.defineProperty(Video.prototype, 'key'...) |
| if (typeof property.type == "string" && typeof property.id == "string") { |
| this.id = property.id; // ид ролика с источника. |
| this.type = property.type; // "v", "y", "m", "o"... |
| // Запрашиваем видео с кэша дабы не плодить обьекты. |
| if (typeof (video = localBase.isVideo(this.key)) == "object") |
| { |
| // Возвращаем ссылку на обьект видеофайла |
| return video; |
| } |
| // Далее заполнение обьекта данными |
| if (typeof property.title == "string") |
| this.title = property.title; |
| |
| if (typeof property.duration == "number") |
| this.duration = property.duration; |
| |
| if (typeof property.description == "string") |
| this.description = property.description; |
| |
| if (typeof property.duration == "string") { |
| property.duration = parseInt(property.duration); |
| if (!isNaN(property.duration)) |
| this.duration = property.duration; |
| } |
| // Передаем ссылку на обьект в локальную базу |
| localBase.setVideo(this); |
| } else { |
| //console.log(property); |
| } |
| } |
| }; |
| |
| // Далее обьявляем обьщие методы (Прототипы) |
| |
| |
| // Составление уникального ключа с типа и ид |
| Object.defineProperty(Video.prototype, 'key', { |
| get: function () { |
| if (!(typeof this.type == "string" && typeof this.id == "string")) |
| return; |
| if (typeof this._tmp != "object") { |
| this._tmp = {}; |
| } |
| if (typeof this._tmp.key != "string") { |
| this._tmp.key = this.type + '_' + this.id; |
| } |
| return this._tmp.key; |
| }, |
| configurable: true, |
| enumerable: true |
| }); |
| |
| // Получение строкового отображения продолжительности видеофайла |
| Object.defineProperty(Video.prototype, 'strTime', { |
| get: function () { |
| if (typeof this._tmp != "object") { |
| this._tmp = {}; |
| } |
| if (typeof this._tmp.strTime != "string") { |
| this._tmp.strTime = secToMin(this.duration); |
| } |
| return this._tmp.strTime; |
| }, |
| configurable: true, |
| enumerable: true |
| }); |
| |
| // Генерация сылка на данный видеофайл. С дальнейшим кешированием в _tmp |
| Object.defineProperty(Video.prototype, 'url', { |
| get: function () { |
| if (!(typeof this.type == "string" && typeof this.id == "string")) |
| return '/404'; |
| if (typeof this.title != "string") |
| this.title = 'video'; |
| if (typeof this._tmp != "object") { |
| this._tmp = {}; |
| } |
| if (typeof this._tmp.url != "string" || this._tmp.url == '') |
| this._tmp.url = '/' + chpurl.titleToUrl(this.title) + '/' + this.type + '_' + this.id; |
| //console.log(this); |
| return this._tmp.url; |
| |
| }, |
| configurable: true, |
| enumerable: true |
| }); |
| module.exports = Video; |