-
Notifications
You must be signed in to change notification settings - Fork 983
/
File.groovy
88 lines (74 loc) · 1.51 KB
/
File.groovy
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
80
81
82
83
84
85
86
87
88
package streama
class File {
def uploadService
Date dateCreated
Date lastUpdated
String sha256Hex
String name
String extension
String contentType
String originalFilename
Long size
String externalLink
String localFile
String quality
static constraints = {
sha256Hex maxSize: 64
quality inList: ['720p', '480p', '360p']
}
static transients = ['uploadService']
def getImagePath(){
uploadService.getPath(this)
}
def getSrc(){
if(externalLink){
return externalLink
}
def res = uploadService.getFileSrc(this)
return res
}
def getFileExists(){
if(this.imagePath){
java.io.File rawFile = new java.io.File(this.imagePath)
return rawFile.exists()
}else{
return false
}
}
def getAssociatedVideos(){
def videos = Video.withCriteria {
ne("deleted", true)
files{
idEq(this.id)
}
}
return videos
}
def getAssociatedVideosInclDeleted(){
def videos = Video.withCriteria {
files{
idEq(this.id)
}
}
return videos
}
def getIsInUse(){
if(this.associatedVideos){
return true
}
else if(TvShow.findByDeletedNotEqualAndBackdrop_image(true, this)){
return true
}
else if(TvShow.findByDeletedNotEqualAndPoster_image(true, this)){
return true
}
}
def getSimpleInstance(){
return [
id: this.id,
src: this.getSrc(),
originalFilename: this.originalFilename,
contentType: this.contentType
]
}
}