kannon/models/Track.js

59 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2022-06-03 17:04:44 +02:00
const path = require('path');
2022-04-14 14:23:41 +02:00
const { DataTypes } = require('sequelize');
2022-06-03 17:04:44 +02:00
const Base = require('./Base.js');
2022-06-03 14:52:35 +02:00
2022-06-03 17:04:44 +02:00
const tableName = path.basename(__filename, '.js').toLowerCase();
class Track extends Base {
2022-06-03 14:52:35 +02:00
2022-06-15 16:56:38 +02:00
constructor(tags, file) {
2022-06-08 15:06:38 +02:00
super();
2022-06-15 16:56:38 +02:00
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;
2022-06-03 14:52:35 +02:00
}
2022-06-03 17:04:44 +02:00
isValid() {
return this.title !== undefined &&
this.file !== undefined;
}
2022-06-03 14:52:35 +02:00
2022-06-03 17:04:44 +02:00
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
});
}
2022-06-03 14:52:35 +02:00
}
2022-06-03 17:04:44 +02:00
module.exports = Track;