fix(backends): fix commit message handling (#1568)
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { flow, has } from "lodash";
|
||||
import { flow, get } from "lodash";
|
||||
import {
|
||||
localForage,
|
||||
unsentRequest,
|
||||
@ -118,10 +118,19 @@ export default class API {
|
||||
return this.processFiles(entries);
|
||||
};
|
||||
|
||||
uploadBlob = async item => {
|
||||
const contentBase64 = await (has(item, 'toBase64') ? item.toBase64() : Promise.resolve(item.raw));
|
||||
uploadBlob = async (item, { commitMessage, branch = this.branch } = {}) => {
|
||||
const contentBlob = get(item, 'fileObj', new Blob([item.raw]));
|
||||
const formData = new FormData();
|
||||
formData.append(item.path, contentBase64);
|
||||
// Third param is filename header, in case path is `message`, `branch`, etc.
|
||||
formData.append(item.path, contentBlob, basename(item.path));
|
||||
formData.append('branch', branch);
|
||||
if (commitMessage) {
|
||||
formData.append("message", commitMessage);
|
||||
}
|
||||
if (this.commitAuthor) {
|
||||
const { name, email } = this.commitAuthor;
|
||||
formData.append("author", `${name} <${email}>`);
|
||||
}
|
||||
|
||||
return flow([
|
||||
unsentRequest.withMethod("POST"),
|
||||
@ -131,17 +140,21 @@ export default class API {
|
||||
])(`${ this.repoURL }/src`);
|
||||
};
|
||||
|
||||
persistFiles = (files, { commitMessage, newEntry }) => Promise.all(
|
||||
files.filter(({ uploaded }) => !uploaded).map(this.uploadBlob)
|
||||
persistFiles = (files, { commitMessage }) => Promise.all(
|
||||
files.filter(({ uploaded }) => !uploaded).map(file => this.uploadBlob(file, { commitMessage }))
|
||||
);
|
||||
|
||||
deleteFile = (path, message, options={}) => {
|
||||
const branch = options.branch || this.branch;
|
||||
deleteFile = (path, message, { branch = this.branch } = {}) => {
|
||||
const body = new FormData();
|
||||
body.append('files', path);
|
||||
if (message && message !== "") {
|
||||
body.append('branch', branch);
|
||||
if (message) {
|
||||
body.append("message", message);
|
||||
}
|
||||
if (this.commitAuthor) {
|
||||
const { name, email } = this.commitAuthor;
|
||||
body.append("author", `${name} <${email}>`);
|
||||
}
|
||||
return flow([
|
||||
unsentRequest.withMethod("POST"),
|
||||
unsentRequest.withBody(body),
|
||||
|
Reference in New Issue
Block a user