UNPKG

6.04 kBJavaScriptView Raw
1// var request = require("request");
2
3module.exports = function(){
4 this.id = "box-file-details";
5 this.label = "File Details";
6
7 this.input = {
8 "title": "File Details",
9 "type": "object",
10 "properties": {
11 "token":{
12 "title":"Box Access Token",
13 "type":"string",
14 "oauth" : "box",
15 "minLength" : 1,
16 "format":"token"
17 },
18 "file_id":{
19 "title":"File ID",
20 "type" :"string",
21 "minLength":1,
22 "description":"Enter file ID"
23 }
24 }
25 };
26 this.help = "Service to get file details"
27
28 this.output = {
29 "title" : "output",
30 "type" : "object",
31 "properties":{
32 "type":{
33 "title":"type",
34 "type" :"string"
35 },
36 "id":{
37 "title":"id",
38 "type" :"string"
39 },
40 "file_version":{
41 "title":"file_version",
42 "type" :"object"
43 },
44 "name":{
45 "title":"name",
46 "type" :"string"
47 },
48 "size":{
49 "title":"size",
50 "type" :"integer"
51 },
52 "path_collection":{
53 "title":"path_collection",
54 "type" :"object"
55 },
56 "created_at":{
57 "title":"created_at",
58 "type" :"string"
59 },
60 "modified_at":{
61 "title":"modified_at",
62 "type" :"string"
63 },
64 "content_created_at":{
65 "title":"content_created_at",
66 "type" :"string"
67 },
68 "content_modified_at":{
69 "title":"content_modified_at",
70 "type" :"string"
71 },
72 "created_by":{
73 "title":"created_by",
74 "type" :"object",
75 "properties":{
76 "type":{
77 "title":"type",
78 "type" :"string"
79 },
80 "id":{
81 "title":"id",
82 "type" :"string"
83 },
84 "name":{
85 "title":"name",
86 "type" :"string"
87 },
88 "login":{
89 "title":"login",
90 "type" :"string"
91 }
92 }
93 },
94 "modified_by":{
95 "title":"modified_by",
96 "type" :"object",
97 "properties":{
98 "type":{
99 "title":"type",
100 "type" :"string"
101 },
102 "id":{
103 "title":"id",
104 "type" :"string"
105 },
106 "name":{
107 "title":"name",
108 "type" :"string"
109 },
110 "login":{
111 "title":"login",
112 "type" :"string"
113 }
114 }
115 },
116 "owned_by":{
117 "title":"owned_by",
118 "type" :"object",
119 "properties":{
120 "type":{
121 "title":"type",
122 "type" :"string"
123 },
124 "id":{
125 "title":"id",
126 "type" :"string"
127 },
128 "name":{
129 "title":"name",
130 "type" :"string"
131 },
132 "login":{
133 "title":"login",
134 "type" :"string"
135 }
136 }
137 },
138 "shared_link":{
139 "title":"shared_link",
140 "type" :"any"
141 },
142 "parent":{
143 "title":"parent",
144 "type" :"object",
145 "properties":{
146 "type":{
147 "title":"type",
148 "type" :"string"
149 },
150 "id":{
151 "title":"id",
152 "type" :"string"
153 },
154 "sequence_id":{
155 "title":"id",
156 "type" :"any"
157 },
158 "etag":{
159 "title":"etag",
160 "type" :"any"
161 },
162 "name":{
163 "title":"name",
164 "type" :"string"
165 }
166 }
167 }
168 }
169 };
170 this.execute = function(input,output){
171 input.file_id = String(input.file_id).trim();
172 var expId = input.file_id.substring(0,2);
173 if(expId =="f_"){
174 input.file_id = input.file_id.substring(2, input.file_id.length);
175 }
176
177 request({
178 headers:{
179 "Authorization": "Bearer "+input.token,
180 "Accept":"application/json"
181 },
182 url:"https://api.box.com/2.0/files/"+input.file_id
183 },function(err,response,body){
184 if(err){
185 return output(err);
186 }
187 else{
188 if(response.statusCode==405){
189 return output("The file ID entered is not valid");
190 }
191 if(response.statusCode && response.statusCode >=200 && response.statusCode < 400){
192 if(typeof(body)=="string"){
193 body = JSON.parse(body);
194 }
195 return output(null,body);
196 }
197 return output(body);
198 }
199 })
200 };
201}
202