Code Duplication    Length = 45-45 lines in 2 locations

src/server/routes/operations/post/edit.js 1 location

@@ 1-45 (lines=45) @@
1
import {
2
  cmsOperations,
3
  abeExtend
4
} from '../../../../cli'
5
6
var route = function(req, res, next){
7
  abeExtend.hooks.instance.trigger('beforeRoute', req, res, next)
8
  if(typeof res._header !== 'undefined' && res._header !== null) return
9
10
  let regUrl = /\/abe\/save\/(.*?)\/edit\//
11
  var workflow = 'draft'
12
  var match = req.originalUrl.match(regUrl)
13
  if (match != null && match[1] != null) {
14
    workflow = match[1]
15
  }
16
  var postUrl = req.originalUrl.replace(regUrl, '')
17
  var json = req.body.json
18
  
19
  var p
20
  if (workflow === 'publish') {
21
    p = cmsOperations.post.publish(
22
      postUrl, 
23
      json
24
    )
25
  }else {
26
    p = cmsOperations.post.draft(
27
      postUrl, 
28
      json, 
29
      workflow
30
    )
31
  }
32
33
  p.then((result) => {
34
    res.set('Content-Type', 'application/json')
35
    res.send(JSON.stringify(result))
36
  },
37
  (result) => {
38
    res.set('Content-Type', 'application/json')
39
    res.send(JSON.stringify(result))
40
  }).catch(function(e) {
41
    console.error('[ERROR] post-reject.js', e)
42
  })
43
}
44
45
export default route

src/server/routes/operations/post/submit.js 1 location

@@ 1-45 (lines=45) @@
1
import {
2
  cmsOperations,
3
  abeExtend
4
} from '../../../../cli'
5
6
var route = function(req, res, next){
7
  abeExtend.hooks.instance.trigger('beforeRoute', req, res, next)
8
  if(typeof res._header !== 'undefined' && res._header !== null) return
9
10
  let regUrl = /\/abe\/save\/(.*?)\/submit\//
11
  var workflow = 'draft'
12
  var match = req.originalUrl.match(regUrl)
13
  if (match != null && match[1] != null) {
14
    workflow = match[1]
15
  }
16
  var postUrl = req.originalUrl.replace(regUrl, '')
17
  var json = req.body.json
18
  
19
  var p
20
  if (workflow === 'publish') {
21
    p = cmsOperations.post.publish(
22
      postUrl, 
23
      json
24
    )
25
  }else {
26
    p = cmsOperations.post.draft(
27
      postUrl, 
28
      json, 
29
      workflow
30
    )
31
  }
32
33
  p.then((result) => {
34
    res.set('Content-Type', 'application/json')
35
    res.send(JSON.stringify(result))
36
  },
37
  (result) => {
38
    res.set('Content-Type', 'application/json')
39
    res.send(JSON.stringify(result))
40
  }).catch(function(e) {
41
    console.error('[ERROR] post-save.js', e)
42
  })
43
}
44
45
export default route