mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-04 19:05:17 +01:00
updates
This commit is contained in:
parent
0f5d0ce752
commit
6a8232fbfc
5
.prettierrc
Normal file
5
.prettierrc
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none"
|
||||
}
|
@ -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
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 = {}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user