backend-manager 3.2.63 → 3.2.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -21,16 +21,23 @@ Module.prototype.main = function () {
|
|
|
21
21
|
return reject(assistant.errorify(`Admin required.`, {code: 401}));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// Get repo info
|
|
24
25
|
const repoInfo = assistant.parseRepo(get(self.Manager.config, 'github.repo_website'));
|
|
25
|
-
|
|
26
26
|
const poster = new Poster();
|
|
27
27
|
|
|
28
|
+
assistant.log(`main(): Creating post...`, repoInfo);
|
|
29
|
+
|
|
28
30
|
// Save to disk OR commit
|
|
29
31
|
poster.onDownload = function (meta) {
|
|
30
32
|
return new Promise(async function(resolve, reject) {
|
|
31
33
|
const tempPath = (meta.tempPath);
|
|
32
34
|
const finalPath = poster.removeDirDot(meta.finalPath);
|
|
33
35
|
|
|
36
|
+
// Log
|
|
37
|
+
assistant.log(`onDownload(): tempPath`, tempPath);
|
|
38
|
+
assistant.log(`onDownload(): finalPath`, finalPath);
|
|
39
|
+
|
|
40
|
+
// Save to disk
|
|
34
41
|
poster.readImage(tempPath)
|
|
35
42
|
.then(image => {
|
|
36
43
|
createFile(get(self.Manager.config, 'github.user'), repoInfo.user, repoInfo.name, get(self.Manager.config, 'github.key'), finalPath, image)
|
|
@@ -42,8 +49,8 @@ Module.prototype.main = function () {
|
|
|
42
49
|
});
|
|
43
50
|
}
|
|
44
51
|
|
|
52
|
+
// Create post
|
|
45
53
|
const finalPost = await poster.create(payload.data).catch(e => e);
|
|
46
|
-
|
|
47
54
|
if (finalPost instanceof Error) {
|
|
48
55
|
return reject(assistant.errorify(`Failed to post: ${finalPost}`, {code: 500}));
|
|
49
56
|
}
|
|
@@ -64,7 +71,12 @@ Module.prototype.main = function () {
|
|
|
64
71
|
// }
|
|
65
72
|
|
|
66
73
|
// Save post OR commit
|
|
67
|
-
|
|
74
|
+
const githubUser = get(self.Manager.config, 'github.user');
|
|
75
|
+
const githubKey = get(self.Manager.config, 'github.key');
|
|
76
|
+
const filePath = poster.removeDirDot(finalPost.path);
|
|
77
|
+
const fileContent = finalPost.content;
|
|
78
|
+
|
|
79
|
+
await createFile(githubUser, repoInfo.user, repoInfo.name, githubKey, filePath, fileContent)
|
|
68
80
|
.then(() => {
|
|
69
81
|
return resolve({data: finalPost});
|
|
70
82
|
})
|
|
@@ -77,19 +89,30 @@ Module.prototype.main = function () {
|
|
|
77
89
|
};
|
|
78
90
|
|
|
79
91
|
// HELPERS //
|
|
80
|
-
|
|
81
|
-
|
|
92
|
+
Module.prototype.createFile = function (user, repoUser, repoName, key, path, contents) {
|
|
93
|
+
const self = this;
|
|
94
|
+
const Manager = self.Manager;
|
|
95
|
+
const Api = self.Api;
|
|
96
|
+
const assistant = self.assistant;
|
|
97
|
+
const payload = self.payload;
|
|
82
98
|
|
|
83
|
-
let base64Data = Buffer.from(contents).toString('base64');
|
|
84
|
-
// base64Data = contents;
|
|
85
|
-
// console.log('--------base64Data', base64Data);
|
|
86
99
|
return new Promise(async (resolve, reject) => {
|
|
100
|
+
let fileParsed = pathApi.parse(path);
|
|
101
|
+
let base64Data = Buffer.from(contents).toString('base64');
|
|
87
102
|
let sha;
|
|
88
|
-
try {
|
|
89
103
|
|
|
90
|
-
|
|
104
|
+
// Log
|
|
105
|
+
assistant.log(`createFile(): Writing file to ${repoUser}/${repoName}/${path}`);
|
|
91
106
|
|
|
107
|
+
// Try to get sha
|
|
108
|
+
try {
|
|
109
|
+
let branch = repoName === 'ultimate-jekyll' ? 'template' : 'master';
|
|
92
110
|
let pathGet = `https://api.github.com/repos/${repoUser}/${repoName}/git/trees/${branch}:${encodeURIComponent(pathApi.dirname(path))}`;
|
|
111
|
+
|
|
112
|
+
// Log
|
|
113
|
+
assistant.log(`createFile(): pathGet`, pathGet);
|
|
114
|
+
|
|
115
|
+
// Make request
|
|
93
116
|
await makeRequest({
|
|
94
117
|
method: 'GET',
|
|
95
118
|
url: pathGet,
|
|
@@ -116,8 +139,7 @@ async function createFile(user, repoUser, repoName, key, path, contents) {
|
|
|
116
139
|
}
|
|
117
140
|
|
|
118
141
|
let pathPut = `https://api.github.com/repos/${repoUser}/${repoName}/contents/${path}`;
|
|
119
|
-
let writeRequest =
|
|
120
|
-
{
|
|
142
|
+
let writeRequest = {
|
|
121
143
|
// url: `https://api.github.com/repos/:owner/:repo/contents/:path`,
|
|
122
144
|
method: 'PUT',
|
|
123
145
|
url: pathPut,
|
|
@@ -133,10 +155,16 @@ async function createFile(user, repoUser, repoName, key, path, contents) {
|
|
|
133
155
|
'Authorization': `Basic ${Buffer.from(user + ':' + key).toString('base64')}`,
|
|
134
156
|
}
|
|
135
157
|
}
|
|
158
|
+
|
|
159
|
+
// Log
|
|
160
|
+
assistant.log(`createFile(): pathPut`, pathPut);
|
|
161
|
+
|
|
162
|
+
// Add sha if it exists
|
|
136
163
|
if (sha) {
|
|
137
164
|
writeRequest.body.sha = sha;
|
|
138
165
|
}
|
|
139
|
-
|
|
166
|
+
|
|
167
|
+
// Make request
|
|
140
168
|
await makeRequest(writeRequest)
|
|
141
169
|
.then((json) => {
|
|
142
170
|
if (!json || (json.message && (json.message === 'Not Found' || json.message.includes('Invalid request'))) ) {
|