2023-07-05 01:14:44 +02:00
|
|
|
const { DataTypes, Model } = require('sequelize')
|
|
|
|
|
2023-08-16 01:03:43 +02:00
|
|
|
class FeedEpisode extends Model {
|
|
|
|
constructor(values, options) {
|
|
|
|
super(values, options)
|
|
|
|
|
|
|
|
/** @type {UUIDV4} */
|
|
|
|
this.id
|
|
|
|
/** @type {string} */
|
|
|
|
this.title
|
|
|
|
/** @type {string} */
|
|
|
|
this.description
|
|
|
|
/** @type {string} */
|
|
|
|
this.siteURL
|
|
|
|
/** @type {string} */
|
|
|
|
this.enclosureURL
|
|
|
|
/** @type {string} */
|
|
|
|
this.enclosureType
|
|
|
|
/** @type {BigInt} */
|
|
|
|
this.enclosureSize
|
|
|
|
/** @type {string} */
|
|
|
|
this.pubDate
|
|
|
|
/** @type {string} */
|
|
|
|
this.season
|
|
|
|
/** @type {string} */
|
|
|
|
this.episode
|
|
|
|
/** @type {string} */
|
|
|
|
this.episodeType
|
|
|
|
/** @type {number} */
|
|
|
|
this.duration
|
|
|
|
/** @type {string} */
|
|
|
|
this.filePath
|
|
|
|
/** @type {boolean} */
|
|
|
|
this.explicit
|
|
|
|
/** @type {UUIDV4} */
|
|
|
|
this.feedId
|
|
|
|
/** @type {Date} */
|
|
|
|
this.createdAt
|
|
|
|
/** @type {Date} */
|
|
|
|
this.updatedAt
|
|
|
|
}
|
|
|
|
|
|
|
|
getOldEpisode() {
|
|
|
|
const enclosure = {
|
|
|
|
url: this.enclosureURL,
|
|
|
|
size: this.enclosureSize,
|
|
|
|
type: this.enclosureType
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
2023-08-16 01:03:43 +02:00
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
title: this.title,
|
|
|
|
description: this.description,
|
|
|
|
enclosure,
|
|
|
|
pubDate: this.pubDate,
|
|
|
|
link: this.siteURL,
|
|
|
|
author: this.author,
|
|
|
|
explicit: this.explicit,
|
|
|
|
duration: this.duration,
|
|
|
|
season: this.season,
|
|
|
|
episode: this.episode,
|
|
|
|
episodeType: this.episodeType,
|
|
|
|
fullPath: this.filePath
|
|
|
|
}
|
|
|
|
}
|
2023-07-06 01:18:37 +02:00
|
|
|
|
2023-09-23 21:27:13 +02:00
|
|
|
/**
|
|
|
|
* Create feed episode from old model
|
2024-05-29 00:24:02 +02:00
|
|
|
*
|
|
|
|
* @param {string} feedId
|
|
|
|
* @param {Object} oldFeedEpisode
|
2023-09-23 21:27:13 +02:00
|
|
|
* @returns {Promise<FeedEpisode>}
|
|
|
|
*/
|
|
|
|
static createFromOld(feedId, oldFeedEpisode) {
|
|
|
|
const newEpisode = this.getFromOld(oldFeedEpisode)
|
|
|
|
newEpisode.feedId = feedId
|
|
|
|
return this.create(newEpisode)
|
|
|
|
}
|
|
|
|
|
2023-08-16 01:03:43 +02:00
|
|
|
static getFromOld(oldFeedEpisode) {
|
|
|
|
return {
|
|
|
|
id: oldFeedEpisode.id,
|
|
|
|
title: oldFeedEpisode.title,
|
|
|
|
author: oldFeedEpisode.author,
|
|
|
|
description: oldFeedEpisode.description,
|
|
|
|
siteURL: oldFeedEpisode.link,
|
|
|
|
enclosureURL: oldFeedEpisode.enclosure?.url || null,
|
|
|
|
enclosureType: oldFeedEpisode.enclosure?.type || null,
|
|
|
|
enclosureSize: oldFeedEpisode.enclosure?.size || null,
|
|
|
|
pubDate: oldFeedEpisode.pubDate,
|
|
|
|
season: oldFeedEpisode.season || null,
|
|
|
|
episode: oldFeedEpisode.episode || null,
|
|
|
|
episodeType: oldFeedEpisode.episodeType || null,
|
|
|
|
duration: oldFeedEpisode.duration,
|
|
|
|
filePath: oldFeedEpisode.fullPath,
|
|
|
|
explicit: !!oldFeedEpisode.explicit
|
2023-07-06 01:18:37 +02:00
|
|
|
}
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
|
2023-08-16 01:03:43 +02:00
|
|
|
/**
|
|
|
|
* Initialize model
|
2024-05-29 00:24:02 +02:00
|
|
|
* @param {import('../Database').sequelize} sequelize
|
2023-08-16 01:03:43 +02:00
|
|
|
*/
|
|
|
|
static init(sequelize) {
|
2024-05-29 00:24:02 +02:00
|
|
|
super.init(
|
|
|
|
{
|
|
|
|
id: {
|
|
|
|
type: DataTypes.UUID,
|
|
|
|
defaultValue: DataTypes.UUIDV4,
|
|
|
|
primaryKey: true
|
|
|
|
},
|
|
|
|
title: DataTypes.STRING,
|
|
|
|
author: DataTypes.STRING,
|
|
|
|
description: DataTypes.TEXT,
|
|
|
|
siteURL: DataTypes.STRING,
|
|
|
|
enclosureURL: DataTypes.STRING,
|
|
|
|
enclosureType: DataTypes.STRING,
|
|
|
|
enclosureSize: DataTypes.BIGINT,
|
|
|
|
pubDate: DataTypes.STRING,
|
|
|
|
season: DataTypes.STRING,
|
|
|
|
episode: DataTypes.STRING,
|
|
|
|
episodeType: DataTypes.STRING,
|
|
|
|
duration: DataTypes.FLOAT,
|
|
|
|
filePath: DataTypes.STRING,
|
|
|
|
explicit: DataTypes.BOOLEAN
|
2023-08-16 01:03:43 +02:00
|
|
|
},
|
2024-05-29 00:24:02 +02:00
|
|
|
{
|
|
|
|
sequelize,
|
|
|
|
modelName: 'feedEpisode'
|
|
|
|
}
|
|
|
|
)
|
2023-07-05 01:14:44 +02:00
|
|
|
|
2023-08-16 01:03:43 +02:00
|
|
|
const { feed } = sequelize.models
|
2023-07-05 01:14:44 +02:00
|
|
|
|
2023-08-16 01:03:43 +02:00
|
|
|
feed.hasMany(FeedEpisode, {
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
|
|
|
FeedEpisode.belongsTo(feed)
|
|
|
|
}
|
|
|
|
}
|
2023-07-05 01:14:44 +02:00
|
|
|
|
2024-05-29 00:24:02 +02:00
|
|
|
module.exports = FeedEpisode
|