2024-01-24 01:35:47 +01:00
|
|
|
import { BaseEntity, BeforeInsert, Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
2024-01-22 23:04:46 +01:00
|
|
|
import { FULL_SERVER_ROOT } from "../Modules/Constants";
|
2024-01-24 01:35:47 +01:00
|
|
|
import { Rating } from "./Rating";
|
|
|
|
import { existsSync, mkdirSync } from "fs";
|
|
|
|
import { v4 } from "uuid";
|
2024-01-22 00:41:59 +01:00
|
|
|
|
|
|
|
@Entity()
|
|
|
|
export class Song extends BaseEntity {
|
|
|
|
@PrimaryGeneratedColumn("uuid")
|
|
|
|
ID: string;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
Name: string;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
Year: number;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
ArtistName: string;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
Length: number;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
Scale: "Minor" | "Major";
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
Key: string;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
Album: string;
|
|
|
|
|
|
|
|
@Column({ default: "Guitar" })
|
|
|
|
GuitarStarterType: "Keytar" | "Guitar";
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
Tempo: number;
|
|
|
|
|
|
|
|
@Column()
|
2024-01-22 23:04:46 +01:00
|
|
|
Directory: string;
|
|
|
|
|
|
|
|
@Column({ nullable: true })
|
|
|
|
Midi?: string;
|
|
|
|
|
|
|
|
@Column({ nullable: true })
|
|
|
|
Cover?: string;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
BassDifficulty: number;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
GuitarDifficulty: number;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
DrumsDifficulty: number;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
VocalsDifficulty: number;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
CreationDate: Date;
|
2024-01-22 00:41:59 +01:00
|
|
|
|
|
|
|
@Column({ nullable: true })
|
|
|
|
Lipsync?: string;
|
2024-01-22 23:04:46 +01:00
|
|
|
|
2024-01-24 01:35:47 +01:00
|
|
|
@OneToMany(() => Rating, R => R.Rated)
|
|
|
|
Ratings: Rating[];
|
|
|
|
|
2024-01-22 23:04:46 +01:00
|
|
|
@BeforeInsert()
|
|
|
|
Setup() {
|
2024-01-24 01:35:47 +01:00
|
|
|
this.ID = v4();
|
|
|
|
this.Directory = `./Saved/Songs/${this.ID}`;
|
|
|
|
if (!existsSync(this.Directory))
|
|
|
|
mkdirSync(this.Directory);
|
|
|
|
|
2024-01-22 23:04:46 +01:00
|
|
|
this.CreationDate = new Date();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Package() {
|
|
|
|
return {
|
|
|
|
...this,
|
|
|
|
Directory: undefined, // we should NOT reveal that
|
|
|
|
Midi: this.Midi ?? `${FULL_SERVER_ROOT}/song/download/${this.ID}/midi.mid`,
|
|
|
|
Cover: this.Cover ?? `${FULL_SERVER_ROOT}/song/download/${this.ID}/cover.png`
|
|
|
|
}
|
|
|
|
}
|
2024-01-22 00:41:59 +01:00
|
|
|
}
|