2024-01-28 16:54:32 +01:00
|
|
|
import { BaseEntity, BeforeInsert, BeforeRemove, Column, Entity, ManyToOne, 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";
|
2024-01-28 16:54:32 +01:00
|
|
|
import { existsSync, mkdirSync, rmSync } from "fs";
|
2024-01-24 01:35:47 +01:00
|
|
|
import { v4 } from "uuid";
|
2024-01-28 16:54:32 +01:00
|
|
|
import { User } from "./User";
|
|
|
|
import { join } from "path";
|
2024-01-22 00:41:59 +01:00
|
|
|
|
|
|
|
@Entity()
|
|
|
|
export class Song extends BaseEntity {
|
|
|
|
@PrimaryGeneratedColumn("uuid")
|
|
|
|
ID: string;
|
|
|
|
|
2024-01-28 16:54:32 +01:00
|
|
|
@ManyToOne(() => User, U => U.CreatedTracks)
|
|
|
|
Author: User;
|
|
|
|
|
2024-01-22 00:41:59 +01:00
|
|
|
@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;
|
|
|
|
|
2024-01-28 16:54:32 +01:00
|
|
|
@Column()
|
|
|
|
IsDraft: boolean;
|
2024-01-28 22:02:29 +01:00
|
|
|
|
|
|
|
@Column({ default: false })
|
|
|
|
DraftAwaitingReview: boolean;
|
2024-01-28 16:54:32 +01:00
|
|
|
|
2024-01-22 23:04:46 +01:00
|
|
|
@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}`;
|
2024-01-28 16:54:32 +01:00
|
|
|
if (!existsSync(join(this.Directory, "Chunks")))
|
|
|
|
mkdirSync(join(this.Directory, "Chunks"), { recursive: true });
|
2024-01-24 01:35:47 +01:00
|
|
|
|
2024-01-22 23:04:46 +01:00
|
|
|
this.CreationDate = new Date();
|
|
|
|
}
|
|
|
|
|
2024-01-28 16:54:32 +01:00
|
|
|
@BeforeRemove()
|
|
|
|
Delete() {
|
|
|
|
if (existsSync(this.Directory) && this.Directory.endsWith(this.ID))
|
|
|
|
rmSync(this.Directory, { recursive: true, force: true }); // lets hope this does not cause steam launcher for linux 2.0
|
|
|
|
}
|
|
|
|
|
2024-01-22 23:04:46 +01:00
|
|
|
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
|
|
|
}
|