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