Code Duplication    Length = 57-68 lines in 2 locations

src/cli/cms/operations/post.js 2 locations

@@ 12-79 (lines=68) @@
9
  Manager
10
} from '../../'
11
12
export function publish(filePath, tplPath, json) {
13
  var p = new Promise((resolve, reject) => {
14
    abeExtend.hooks.instance.trigger('beforePublish', json, filePath, tplPath)
15
    var p1 = new Promise((resolve) => {
16
      cmsOperations.save.save(
17
        path.join(config.root, config.draft.url, filePath.replace(config.root)),
18
        tplPath,
19
        json,
20
        '',
21
        'draft',
22
        null,
23
        'publish')
24
        .then(() => {
25
          resolve()
26
        }).catch(function(e) {
27
          console.error(e)
28
        })
29
    })
30
31
    p1.then((resSave) => {
32
      cmsOperations.save.save(
33
        path.join(config.root, config.draft.url, filePath.replace(config.root)),
34
        tplPath,
35
        json,
36
        '',
37
        'publish',
38
        resSave,
39
        'publish')
40
        .then((resSave) => {
41
          var result
42
          if(typeof resSave.error !== 'undefined' && resSave.error !== null  ){
43
            result = {
44
              success: 0,
45
              error: resSave.error
46
            }
47
          } else if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){
48
            result = resSave
49
          } else if(typeof resSave.json !== 'undefined' && resSave.json !== null){
50
            result = {
51
              success: 1,
52
              json: resSave.json
53
            }
54
          }
55
          abeExtend.hooks.instance.trigger('afterPublish', result)
56
          Manager.instance.updateList()
57
          resolve(result)
58
        }).catch(function(e) {
59
          console.error('post.js', e)
60
          var result = {
61
            success: 0,
62
            error: 'publish error'
63
          }
64
          abeExtend.hooks.instance.trigger('afterPublish', result)
65
          resolve(result)
66
        })
67
    }).catch(function(e) {
68
      console.error('post.js', e)
69
      var result = {
70
        success: 0,
71
        error: 'publish error'
72
      }
73
      abeExtend.hooks.instance.trigger('afterPublish', result)
74
      resolve(result)
75
    })
76
  })
77
78
  return p
79
}
80
81
export function unpublish(filePath) {
82
  abeExtend.hooks.instance.trigger('beforeUnpublish', filePath)
@@ 108-164 (lines=57) @@
105
  }
106
}
107
108
export function reject(filePath, tplPath, json) {
109
  abeExtend.hooks.instance.trigger('beforeReject', filePath)
110
  
111
  var p = new Promise((resolve) => {
112
    cmsOperations.save.save(
113
      path.join(config.root, config.draft.url, filePath.replace(config.root)),
114
      tplPath,
115
      json,
116
      '',
117
      'draft',
118
      null,
119
      'reject')
120
      .then(() => {
121
        resolve()
122
      }).catch(function(e) {
123
        console.error(e)
124
      })
125
  })
126
127
  p.then((resSave) => {
128
    cmsOperations.save.save(
129
      path.join(config.root, config.draft.url, filePath.replace(config.root)),
130
      tplPath,
131
      json,
132
      '',
133
      'reject',
134
      resSave,
135
      'reject')
136
      .then((resSave) => {
137
        var result
138
        if(typeof resSave.error !== 'undefined' && resSave.error !== null  ){
139
          result = {
140
            success: 0,
141
            error: resSave.error
142
          }
143
        } else if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){
144
          result = resSave
145
        } else if(typeof resSave.json !== 'undefined' && resSave.json !== null){
146
          result = {
147
            success: 1,
148
            json: resSave.json
149
          }
150
        }
151
        abeExtend.hooks.instance.trigger('afterReject', result)
152
        Manager.instance.updateList()
153
        resolve(result)
154
      })
155
  }).catch(function(e) {
156
    console.error(e)
157
    var result = {
158
      success: 0,
159
      error: 'reject error'
160
    }
161
    abeExtend.hooks.instance.trigger('afterReject', result)
162
    resolve(result)
163
  }) 
164
}