-
Notifications
You must be signed in to change notification settings - Fork 2
/
songs.js
79 lines (77 loc) · 1.77 KB
/
songs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const mongoose = require("mongoose")
const songsSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
songURL: {
type: String,
required: true,
validate: {
validator: async v => {
if(!v) return true
await fetch(v)
return true
},
message: "Not a valid video"
}
},
urlHash: {
type: String,
required: true
},
songName: {
type: String,
required: true
},
ytVideoID: {
type: String,
required: true,
validate: {
validator: async v => {
let exists = await fetch("https://youtube.com/watch?v="+v)
return exists.ok
},
message: "Not a valid youtube video"
}
},
songID: {
type: String,
required: true
},
state: {
type: String,
required: true,
validate: {
validator: v => ["rated", "unrated", "mashup", "challenge", "remix", "loop"].includes(v),
message: "Not a valid state!"
}
},
filetype: {
type: String,
required: true,
validate: {
validator: v => ["mp3", "ogg"].includes(v),
message: "Not a valid file type!"
}
},
downloadUrl: {
type: String,
required: true
},
downloads: Number,
levelID: {
type: [String],
required: true,
validate: {
validator: async v => {
if(!v.length) return false;
return true
},
message: "Not a valid level ID!"
}
},
}, {
id: false
})
module.exports = mongoose.model("songs", songsSchema)