|
1
|
|
|
import path from 'path' |
|
2
|
|
|
|
|
3
|
|
|
import { |
|
4
|
|
|
cmsData, |
|
5
|
|
|
cmsOperations, |
|
6
|
|
|
coreUtils, |
|
7
|
|
|
config, |
|
8
|
|
|
abeExtend, |
|
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-publish.js', e) |
|
60
|
|
|
var result = { |
|
61
|
|
|
success: 0, |
|
62
|
|
|
error: 'post-publish error' |
|
63
|
|
|
} |
|
64
|
|
|
abeExtend.hooks.instance.trigger('afterPublish', result) |
|
65
|
|
|
resolve(result) |
|
66
|
|
|
}) |
|
67
|
|
|
}).catch(function(e) { |
|
68
|
|
|
console.error('post-publish.js', e) |
|
69
|
|
|
var result = { |
|
70
|
|
|
success: 0, |
|
71
|
|
|
error: 'post-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) |
|
83
|
|
|
filePath = coreUtils.slug.clean(filePath) |
|
84
|
|
|
var tplUrl = cmsData.file.fromUrl(path.join(config.publish.url, filePath)) |
|
85
|
|
|
if(coreUtils.file.exist(tplUrl.json.path)) { |
|
86
|
|
|
var json = JSON.parse(JSON.stringify(cmsData.file.get(tplUrl.json.path))) |
|
87
|
|
|
if(json.abe_meta.publish != null) { |
|
88
|
|
|
delete json.abe_meta.publish |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
cmsOperations.save.save( |
|
92
|
|
|
path.join(config.root, config.draft.url, json.abe_meta.link.replace(config.root)), |
|
93
|
|
|
json.abe_meta.template, |
|
94
|
|
|
json, |
|
95
|
|
|
'', |
|
96
|
|
|
'reject', |
|
97
|
|
|
null, |
|
98
|
|
|
'reject' |
|
99
|
|
|
) |
|
100
|
|
|
.then(() => { |
|
101
|
|
|
cmsOperations.remove.removeFile(tplUrl.publish.path, tplUrl.publish.json) |
|
102
|
|
|
abeExtend.hooks.instance.trigger('afterUnpublish', tplUrl.publish.path, tplUrl.publish.json) |
|
103
|
|
|
Manager.instance.updateList() |
|
104
|
|
|
}) |
|
105
|
|
|
} |
|
106
|
|
|
} |