Skip to content

Commit f957ea0

Browse files
committed
Update files to authenticate with request headers
1 parent 6a84b7b commit f957ea0

File tree

3 files changed

+44
-40
lines changed

3 files changed

+44
-40
lines changed

server/scripts/examples-gg-latest.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,11 @@ function getCodePackage() {
114114
// url: 'https://api.github.com/repos/generative-design/Code-Package-p5.js/contents',
115115
url: `https://api.github.com/repos/generative-design/Code-Package-p5.js/contents${branchRef}`,
116116
// url: 'https://api.github.com/repos/generative-design/Code-Package-p5.js/contents?ref=pre-release',
117-
qs: {
118-
client_id: clientId,
119-
client_secret: clientSecret
120-
},
121117
method: 'GET',
122-
headers,
118+
headers: {
119+
...headers,
120+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
121+
},
123122
json: true
124123
};
125124

@@ -144,12 +143,11 @@ function getSketchDirectories(sketchRootList) {
144143
// console.log(sketches)
145144
const options = {
146145
url: `https://api.github.com/repos/generative-design/Code-Package-p5.js/contents/${sketches.path}${branchRef}`,
147-
qs: {
148-
client_id: clientId,
149-
client_secret: clientSecret
150-
},
151146
method: 'GET',
152-
headers,
147+
headers: {
148+
...headers,
149+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
150+
},
153151
json: true
154152
};
155153

@@ -179,12 +177,11 @@ function appendSketchItemLinks(sketchList) {
179177
const options = {
180178
// url: `${sketches.url}?client_id=${clientId}&client_secret=${clientSecret}`,
181179
url: `https://api.github.com/repos/generative-design/Code-Package-p5.js/contents/${sketches.path}${branchRef}`,
182-
qs: {
183-
client_id: clientId,
184-
client_secret: clientSecret
185-
},
186180
method: 'GET',
187-
headers,
181+
headers: {
182+
...headers,
183+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
184+
},
188185
json: true
189186
};
190187

@@ -205,12 +202,11 @@ function getSketchItems(sketchList) {
205202
if (item.name === 'data') {
206203
const options = {
207204
url: `https://api.github.com/repos/generative-design/Code-Package-p5.js/contents/${item.path}${branchRef}`,
208-
qs: {
209-
client_id: clientId,
210-
client_secret: clientSecret
211-
},
212205
method: 'GET',
213-
headers,
206+
headers: {
207+
...headers,
208+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
209+
},
214210
json: true
215211
};
216212

@@ -409,12 +405,11 @@ function getAllSketchContent(newProjectList) {
409405
) {
410406
const options = {
411407
url: newProject.files[i].content,
412-
qs: {
413-
client_id: clientId,
414-
client_secret: clientSecret
415-
},
416408
method: 'GET',
417-
headers
409+
headers: {
410+
...headers,
411+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
412+
}
418413
};
419414

420415
// console.log("CONVERT ME!")

server/scripts/examples-ml5.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ ok(editorApiUrl, 'EDITOR_API_URL is required');
2525
//
2626
const githubRequestOptions = {
2727
url: baseUrl,
28-
qs: {
29-
client_id: clientId,
30-
client_secret: clientSecret
31-
},
3228
method: 'GET',
33-
headers,
29+
headers: {
30+
...headers,
31+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
32+
},
3433
json: true
3534
};
3635

server/scripts/examples.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ mongoose.connection.on('error', () => {
4949
function getCategories() {
5050
const categories = [];
5151
const options = {
52-
url: `https://api.github.com/repos/processing/p5.js-website/contents/src/data/examples/en?client_id=${
53-
clientId}&client_secret=${clientSecret}`,
52+
url: 'https://api.github.com/repos/processing/p5.js-website/contents/src/data/examples/en',
5453
method: 'GET',
55-
headers,
54+
headers: {
55+
...headers,
56+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
57+
},
5658
json: true
5759
};
5860
return rp(options).then((res) => {
@@ -73,9 +75,12 @@ function getCategories() {
7375
function getSketchesInCategories(categories) {
7476
return Q.all(categories.map((category) => {
7577
const options = {
76-
url: `${category.url.replace('?ref=main', '')}?client_id=${clientId}&client_secret=${clientSecret}`,
78+
url: `${category.url.replace('?ref=main', '')}`,
7779
method: 'GET',
78-
headers,
80+
headers: {
81+
...headers,
82+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
83+
},
7984
json: true
8085
};
8186

@@ -107,9 +112,12 @@ function getSketchesInCategories(categories) {
107112
function getSketchContent(projectsInAllCategories) {
108113
return Q.all(projectsInAllCategories.map(projectsInOneCategory => Q.all(projectsInOneCategory.map((project) => {
109114
const options = {
110-
url: `${project.sketchUrl.replace('?ref=main', '')}?client_id=${clientId}&client_secret=${clientSecret}`,
115+
url: `${project.sketchUrl.replace('?ref=main', '')}`,
111116
method: 'GET',
112-
headers
117+
headers: {
118+
...headers,
119+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
120+
}
113121
};
114122

115123
return rp(options).then((res) => {
@@ -134,10 +142,12 @@ function getSketchContent(projectsInAllCategories) {
134142

135143
function createProjectsInP5user(projectsInAllCategories) {
136144
const options = {
137-
url: `https://api.github.com/repos/processing/p5.js-website/contents/src/data/examples/assets?client_id=${
138-
clientId}&client_secret=${clientSecret}`,
145+
url: 'https://api.github.com/repos/processing/p5.js-website/contents/src/data/examples/assets',
139146
method: 'GET',
140-
headers,
147+
headers: {
148+
...headers,
149+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
150+
},
141151
json: true
142152
};
143153

0 commit comments

Comments
 (0)