-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.py
More file actions
337 lines (273 loc) Β· 10.9 KB
/
Copy pathupload.py
File metadata and controls
337 lines (273 loc) Β· 10.9 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import requests
def upload_jlc(zip_path: str):
"""
Submits a zip file to JLCPCB and retrieves the URL to the order page.
"""
# API endpoint
url = "https://cart.jlcpcb.com/api/overseas-shop-cart/v1/file/uploadGerber"
# Form data
data = {"calculationCostsType": "1"}
headers = {
"accept": "application/json, text/plain, */*",
"cache-control": "no-cache",
}
files = {"gerberFile": open(zip_path, "rb")}
"""
Reference headers:
headers = {
"accept": "application/json, text/plain, /",
"accept-language": "en-GB, en-US;q=0.9, en;q=0.8",
"cache-control": "no-cache",
"content-type": "multipart/form-data; boundary=----WebKitFormBoundarySvY28A6yVIy2sAAw",
"pragma": "no-cache",
"priority": "u=1, i",
"sec-ch-ua": '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"secretkey": "30626637303034332d366337642d346233382d386133392d353336616232663931383035",
"x-xsrf-token": "726726cf-24c3-4859-ac5b-0bed9f24ed4d",
}
Properties:
"referrer": "https://cart.jlcpcb.com/quote?spm=Jlcpcb.Homepage.1006",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": '------WebKitFormBoundarySvY28A6yVIy2sAAw\r\nContent-Disposition: form-data; name="gerberFile"; filename="output (37).zip"\r\nContent-Type: application/x-zip-compressed\r\n\r\n\r\n------WebKitFormBoundarySvY28A6yVIy2sAAw\r\nContent-Disposition: form-data; name="calculationCostsType"\r\n\r\n1\r\n------WebKitFormBoundarySvY28A6yVIy2sAAw--\r\n',
"method": "POST",
"mode": "cors",
"credentials": "include"
Response:
{
"code": 200,
"data": {
"fileId": "cc39a7d04a7743938f4ce34de9270b1b",
"fileName": "output (48).zip",
"calculationCostsType": 1,
"result": "success",
"resultStatus": null,
"s3SignatureResponse": {
"local": true,
"uploadFileToS3Url": null,
"httpStatusCode": null,
"signature": null,
"uploadBySignatureRequest": null
},
"fileSystemAccessId": "8614393686272851968",
"uid": null
},
"message": null
}
"""
response = requests.post(url, headers=headers, files=files, data=data)
if response.status_code == 200:
print("π’ Successfully uploaded to JLCPCB")
json_response = response.json()
data = json_response.get("data")
file_id = data.get("fileId")
order_url = "https://cart.jlcpcb.com/quote?homeUploadNum=" + file_id
if file_id:
print("π’ Access at:", order_url)
return order_url
else:
print("π΄ Failed to upload to JLCPCB")
print(response)
print(response.text)
def upload_euro(zip_path: str):
"""
Submits a zip file to Eurocircuits and retrieves the URL to the order page.
"""
# API endpoint
url = (
"https://www.eurocircuits.com/wp-json/eurocircuits/v1/calculation-upload-file/"
)
# Form data
data = {"data_type": "pcb"}
headers = {
"accept": "application/json, text/plain, */*",
"cache-control": "no-cache",
}
files = {"file": open(zip_path, "rb")}
"""
Reference headers:
headers = {
"accept": "application/json",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
"cache-control": "no-cache",
"content-type": "multipart/form-data; boundary=----WebKitFormBoundaryf6ekasTaY2DqAx5N",
"priority": "u=1, i",
"sec-ch-ua": '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest",
}
Properties:
"referrer": "https://www.eurocircuits.com/",
"referrerPolicy": "no-referrer-when-downgrade",
"method": "POST",
"mode": "cors",
"credentials": "include"
Response:
{
"success": true,
"message": "File uploaded successfully and sent to external service.",
"redirect_url": "https://be.eurocircuits.com/shop/assembly/configurepcb.aspx?sessionid=d9bfe4b5-dc9a-4e9b-80cf-3b1e747c971f&from=wp&type=PCB&filename=output-37.zip"
}
"""
response = requests.post(url, headers=headers, files=files, data=data)
if response.status_code == 200:
print("π’ Successfully uploaded to Eurocircuits")
json_response = response.json()
order_url = json_response.get("redirect_url")
if order_url:
print("π’ Access at:", order_url)
return order_url
else:
print("π΄ Failed to upload to Eurocircuits")
print(response)
print(response.text)
def upload_pcbway(zip_path: str):
"""
Submits a zip file to PCBWay and retrieves the URL to the order page.
"""
# FIX: This this one doesn't work, I didn't spend long looking into it, PCBWay
# lets us upload files via POST request and responds with a URL to that uploaded
# file, but I don't think there's a way to give a client a URL that takes them to
# an order page with that file loaded.
raise NotImplementedError()
# API endpoint
url = "https://www.pcbway.com/common/upfile/"
# Form data
data = {"name": "output.zip"}
data = {"uptype": "gerberfile"}
headers = {
"accept": "application/json, text/plain, */*",
"cache-control": "no-cache",
}
"""
Reference headers:
headers = {
"accept": "*/*",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
"cache-control": "no-cache",
"content-type": "multipart/form-data; boundary=----WebKitFormBoundaryIOCavAfwzkzo5BXv",
"pragma": "no-cache",
"priority": "u=1, i",
"sec-ch-ua": '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
}
Properties:
"referrer": "https://www.pcbway.com/QuickOrderOnline.aspx",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "------WebKitFormBoundaryIOCavAfwzkzo5BXv\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\noutput (69).zip\r\n------WebKitFormBoundaryIOCavAfwzkzo5BXv\r\nContent-Disposition: form-data; name=\"uptype\"\r\n\r\ngerberfile\r\n------WebKitFormBoundaryIOCavAfwzkzo5BXv\r\nContent-Disposition: form-data; name=\"file\"; filename=\"output (69).zip\"\r\nContent-Type: application/x-zip-compressed\r\n\r\n\r\n------WebKitFormBoundaryIOCavAfwzkzo5BXv--\r\n",
"method": "POST",
"mode": "cors",
"credentials": "include"
Response:
{
"url": "https://pcbwayfile.s3.us-west-2.amazonaws.com/gerber/25/05/24/075614912d64f7878f75c46fc82e29625b99f7c246670.zip",
"title": "",
"original": "output (69).zip",
"state": "SUCCESS"
}
"""
files = {"file": open(zip_path, "rb")}
response = requests.post(url, headers=headers, files=files, data=data)
if response.status_code == 200:
print("π’ Successfully uploaded to PCBWay")
json_response = response.json()
file_url = json_response.get("url")
# FIX: Do another request to get the order URL
order_url = None
if order_url:
print("π’ Access at:", order_url)
return order_url
else:
print("π΄ Failed to upload to PCBWay")
print(response)
print(response.text)
def upload_aisler(zip_path: str):
"""
Submits a zip file to Aisler and retrieves the URL to the order page.
"""
# First have to do a GET request to get a new project ID/upload URL
upload_url = None
order_url = None
url = "https://aisler.net/p/new.json?locale=en"
"""
Response:
{
"project_url": "https://aisler.net/p/BFPSKZOJ?locale=en",
"project_id": "BFPSKZOJ",
"upload_url": "https://aisler.net/p/BFPSKZOJ/uploads.json?locale=en"
}
"""
response = requests.get(url)
if response.status_code == 201: # Aisler uses proper HTTP status codes
print("π’ Successfully retrieved new project ID from Aisler")
json_response = response.json()
upload_url = json_response.get("upload_url")
order_url = json_response.get("project_url")
else:
print("π΄ Failed to retrieve new project ID from Aisler")
print(response)
print(response.text)
return
# Now regular POST request process
# API endpoint
url = upload_url
headers = {
"accept": "*/*",
"cache-control": "no-cache",
}
"""
Reference headers:
headers = {
"accept": "*/*",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
"cache-control": "no-cache",
"content-type": "multipart/form-data; boundary=----WebKitFormBoundaryuwsL1kp29leLKd8M",
"pragma": "no-cache",
"priority": "u=1, i",
"sec-ch-ua": '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
}
Properties:
"referrer": "https://aisler.net/en",
"referrerPolicy": "strict-origin-when-cross-origin",
"method": "POST",
"mode": "cors",
"credentials": "include"
Response:
201 Created
"""
# Aisler has a weird form, couldn't see the content-disposition in chrome network tab
# so used a packet inspector to find out "upload[file]" and octet-stream (set up SSL
# decryption, then "Follow HTTP/2 Stream" to see the request)
files = {
"upload[file]": (
"output.zip",
open(zip_path, "rb"),
"application/octet-stream",
)
}
response = requests.post(url, headers=headers, files=files)
if response.status_code == 201:
print("π’ Successfully uploaded to Aisler")
print("π’ Access at:", order_url)
return order_url
else:
print("π΄ Failed to upload to Aisler")
print(response)
print(response.text)