Clean explicit json parse (#584)
This commit is contained in:
parent
3acefe4709
commit
51f39c003e
2 changed files with 21 additions and 22 deletions
|
@ -115,13 +115,12 @@ function getCodePackage() {
|
|||
client_secret: clientSecret
|
||||
},
|
||||
method: 'GET',
|
||||
headers
|
||||
headers,
|
||||
json: true
|
||||
};
|
||||
|
||||
return rp(options).then((res) => {
|
||||
const json = JSON.parse(res);
|
||||
|
||||
json.forEach((metadata) => {
|
||||
res.forEach((metadata) => {
|
||||
if (metadata.name.endsWith('P') === true || metadata.name.endsWith('M') === true) {
|
||||
sketchRootList.push(metadata);
|
||||
}
|
||||
|
@ -146,11 +145,12 @@ function getSketchDirectories(sketchRootList) {
|
|||
client_secret: clientSecret
|
||||
},
|
||||
method: 'GET',
|
||||
headers
|
||||
headers,
|
||||
json: true
|
||||
};
|
||||
|
||||
return rp(options).then((res) => {
|
||||
const sketchDirs = flatten(JSON.parse(res));
|
||||
const sketchDirs = flatten(res);
|
||||
|
||||
return sketchDirs;
|
||||
}).catch((err) => {
|
||||
|
@ -182,12 +182,12 @@ function appendSketchItemLinks(sketchList) {
|
|||
client_secret: clientSecret
|
||||
},
|
||||
method: 'GET',
|
||||
headers
|
||||
headers,
|
||||
json: true
|
||||
};
|
||||
|
||||
return rp(options).then((res) => {
|
||||
const sketchItems = JSON.parse(res);
|
||||
sketches.tree = sketchItems;
|
||||
sketches.tree = res;
|
||||
|
||||
return sketchList;
|
||||
});
|
||||
|
@ -208,11 +208,12 @@ function getSketchItems(sketchList) {
|
|||
client_secret: clientSecret
|
||||
},
|
||||
method: 'GET',
|
||||
headers
|
||||
headers,
|
||||
json: true
|
||||
};
|
||||
|
||||
return rp(options).then((res) => {
|
||||
sketch.data = JSON.parse(res);
|
||||
sketch.data = res;
|
||||
return sketch;
|
||||
}).catch((err) => {
|
||||
throw err;
|
||||
|
|
|
@ -47,12 +47,11 @@ function getCategories() {
|
|||
url: `https://api.github.com/repos/processing/p5.js-website/contents/dist/assets/examples/en?client_id=${
|
||||
clientId}&client_secret=${clientSecret}`,
|
||||
method: 'GET',
|
||||
headers
|
||||
headers,
|
||||
json: true
|
||||
};
|
||||
return rp(options).then((res) => {
|
||||
const json = JSON.parse(res);
|
||||
|
||||
json.forEach((metadata) => {
|
||||
res.forEach((metadata) => {
|
||||
let category = '';
|
||||
for (let j = 1; j < metadata.name.split('_').length; j += 1) {
|
||||
category += `${metadata.name.split('_')[j]} `;
|
||||
|
@ -71,13 +70,13 @@ function getSketchesInCategories(categories) {
|
|||
const options = {
|
||||
url: `${category.url.replace('?ref=master', '')}?client_id=${clientId}&client_secret=${clientSecret}`,
|
||||
method: 'GET',
|
||||
headers
|
||||
headers,
|
||||
json: true
|
||||
};
|
||||
|
||||
return rp(options).then((res) => {
|
||||
const projectsInOneCategory = [];
|
||||
const examples = JSON.parse(res);
|
||||
examples.forEach((example) => {
|
||||
res.forEach((example) => {
|
||||
let projectName;
|
||||
if (example.name === '02_Instance_Container.js') {
|
||||
for (let i = 1; i < 5; i += 1) {
|
||||
|
@ -131,12 +130,11 @@ function createProjectsInP5user(projectsInAllCategories) {
|
|||
url: `https://api.github.com/repos/processing/p5.js-website/contents/dist/assets/examples/assets?client_id=${
|
||||
clientId}&client_secret=${clientSecret}`,
|
||||
method: 'GET',
|
||||
headers
|
||||
headers,
|
||||
json: true
|
||||
};
|
||||
|
||||
rp(options).then((res) => {
|
||||
const assets = JSON.parse(res);
|
||||
|
||||
User.findOne({ username: 'p5' }, (err, user) => {
|
||||
if (err) throw err;
|
||||
|
||||
|
@ -236,7 +234,7 @@ function createProjectsInP5user(projectsInAllCategories) {
|
|||
assetsInProject.forEach((assetNamePath, i) => {
|
||||
let assetName = assetNamePath.split('assets/')[1];
|
||||
|
||||
assets.forEach((asset) => {
|
||||
res.forEach((asset) => {
|
||||
if (asset.name === assetName || asset.name.split('.')[0] === assetName) {
|
||||
assetName = asset.name;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue