mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-06 20:05:40 +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
|
# will run `npm install` automatically
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- npm test
|
- npm test
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- node_modules
|
- node_modules
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"webtask-tools": "^3.4.0"
|
"webtask-tools": "^3.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^6.2.0",
|
"eslint": "^6.2.1",
|
||||||
"eslint-config-oceanprotocol": "^1.4.0"
|
"eslint-config-oceanprotocol": "^1.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,11 @@ server.use(cors(corsOptions))
|
|||||||
const baseUrl = 'https://us16.api.mailchimp.com/3.0'
|
const baseUrl = 'https://us16.api.mailchimp.com/3.0'
|
||||||
const listId = '3c6eed8b71'
|
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) => {
|
server.post('/newsletter/:email', (req, res) => {
|
||||||
const { email } = req.params
|
const { email } = req.params
|
||||||
@ -51,27 +55,31 @@ server.post('/newsletter/:email', (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const optionsMarketing = marketingPermissionId => (
|
const optionsMarketing = marketingPermissionId => ({
|
||||||
{
|
...baseOptions,
|
||||||
...baseOptions,
|
json: {
|
||||||
json: {
|
marketing_permissions: [
|
||||||
marketing_permissions: [{
|
{
|
||||||
marketing_permission_id: marketingPermissionId,
|
marketing_permission_id: marketingPermissionId,
|
||||||
text: 'Email',
|
text: 'Email',
|
||||||
enabled: true
|
enabled: true
|
||||||
}]
|
}
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
|
|
||||||
const addMarketingPermissions = (data, cb) => {
|
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) => {
|
request.patch(
|
||||||
if (error) res.send(error)
|
optionsMarketing(marketingPermissionId),
|
||||||
|
(error, response, body) => {
|
||||||
|
if (error) res.send(error)
|
||||||
|
|
||||||
return cb(body)
|
return cb(body)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user exists first
|
// Check if user exists first
|
||||||
|
@ -27,8 +27,12 @@ app.get('/:username', (req, res) => {
|
|||||||
holder.readingTime = posts[i].virtuals.readingTime
|
holder.readingTime = posts[i].virtuals.readingTime
|
||||||
holder.title = posts[i].title
|
holder.title = posts[i].title
|
||||||
holder.subtitle = posts[i].virtuals.subtitle
|
holder.subtitle = posts[i].virtuals.subtitle
|
||||||
holder.imageUrl = `https://cdn-images-1.medium.com/max/600/${posts[i].virtuals.previewImage.imageId}`
|
holder.imageUrl = `https://cdn-images-1.medium.com/max/600/${
|
||||||
holder.postUrl = `https://medium.com/${req.params.username}/${posts[i].id}`
|
posts[i].virtuals.previewImage.imageId
|
||||||
|
}`
|
||||||
|
holder.postUrl = `https://medium.com/${req.params.username}/${
|
||||||
|
posts[i].id
|
||||||
|
}`
|
||||||
parsedPosts.push(holder)
|
parsedPosts.push(holder)
|
||||||
holder = {}
|
holder = {}
|
||||||
}
|
}
|
||||||
|
@ -30,20 +30,24 @@ server.get('/', (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
request.get(options, (error, response, body) => {
|
request.get(options, (error, response, body) => {
|
||||||
if (error || response.statusCode !== 200) res.send(error)
|
|
||||||
|
|
||||||
const data = JSON.parse(body)
|
const data = JSON.parse(body)
|
||||||
let members = []
|
let members = []
|
||||||
|
|
||||||
for (const item of data) {
|
if (error) res.send(error)
|
||||||
members.push(item.member_count)
|
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 })
|
res.send({ groups: data, members })
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.error(error)
|
||||||
res.send(error)
|
res.send(error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -24,25 +24,33 @@ const makeRequest = (options, cb) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
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) => {
|
app.get('/channel/:channelId', (req, res) => {
|
||||||
const options = {
|
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 }
|
headers: { referer: req.headers.host }
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedPosts = []
|
const parsedPosts = []
|
||||||
let holder = {}
|
let holder = {}
|
||||||
|
|
||||||
makeRequest(options, (videos) => {
|
makeRequest(options, videos => {
|
||||||
for (let i = 0; i < videos.length; i++) {
|
for (let i = 0; i < videos.length; i++) {
|
||||||
holder.id = videos[i].id.videoId
|
holder.id = videos[i].id.videoId
|
||||||
holder.title = videos[i].snippet.title
|
holder.title = videos[i].snippet.title
|
||||||
holder.description = videos[i].snippet.description
|
holder.description = videos[i].snippet.description
|
||||||
holder.imageUrl = videos[i].snippet.thumbnails.medium.url
|
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)
|
parsedPosts.push(holder)
|
||||||
holder = {}
|
holder = {}
|
||||||
}
|
}
|
||||||
@ -53,31 +61,39 @@ app.get('/channel/:channelId', (req, res) => {
|
|||||||
|
|
||||||
app.get('/channel/:channelId/raw', (req, res) => {
|
app.get('/channel/:channelId/raw', (req, res) => {
|
||||||
const options = {
|
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 }
|
headers: { referer: req.headers.host }
|
||||||
}
|
}
|
||||||
|
|
||||||
makeRequest(options, (videos) => {
|
makeRequest(options, videos => {
|
||||||
res.send(videos)
|
res.send(videos)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/playlist/:playlistId', (req, res) => {
|
app.get('/playlist/:playlistId', (req, res) => {
|
||||||
const options = {
|
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 }
|
headers: { referer: req.headers.host }
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedPosts = []
|
const parsedPosts = []
|
||||||
let holder = {}
|
let holder = {}
|
||||||
|
|
||||||
makeRequest(options, (videos) => {
|
makeRequest(options, videos => {
|
||||||
for (let i = 0; i < videos.length; i++) {
|
for (let i = 0; i < videos.length; i++) {
|
||||||
holder.id = videos[i].snippet.resourceId.videoId
|
holder.id = videos[i].snippet.resourceId.videoId
|
||||||
holder.title = videos[i].snippet.title
|
holder.title = videos[i].snippet.title
|
||||||
holder.description = videos[i].snippet.description
|
holder.description = videos[i].snippet.description
|
||||||
holder.imageUrl = videos[i].snippet.thumbnails.medium.url
|
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)
|
parsedPosts.push(holder)
|
||||||
holder = {}
|
holder = {}
|
||||||
}
|
}
|
||||||
@ -88,11 +104,13 @@ app.get('/playlist/:playlistId', (req, res) => {
|
|||||||
|
|
||||||
app.get('/playlist/:playlistId/raw', (req, res) => {
|
app.get('/playlist/:playlistId/raw', (req, res) => {
|
||||||
const options = {
|
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 }
|
headers: { referer: req.headers.host }
|
||||||
}
|
}
|
||||||
|
|
||||||
makeRequest(options, (videos) => {
|
makeRequest(options, videos => {
|
||||||
res.send(videos)
|
res.send(videos)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user