diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..910ce78 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "semi": false, + "singleQuote": true, + "trailingComma": "none" +} diff --git a/.travis.yml b/.travis.yml index 69521fc..d2ffd71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,11 +4,11 @@ node_js: node # will run `npm install` automatically script: - - npm test + - npm test notifications: email: false cache: - directories: - - node_modules + directories: + - node_modules diff --git a/package.json b/package.json index 6994826..03bc392 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "webtask-tools": "^3.4.0" }, "devDependencies": { - "eslint": "^6.2.0", - "eslint-config-oceanprotocol": "^1.4.0" + "eslint": "^6.2.1", + "eslint-config-oceanprotocol": "^1.5.0" } } diff --git a/webtask-mailchimp.js b/webtask-mailchimp.js index 9dadd49..42564f8 100644 --- a/webtask-mailchimp.js +++ b/webtask-mailchimp.js @@ -23,7 +23,11 @@ server.use(cors(corsOptions)) const baseUrl = 'https://us16.api.mailchimp.com/3.0' const listId = '3c6eed8b71' -const md5 = data => crypto.createHash('md5').update(data).digest('hex') +const md5 = data => + crypto + .createHash('md5') + .update(data) + .digest('hex') server.post('/newsletter/:email', (req, res) => { const { email } = req.params @@ -51,27 +55,31 @@ server.post('/newsletter/:email', (req, res) => { } } - const optionsMarketing = marketingPermissionId => ( - { - ...baseOptions, - json: { - marketing_permissions: [{ + const optionsMarketing = marketingPermissionId => ({ + ...baseOptions, + json: { + marketing_permissions: [ + { marketing_permission_id: marketingPermissionId, text: 'Email', enabled: true - }] - } + } + ] } - ) + }) const addMarketingPermissions = (data, cb) => { - const marketingPermissionId = data.marketing_permissions[0].marketing_permission_id + const marketingPermissionId = + data.marketing_permissions[0].marketing_permission_id - request.patch(optionsMarketing(marketingPermissionId), (error, response, body) => { - if (error) res.send(error) + request.patch( + optionsMarketing(marketingPermissionId), + (error, response, body) => { + if (error) res.send(error) - return cb(body) - }) + return cb(body) + } + ) } // Check if user exists first diff --git a/webtask-medium.js b/webtask-medium.js index 49dfe15..0fd5341 100644 --- a/webtask-medium.js +++ b/webtask-medium.js @@ -27,8 +27,12 @@ app.get('/:username', (req, res) => { holder.readingTime = posts[i].virtuals.readingTime holder.title = posts[i].title holder.subtitle = posts[i].virtuals.subtitle - holder.imageUrl = `https://cdn-images-1.medium.com/max/600/${posts[i].virtuals.previewImage.imageId}` - holder.postUrl = `https://medium.com/${req.params.username}/${posts[i].id}` + holder.imageUrl = `https://cdn-images-1.medium.com/max/600/${ + posts[i].virtuals.previewImage.imageId + }` + holder.postUrl = `https://medium.com/${req.params.username}/${ + posts[i].id + }` parsedPosts.push(holder) holder = {} } diff --git a/webtask-meetup.js b/webtask-meetup.js index 045120b..7f81933 100644 --- a/webtask-meetup.js +++ b/webtask-meetup.js @@ -30,20 +30,24 @@ server.get('/', (req, res) => { try { request.get(options, (error, response, body) => { - if (error || response.statusCode !== 200) res.send(error) - const data = JSON.parse(body) let members = [] - for (const item of data) { - members.push(item.member_count) + if (error) res.send(error) + if (response.statusCode !== 200) res.send(body) + + if (Array.isArray(data)) { + for (const item of data) { + members.push(item.member_count) + } + + members = members.reduce((a, b) => a + b, 0) } - members = members.reduce((a, b) => a + b, 0) res.send({ groups: data, members }) }) } catch (error) { - console.log(error) + console.error(error) res.send(error) } }) diff --git a/webtask-youtube.js b/webtask-youtube.js index 5fc2cbd..526de5b 100644 --- a/webtask-youtube.js +++ b/webtask-youtube.js @@ -24,25 +24,33 @@ const makeRequest = (options, cb) => { } app.get('/', (req, res) => { - res.send('Please use /channel or /playlist endpoints, appended with the channel or playlist ID as parameter.') + res.send( + 'Please use /channel or /playlist endpoints, appended with the channel or playlist ID as parameter.' + ) }) app.get('/channel/:channelId', (req, res) => { const options = { - url: `https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${req.params.channelId}&maxResults=10&order=date&type=video&key=${req.webtaskContext.secrets.YOUTUBE_API_KEY}`, + url: `https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${ + req.params.channelId + }&maxResults=10&order=date&type=video&key=${ + req.webtaskContext.secrets.YOUTUBE_API_KEY + }`, headers: { referer: req.headers.host } } const parsedPosts = [] let holder = {} - makeRequest(options, (videos) => { + makeRequest(options, videos => { for (let i = 0; i < videos.length; i++) { holder.id = videos[i].id.videoId holder.title = videos[i].snippet.title holder.description = videos[i].snippet.description holder.imageUrl = videos[i].snippet.thumbnails.medium.url - holder.videoUrl = `https://www.youtube.com/watch?v=${videos[i].id.videoId}` + holder.videoUrl = `https://www.youtube.com/watch?v=${ + videos[i].id.videoId + }` parsedPosts.push(holder) holder = {} } @@ -53,31 +61,39 @@ app.get('/channel/:channelId', (req, res) => { app.get('/channel/:channelId/raw', (req, res) => { const options = { - url: `https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${req.params.channelId}&maxResults=10&order=date&type=video&key=${req.webtaskContext.secrets.YOUTUBE_API_KEY}`, + url: `https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${ + req.params.channelId + }&maxResults=10&order=date&type=video&key=${ + req.webtaskContext.secrets.YOUTUBE_API_KEY + }`, headers: { referer: req.headers.host } } - makeRequest(options, (videos) => { + makeRequest(options, videos => { res.send(videos) }) }) app.get('/playlist/:playlistId', (req, res) => { const options = { - url: `https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=10&playlistId=${req.params.playlistId}&key=${req.webtaskContext.secrets.YOUTUBE_API_KEY}`, + url: `https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=10&playlistId=${ + req.params.playlistId + }&key=${req.webtaskContext.secrets.YOUTUBE_API_KEY}`, headers: { referer: req.headers.host } } const parsedPosts = [] let holder = {} - makeRequest(options, (videos) => { + makeRequest(options, videos => { for (let i = 0; i < videos.length; i++) { holder.id = videos[i].snippet.resourceId.videoId holder.title = videos[i].snippet.title holder.description = videos[i].snippet.description holder.imageUrl = videos[i].snippet.thumbnails.medium.url - holder.videoUrl = `https://www.youtube.com/watch?v=${videos[i].snippet.resourceId.videoId}` + holder.videoUrl = `https://www.youtube.com/watch?v=${ + videos[i].snippet.resourceId.videoId + }` parsedPosts.push(holder) holder = {} } @@ -88,11 +104,13 @@ app.get('/playlist/:playlistId', (req, res) => { app.get('/playlist/:playlistId/raw', (req, res) => { const options = { - url: `https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=10&playlistId=${req.params.playlistId}&key=${req.webtaskContext.secrets.YOUTUBE_API_KEY}`, + url: `https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=10&playlistId=${ + req.params.playlistId + }&key=${req.webtaskContext.secrets.YOUTUBE_API_KEY}`, headers: { referer: req.headers.host } } - makeRequest(options, (videos) => { + makeRequest(options, videos => { res.send(videos) }) })