const path = require('path'); const { DataTypes } = require('sequelize'); const Base = require('./Base.js'); const tableName = path.basename(__filename, '.js').toLowerCase(); class Track extends Base { constructor(tags, file) { super(); this.tableName = tableName; this.title = tags?.common?.title; this.year = tags?.common?.year; this.duration = tags?.common?.duration; let comment = undefined; if (tags?.common?.comment !== undefined) { let comment = ''; if (Array.isArray(tags.common.comment)) { for (let index = 0; index < tags.common.comment.length; index++) { if (comment.length > 0) { comment += '\n'; } comment += tags.common.comment[index]; } } else { comment = tags.common.comment; } } this.comment = comment; this.diskno = tags?.common?.disk?.no; this.diskof = tags?.common?.disk?.of; this.trackno = tags?.common?.track?.no; this.trackof = tags?.common?.track?.of; this.file = file; } isValid() { return this.title !== undefined && this.file !== undefined; } async getModel() { return database.connection.define(tableName, { title: DataTypes.TEXT, year: DataTypes.INTEGER, duration: DataTypes.FLOAT, comment: DataTypes.TEXT, diskno: DataTypes.INTEGER, diskof: DataTypes.INTEGER, trackno: DataTypes.INTEGER, trackof: DataTypes.INTEGER, file: DataTypes.TEXT }); } } module.exports = Track;