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