-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.js
More file actions
174 lines (137 loc) · 5.14 KB
/
Copy pathapi.js
File metadata and controls
174 lines (137 loc) · 5.14 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const fetch = require('node-fetch');
const WebhookService = require('./services/webhook-service');
const TranslationService = require('./services/translation-service');
const { onshapeApiUrl } = require('./config');
const { forwardRequestToOnshape } = require('./utils');
const redisClient = require('./redis-client');
const apiRouter = require('express').Router();
/**
* Add Custom Feature to the Feature List
*/
apiRouter.post('/createAppElement', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/appelements/d/${req.query.documentId}/w/${req.query.workspaceId}`, req, res);
});
/**
* Get the Elements of the current document/workspace.
*
* GET /api/elements
* -> 200, [ ...elements ]
* -or-
* -> 500, { error: '...' }
*/
apiRouter.get('/elements', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/documents/d/${req.query.documentId}/w/${req.query.workspaceId}/elements`, req, res);
});
/**
* Get the Elements of the current document/workspace.
*
* GET /api/elements
* -> 200, [ ...elements ]
* -or-
* -> 500, { error: '...' }
*/
apiRouter.get('/getElementChangeId', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/appelements/d/${req.query.documentId}/w/${req.query.workspaceId}/e/${req.query.storageId}/content/json?transactionId=&changeId=`, req, res);
});
/**
* Get the default settings from Onshape user
*/
apiRouter.get('/users/settings', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/users/settings`, req, res);
});
/**
* Get the Session info from Onshape to get User ID information
*/
apiRouter.get('/users/sessioninfo', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/users/sessioninfo`, req, res);
});
/**
* Get all Feature Studio elements from the document
*/
apiRouter.get('/getApplicationStorage', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/documents/d/${req.query.documentId}/w/${req.query.workspaceId}/elements?elementType=APPLICATION&withThumbnails=false`, req, res);
});
/**
* Get all Feature Studio elements from the document
*/
apiRouter.get('/getFStudio', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/documents/d/${req.query.documentId}/w/${req.query.workspaceId}/elements?elementType=FEATURESTUDIO&withThumbnails=false`, req, res);
});
/**
* Get the Feature Studio contents from the onshape document
*/
apiRouter.get('/fsContents', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/featurestudios/d/${req.query.documentId}/w/${req.query.workspaceId}/e/${req.query.blockly}`, req, res);
});
/**
* Update the contents of the target Feature Studio
*/
apiRouter.post('/updateFStudio', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/featurestudios/d/${req.query.documentId}/w/${req.query.workspaceId}/e/${req.query.blockly}`, req, res);
});
/**
* Create a new Feature Studio
*/
apiRouter.post('/createFStudio', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/featurestudios/d/${req.query.documentId}/w/${req.query.workspaceId}`, req, res);
});
/**
* Create a new Feature Studio
*/
apiRouter.post('/updateAppElement', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/appelements/d/${req.query.documentId}/w/${req.query.workspaceId}/e/${req.query.storageId}/content`, req, res);
});
/**
* Get the Feature Studio Specs
*/
apiRouter.get('/specsFStudio', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/featurestudios/d/${req.query.documentId}/w/${req.query.workspaceId}/e/${req.query.blockly}/featurespecs`, req, res);
});
/**
* Add Custom Feature to the Feature List
*/
apiRouter.post('/addFeatureToList', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/partstudios/d/${req.query.documentId}/w/${req.query.workspaceId}/e/${req.query.elementId}/features`, req, res);
});
/**
* Get the Feature List of the target Part Studio
*/
apiRouter.get('/getFeatureList', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/partstudios/d/${req.query.documentId}/w/${req.query.workspaceId}/e/${req.query.elementId}/features`, req, res);
});
/**
* Get the Parts of the given Element in the current document/workspace.
*
* GET /api/elements/:eid/parts
* -> 200, [ ...parts ]
* -or-
* -> 500, { error: '...' }
*/
apiRouter.get('/elements/:eid/parts', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/parts/d/${req.query.documentId}/w/${req.query.workspaceId}/e/${req.params.eid}`, req, res);
});
/**
* Get the Parts of the current document/workspace.
*
* GET /api/parts
* -> 200, [ ...parts ]
* -or-
* -> 500, { error: '...' }
*/
apiRouter.get('/parts', (req, res) => {
forwardRequestToOnshape(`${onshapeApiUrl}/parts/d/${req.query.documentId}/w/${req.query.workspaceId}`, req, res);
});
/**
* Receive a webhook event.
*
* POST /api/event
* -> 200
*/
apiRouter.post('/event', (req, res) => {
if (req.body.event === 'onshape.model.translation.complete') {
// Save in Redis so we can return to client later (& unregister the webhook).
redisClient.set(req.body.translationId, req.body.webhookId);
}
res.status(200).send();
});
module.exports = apiRouter;