Skip to content

Commit

Permalink
For #3 we now support API REST for article, author, case-study, video…
Browse files Browse the repository at this point in the history
…, ready for initial version
  • Loading branch information
victorkane committed Sep 7, 2018
1 parent 7f9bca5 commit e623f93
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cms/content/videos/greta-the-gymnast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
metaData:
itemSlug: greta-the-gymnast
itemName: Greta the Gymnast
itemType: video
language: en-US
published: true
publishedDate: '2015-08-28T00:00:00.000Z'
createdDate: '2015-08-28T18:40:54.816Z'
modifiedDate: '2015-08-28T00:00:00.000Z'
articleTitle: The Content Migration Rescue Process
articleSubTitle: null
author: Victor Kane
videoMedia:
mediaLink:
linkAttributes:
- attrName: title
attrValue: Greta the Gymnast
linkUrl: https://www.youtube.com/embed/AxOvzCaFVZ4
linkFilePath: AxOvzCaFVZ4
mediaCaption: Greta the Gymnast
mediaType: video
videoDescription:
value: |
## Greta shows her stuff

Greta shows great dexterity, speed and agility in roof climbing around the neighborhood.
videoSummary:
value: null
tags:
- tagSlug: cat-migration-rescue
tagName: Cat Migration Rescue
28 changes: 28 additions & 0 deletions cms/upsert/upsert.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require('dotenv').config()
// const util = require('util')

const apiHost = 'http://' + process.env.API_HOST + ':' + process.env.API_PORT
let contentType = null;

if (process.argv.length > 3) {
contentType = process.argv[2]
Expand Down Expand Up @@ -46,6 +47,31 @@ async function processArticles(contentItem) {
return res
}

async function processVideos(contentItem) {
// get author _id for query population TODO authors, make sure we have one at least
const optionsGet = {
method: 'GET',
uri: apiHost + '/api/authors?itemName=' + contentItem.author + '&select=_id',
json: true
}
const authors = await rp(optionsGet)
if (authors.length > 0) {
contentItem.author = authors[0]._id
} else {
return console.log("no author specified\n")
}
// upsert video
const optionsPut = {
method: 'PUT',
uri: apiHost + '/api/' + contentType,
body: contentItem,
json: true
}
const res = await rp(optionsPut)
console.log("res", res.message)
return res
}

async function processBooks(contentItem) {
// get author _id for query population TODO authors and/or editors, make sure we have one at least one of either
const optionsGetAuthor = {
Expand Down Expand Up @@ -134,6 +160,8 @@ fs.readFile(file, 'utf8', function (err,content) {
let result = 0
if (contentType === 'articles') {
result = processArticles(contentItem)
} else if (contentType === 'videos') {
result = processVideos(contentItem)
} else if (contentType === 'books') {
result = processBooks(contentItem)
} else if (contentType === 'case-studies') {
Expand Down

0 comments on commit e623f93

Please sign in to comment.