forked from coldbox-modules/cbgithub
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContent.cfc
More file actions
92 lines (73 loc) · 2.44 KB
/
Content.cfc
File metadata and controls
92 lines (73 loc) · 2.44 KB
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
89
90
91
92
component accessors="true" {
property name="ContentService"
inject="ContentService@cbgithub"
getter="false"
setter="false";
property name="content" default="";
property name="_links" default="";
property name="html_url" default="";
property name="sha" default="";
property name="path" default="";
property name="url" default="";
property name="size" default="";
property name="name" default="";
property name="submodule_git_url" default="";
property name="type" default="";
property name="git_url" default="";
property name="download_url" default="";
property name="encoding" default="";
property name="mimetype" default="";
Content function init() {
variables.base64Library = createObject( "java", "org.apache.commons.codec.binary.Base64" );
variables._links = {
"git": "",
"self": "",
"html": ""
};
variables.mimeType = "";
return this;
}
function getContent(
boolean decode = true,
string encoding = "UTF-8"
) {
if ( arguments.decode ) {
var decodedContent = decodeContent();
if ( listFirst( getMimeType(), "/" ) == "text" ) {
return toString( decodedContent, arguments.encoding );
}
return decodedContent;
} else {
return variables.content;
}
}
function getMimeType() {
if ( variables.type == "file" && variables.mimeType == "" ) {
var randomFilename = createUUID();
fileWrite( "ram:///#randomFilename#", decodeContent() );
variables.mimeType = fileGetMimeType( "ram:///#randomFilename#", true );
fileDelete( "ram:///#randomFilename#" );
}
return variables.mimeType;
}
function getDownloadUrl() {
return variables.download_url;
}
function getGitUrl() {
return variables.git_url;
}
function getHtmlUrl() {
return variables.html_url;
}
function getLinks() {
return variables._links;
}
function getSubmoduleGitUrl() {
return variables.submodule_git_url;
}
private function decodeContent() {
// drop down into Java to decode the Base64 string due to a bug in Railo 4.2+ and Lucee 4+
// https://luceeserver.atlassian.net/browse/LDEV-555
return variables.base64Library.decodeBase64( variables.content );
}
}