Skip to content

Commit 5801586

Browse files
committed
[#975] Updated examples.js
1 parent 81264a5 commit 5801586

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

server/scripts/examples.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rp from 'request-promise';
1+
import axios from 'axios';
22
import Q from 'q';
33
import mongoose from 'mongoose';
44
import objectID from 'bson-objectid';
@@ -59,12 +59,11 @@ async function getCategories() {
5959
Authorization: `Basic ${Buffer.from(
6060
`${clientId}:${clientSecret}`
6161
).toString('base64')}`
62-
},
63-
json: true
62+
}
6463
};
6564
try {
66-
const res = await rp(options);
67-
res.forEach((metadata) => {
65+
const { data } = await axios.request(options);
66+
data.forEach((metadata) => {
6867
let category = '';
6968
for (let j = 1; j < metadata.name.split('_').length; j += 1) {
7069
category += `${metadata.name.split('_')[j]} `;
@@ -92,9 +91,9 @@ function getSketchesInCategories(categories) {
9291
json: true
9392
};
9493
try {
95-
const res = await rp(options);
94+
const { data } = await axios.request(options);
9695
const projectsInOneCategory = [];
97-
res.forEach((example) => {
96+
data.forEach((example) => {
9897
let projectName;
9998
if (example.name === '02_Instance_Container.js') {
10099
for (let i = 1; i < 5; i += 1) {
@@ -147,23 +146,23 @@ function getSketchContent(projectsInAllCategories) {
147146
}
148147
};
149148
try {
150-
const res = await rp(options);
149+
const { data } = await axios.request(options);
151150
const noNumberprojectName = project.projectName.replace(
152151
/(\d+)/g,
153152
''
154153
);
155154
if (noNumberprojectName === 'Instance Mode: Instance Container ') {
156155
for (let i = 0; i < 4; i += 1) {
157156
const splitedRes = `${
158-
res.split('*/')[1].split('</html>')[i]
157+
data.split('*/')[1].split('</html>')[i]
159158
}</html>\n`;
160159
project.sketchContent = splitedRes.replace(
161160
'p5.js',
162161
'https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.js'
163162
);
164163
}
165164
} else {
166-
project.sketchContent = res;
165+
project.sketchContent = data;
167166
}
168167
return project;
169168
} catch (error) {
@@ -217,15 +216,14 @@ async function addAssetsToProject(assets, response, project) {
217216
Authorization: `Basic ${Buffer.from(
218217
`${clientId}:${clientSecret}`
219218
).toString('base64')}`
220-
},
221-
json: true
219+
}
222220
};
223221

224222
// a function to await for the response that contains the content of asset file
225223
const doRequest = async (optionsAsset) => {
226224
try {
227-
const res = await rp(optionsAsset);
228-
return res;
225+
const { data } = await axios.request(optionsAsset);
226+
return data;
229227
} catch (error) {
230228
throw error;
231229
}
@@ -273,12 +271,11 @@ async function createProjectsInP5user(projectsInAllCategories) {
273271
Authorization: `Basic ${Buffer.from(
274272
`${clientId}:${clientSecret}`
275273
).toString('base64')}`
276-
},
277-
json: true
274+
}
278275
};
279276

280277
try {
281-
const res = await rp(options);
278+
const { data } = await axios.request(options);
282279
const user = await User.findOne({ username: 'p5' }).exec();
283280
await Q.all(
284281
projectsInAllCategories.map((projectsInOneCategory) =>
@@ -382,7 +379,7 @@ async function createProjectsInP5user(projectsInAllCategories) {
382379
[];
383380

384381
try {
385-
await addAssetsToProject(assetsInProject, res, newProject);
382+
await addAssetsToProject(assetsInProject, data, newProject);
386383
const savedProject = await newProject.save();
387384
console.log(
388385
`Created a new project in p5 user: ${savedProject.name}`

0 commit comments

Comments
 (0)