catto.js 1.1.6 → 1.1.8
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/GitHub.js +11 -7
- package/package.json +1 -1
package/GitHub.js
CHANGED
|
@@ -30,13 +30,14 @@ class GitHub {
|
|
|
30
30
|
* Reads data from a file in the Github repository.
|
|
31
31
|
*
|
|
32
32
|
* @param {string} file - Path to the file to be read.
|
|
33
|
+
* @param {boolean} [b64mode=false] - Whetever return data encoded in base64 or not.
|
|
33
34
|
*
|
|
34
35
|
* @returns {(string|object)} - The content of the file. If the file is a JSON file, returns a parsed object, otherwise returns a string.
|
|
35
36
|
*
|
|
36
37
|
* @async
|
|
37
38
|
* @throws {Error} If there is a problem with the API request.
|
|
38
39
|
*/
|
|
39
|
-
async read(file) {
|
|
40
|
+
async read(file, b64mode) {
|
|
40
41
|
var value = (await request.get({
|
|
41
42
|
"url": `https://api.github.com/repos/${this.options.username}/${this.options.repository}/contents/${file}`,
|
|
42
43
|
"headers": {
|
|
@@ -45,10 +46,12 @@ class GitHub {
|
|
|
45
46
|
}
|
|
46
47
|
})).body;
|
|
47
48
|
this.shas[file] = value.sha;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (!b64mode) {
|
|
50
|
+
value = Base64.decode(value.content);
|
|
51
|
+
try {
|
|
52
|
+
value = JSON.parse(value);
|
|
53
|
+
} catch(e) {}
|
|
54
|
+
}
|
|
52
55
|
return value;
|
|
53
56
|
}
|
|
54
57
|
/**
|
|
@@ -56,13 +59,14 @@ class GitHub {
|
|
|
56
59
|
*
|
|
57
60
|
* @param {string} file - Path to the file to be written.
|
|
58
61
|
* @param {(string|object)} value - The data to be written to the file. If it is an object, it will be stringified as a JSON file.
|
|
62
|
+
* @param {boolean} [b64mode=false] - Whetever is data to be written is encoded in base64 or not.
|
|
59
63
|
*
|
|
60
64
|
* @returns {boolean} - Returns true if the write was successful.
|
|
61
65
|
*
|
|
62
66
|
* @async
|
|
63
67
|
* @throws {Error} If there is a problem with the API request.
|
|
64
68
|
*/
|
|
65
|
-
async write(file, value) {
|
|
69
|
+
async write(file, value, b64mode) {
|
|
66
70
|
if (typeof value === "object") {
|
|
67
71
|
value = JSON.stringify(value);
|
|
68
72
|
}
|
|
@@ -74,7 +78,7 @@ class GitHub {
|
|
|
74
78
|
"Content-Type": "application/json"
|
|
75
79
|
},
|
|
76
80
|
"body": JSON.stringify({
|
|
77
|
-
"content": Base64.encode(value),
|
|
81
|
+
"content": (b64mode ? value : Base64.encode(value)),
|
|
78
82
|
"message": this.options.message,
|
|
79
83
|
"sha": this.shas[file]
|
|
80
84
|
})
|