@@ -18,46 +18,45 @@ function getAllFiles(folder) {
18
18
return files;
19
19
}
20
20
21
- function showConsoleLink(serviceName, action, open, id = '') {
22
- let resource = '';
23
- let service = '';
21
+
22
+ function showConsoleLink(serviceName, action, open, ...ids) {
23
+ const projectId = localConfig.getProject().projectId;
24
+
25
+ const url = new URL(globalConfig.getEndpoint().replace('/v1', '/console'));
26
+ url.pathname += `/project-${projectId}`;
27
+ action = action.toLowerCase();
24
28
25
29
switch (serviceName) {
26
30
case "account":
27
- service = 'account';
31
+ url.pathname = url.pathname.replace(`/project-${projectId}`, '');
32
+ url.pathname += getAccountPath(action);
28
33
break;
29
34
case "databases":
30
- resource = 'database';
31
- service = 'databases';
35
+ url.pathname += getDatabasePath(action, ids);
32
36
break;
33
37
case "functions":
34
- resource = 'function';
35
- service = 'functions';
38
+ url.pathname += getFunctionsPath(action, ids);
39
+ break;
40
+ case "messaging":
41
+ url.pathname += getMessagingPath(action, ids);
36
42
break;
37
43
case "projects":
38
- service = `project-${id}`;
39
- id = '';
44
+ url.pathname = url.pathname.replace(`/project-${projectId}`, '');
45
+ url.pathname += getProjectsPath(action, ids);
46
+ break;
47
+ case "storage":
48
+ url.pathname += getBucketsPath(action, ids);
40
49
break;
41
50
case "teams":
42
- resource = 'team';
43
- service = 'auth/teams';
51
+ url.pathname += getTeamsPath(action, ids);
44
52
break;
45
-
46
53
case "users":
47
- resource = 'user';
48
- service = 'auth';
54
+ url.pathname += getUsersPath(action, ids);
49
55
break;
50
56
default:
51
57
return;
52
58
}
53
59
54
- const baseUrl = globalConfig.getEndpoint().replace('/v1', '');
55
-
56
- const end = action === 'get' ? (id ? `/${resource}-${id}` : `/${resource}`) : '';
57
- const projectId = localConfig.getProject().projectId;
58
- const middle = resource !== '' ? `/project-${projectId}` : '';
59
- const url = `${baseUrl}/console${middle}/${service}${end}`
60
-
61
60
62
61
success(url);
63
62
@@ -67,6 +66,161 @@ function showConsoleLink(serviceName, action, open, id = '') {
67
66
}
68
67
}
69
68
69
+ function getAccountPath(action) {
70
+ let path = '/account';
71
+
72
+ if (action === 'listsessions') {
73
+ path += '/sessions';
74
+ }
75
+
76
+ return path;
77
+ }
78
+
79
+ function getDatabasePath(action, ids) {
80
+ let path = '/databases';
81
+
82
+
83
+ if (['get', 'listcollections', 'getcollection', 'listattributes', 'listdocuments', 'getdocument', 'listindexes', 'getdatabaseusage'].includes(action)) {
84
+ path += `/database-${ids[0]}`;
85
+ }
86
+
87
+ if (action === 'getdatabaseusage') {
88
+ path += `/usage`;
89
+ }
90
+
91
+ if (['getcollection', 'listattributes', 'listdocuments', 'getdocument', 'listindexes'].includes(action)) {
92
+ path += `/collection-${ids[1]}`;
93
+ }
94
+
95
+ if (action === 'listattributes') {
96
+ path += '/attributes';
97
+ }
98
+ if (action === 'listindexes') {
99
+ path += '/indexes';
100
+ }
101
+ if (action === 'getdocument') {
102
+ path += `/document-${ids[2]}`;
103
+ }
104
+
105
+
106
+ return path;
107
+ }
108
+
109
+ function getFunctionsPath(action, ids) {
110
+ let path = '/functions';
111
+
112
+ if (action !== 'list') {
113
+ path += `/function-${ids[0]}`;
114
+ }
115
+
116
+ if (action === 'getdeployment') {
117
+ path += `/deployment-${ids[1]}`
118
+ }
119
+
120
+ if (action === 'getexecution' || action === 'listexecution') {
121
+ path += `/executions`
122
+ }
123
+ if (action === 'getfunctionusage') {
124
+ path += `/usage`
125
+ }
126
+
127
+ return path;
128
+ }
129
+
130
+ function getMessagingPath(action, ids) {
131
+ let path = '/messaging';
132
+
133
+ if (['getmessage', 'listmessagelogs'].includes(action)) {
134
+ path += `/message-${ids[0]}`;
135
+ }
136
+
137
+ if (['listproviders', 'getprovider'].includes(action)) {
138
+ path += `/providers`;
139
+ }
140
+
141
+ if (action === 'getprovider') {
142
+ path += `/provider-${ids[0]}`;
143
+ }
144
+
145
+ if (['listtopics', 'gettopic'].includes(action)) {
146
+ path += `/topics`;
147
+ }
148
+
149
+ if (action === 'gettopic') {
150
+ path += `/topic-${ids[0]}`;
151
+ }
152
+
153
+ return path;
154
+ }
155
+
156
+ function getProjectsPath(action, ids) {
157
+ let path = '';
158
+
159
+ if (action !== 'list') {
160
+ path += `/project-${ids[0]}`;
161
+ }
162
+
163
+ if (['listkeys', 'getkey'].includes(action)) {
164
+ path += '/overview/keys'
165
+ }
166
+
167
+ if (['listplatforms', 'getplatform'].includes(action)) {
168
+ path += '/overview/platforms'
169
+ }
170
+
171
+ if (['listwebhooks', 'getwebhook'].includes(action)) {
172
+ path += '/settings/webhooks'
173
+ }
174
+
175
+ if (['getplatform', 'getkey', 'getwebhook'].includes(action)) {
176
+ path += ids[1];
177
+ }
178
+
179
+ return path;
180
+ }
181
+
182
+ function getBucketsPath(action, ids) {
183
+ let path = '/storage';
184
+
185
+ if (action !== 'listbuckets') {
186
+ path += `/bucket-${ids[0]}`;
187
+ }
188
+
189
+ if (action === 'getbucketusage') {
190
+ path += `/usage`
191
+ }
192
+
193
+ if (action === 'getfile') {
194
+ path += `/file-${ids[1]}`
195
+ }
196
+
197
+ return path;
198
+ }
199
+
200
+ function getTeamsPath(action, ids) {
201
+ let path = '/auth/teams';
202
+
203
+ if (action !== 'list') {
204
+ path += `/team-${ids[0]}`;
205
+ }
206
+
207
+ return path;
208
+ }
209
+
210
+ function getUsersPath(action, ids) {
211
+ let path = '/auth';
212
+
213
+ if (action !== 'list') {
214
+ path += `/user-${ids[0]}`;
215
+ }
216
+
217
+ if (action === 'listsessions') {
218
+ path += 'sessions';
219
+ }
220
+
221
+ return path;
222
+ }
223
+
70
224
module.exports = {
71
225
getAllFiles,
72
226
showConsoleLink
0 commit comments