|
1 | | -import rp from 'request-promise'; |
| 1 | +import axios from 'axios'; |
2 | 2 | import Q from 'q'; |
3 | 3 | import mongoose from 'mongoose'; |
4 | 4 | import objectID from 'bson-objectid'; |
@@ -59,12 +59,11 @@ async function getCategories() { |
59 | 59 | Authorization: `Basic ${Buffer.from( |
60 | 60 | `${clientId}:${clientSecret}` |
61 | 61 | ).toString('base64')}` |
62 | | - }, |
63 | | - json: true |
| 62 | + } |
64 | 63 | }; |
65 | 64 | try { |
66 | | - const res = await rp(options); |
67 | | - res.forEach((metadata) => { |
| 65 | + const { data } = await axios.request(options); |
| 66 | + data.forEach((metadata) => { |
68 | 67 | let category = ''; |
69 | 68 | for (let j = 1; j < metadata.name.split('_').length; j += 1) { |
70 | 69 | category += `${metadata.name.split('_')[j]} `; |
@@ -92,9 +91,9 @@ function getSketchesInCategories(categories) { |
92 | 91 | json: true |
93 | 92 | }; |
94 | 93 | try { |
95 | | - const res = await rp(options); |
| 94 | + const { data } = await axios.request(options); |
96 | 95 | const projectsInOneCategory = []; |
97 | | - res.forEach((example) => { |
| 96 | + data.forEach((example) => { |
98 | 97 | let projectName; |
99 | 98 | if (example.name === '02_Instance_Container.js') { |
100 | 99 | for (let i = 1; i < 5; i += 1) { |
@@ -147,23 +146,23 @@ function getSketchContent(projectsInAllCategories) { |
147 | 146 | } |
148 | 147 | }; |
149 | 148 | try { |
150 | | - const res = await rp(options); |
| 149 | + const { data } = await axios.request(options); |
151 | 150 | const noNumberprojectName = project.projectName.replace( |
152 | 151 | /(\d+)/g, |
153 | 152 | '' |
154 | 153 | ); |
155 | 154 | if (noNumberprojectName === 'Instance Mode: Instance Container ') { |
156 | 155 | for (let i = 0; i < 4; i += 1) { |
157 | 156 | const splitedRes = `${ |
158 | | - res.split('*/')[1].split('</html>')[i] |
| 157 | + data.split('*/')[1].split('</html>')[i] |
159 | 158 | }</html>\n`; |
160 | 159 | project.sketchContent = splitedRes.replace( |
161 | 160 | 'p5.js', |
162 | 161 | 'https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.js' |
163 | 162 | ); |
164 | 163 | } |
165 | 164 | } else { |
166 | | - project.sketchContent = res; |
| 165 | + project.sketchContent = data; |
167 | 166 | } |
168 | 167 | return project; |
169 | 168 | } catch (error) { |
@@ -217,15 +216,14 @@ async function addAssetsToProject(assets, response, project) { |
217 | 216 | Authorization: `Basic ${Buffer.from( |
218 | 217 | `${clientId}:${clientSecret}` |
219 | 218 | ).toString('base64')}` |
220 | | - }, |
221 | | - json: true |
| 219 | + } |
222 | 220 | }; |
223 | 221 |
|
224 | 222 | // a function to await for the response that contains the content of asset file |
225 | 223 | const doRequest = async (optionsAsset) => { |
226 | 224 | try { |
227 | | - const res = await rp(optionsAsset); |
228 | | - return res; |
| 225 | + const { data } = await axios.request(optionsAsset); |
| 226 | + return data; |
229 | 227 | } catch (error) { |
230 | 228 | throw error; |
231 | 229 | } |
@@ -273,12 +271,11 @@ async function createProjectsInP5user(projectsInAllCategories) { |
273 | 271 | Authorization: `Basic ${Buffer.from( |
274 | 272 | `${clientId}:${clientSecret}` |
275 | 273 | ).toString('base64')}` |
276 | | - }, |
277 | | - json: true |
| 274 | + } |
278 | 275 | }; |
279 | 276 |
|
280 | 277 | try { |
281 | | - const res = await rp(options); |
| 278 | + const { data } = await axios.request(options); |
282 | 279 | const user = await User.findOne({ username: 'p5' }).exec(); |
283 | 280 | await Q.all( |
284 | 281 | projectsInAllCategories.map((projectsInOneCategory) => |
@@ -382,7 +379,7 @@ async function createProjectsInP5user(projectsInAllCategories) { |
382 | 379 | []; |
383 | 380 |
|
384 | 381 | try { |
385 | | - await addAssetsToProject(assetsInProject, res, newProject); |
| 382 | + await addAssetsToProject(assetsInProject, data, newProject); |
386 | 383 | const savedProject = await newProject.save(); |
387 | 384 | console.log( |
388 | 385 | `Created a new project in p5 user: ${savedProject.name}` |
|
0 commit comments