Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: REST API to serve posts from mobile apps or others
- Loading branch information
1 parent
7576965
commit 9f3725d
Showing
19 changed files
with
223 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import post from './post' | ||
import posts from './posts' | ||
|
||
export { | ||
post, | ||
posts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import path from 'path' | ||
import xss from 'xss' | ||
|
||
import { | ||
cmsData, | ||
coreUtils, | ||
abeExtend | ||
} from '../../../cli' | ||
|
||
/** | ||
* This route returns the editor page as HTML | ||
* @param {[type]} req [description] | ||
* @param {[type]} res [description] | ||
* @param {Function} next [description] | ||
* @return {[type]} [description] | ||
*/ | ||
var route = function(req, res, next) { | ||
console.log('Bonne route') | ||
abeExtend.hooks.instance.trigger('beforeRoute', req, res, next) | ||
if(typeof res._header !== 'undefined' && res._header !== null) return | ||
|
||
var filePath = req.originalUrl.replace('/abe/rest/post', '') | ||
|
||
console.log(filePath) | ||
if(filePath !== '' && filePath !== '/' && filePath != null) { | ||
var filePathTest = cmsData.revision.getDocumentRevision(filePath) | ||
if(typeof filePathTest !== 'undefined' && filePathTest !== null) { | ||
var jsonPath = filePathTest.path | ||
console.log(jsonPath) | ||
if(coreUtils.file.exist(jsonPath)) { | ||
var json = cmsData.file.get(jsonPath, 'utf8') | ||
res.set('Content-Type', 'application/json') | ||
res.send(JSON.stringify(json)) | ||
} | ||
} | ||
} | ||
|
||
// Error | ||
|
||
} | ||
|
||
export default route |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
config, | ||
abeExtend, | ||
Manager | ||
} from '../../../cli' | ||
|
||
/** | ||
* This route returns filtered list of posts in JSON format | ||
* @param {[type]} req [description] | ||
* @param {[type]} res [description] | ||
* @param {Function} next [description] | ||
* @return {[type]} [description] | ||
*/ | ||
var route = function(req, res, next){ | ||
var start = 0 | ||
var length = 25 | ||
var sortField = 'date' | ||
var sortOrder = -1 | ||
var search = '' | ||
|
||
var values = ['date', 'abe_meta.link', 'abe_meta.template', 'date'] | ||
Array.prototype.forEach.call(config.users.workflow, (flow) => { | ||
values[i] = 'abe_meta.' + flow | ||
++i | ||
}) | ||
|
||
abeExtend.hooks.instance.trigger('beforeRoute', req, res, next) | ||
if(typeof res._header !== 'undefined' && res._header !== null) return | ||
|
||
if (typeof req.query.start !== 'undefined') { | ||
start = +req.query.start | ||
} | ||
|
||
if (typeof req.query.length !== 'undefined') { | ||
length = +req.query.length | ||
} | ||
|
||
var i = 4 | ||
if (typeof req.query.order !== 'undefined') { | ||
sortField = values[req.query.order[0]['column']] | ||
sortOrder = (req.query.order[0]['dir'] === 'desc')? -1:1 | ||
} | ||
|
||
if (typeof req.query.search !== 'undefined' && req.query.search.value !== '') { | ||
search = req.query.search.value | ||
} | ||
|
||
var list = Manager.instance.getPage(start, length, sortField, sortOrder, search) | ||
|
||
if (typeof req.query.draw !== 'undefined') { | ||
list['draw'] = req.query.draw | ||
} | ||
|
||
res.set('Content-Type', 'application/json') | ||
res.send(JSON.stringify(list)) | ||
} | ||
|
||
export default route |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters