mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-25 16:04:01 +00:00
Merge pull request #358 from jdalrymple/355-project-upload
fix: Handle body types properly if not JSON ie formData
This commit is contained in:
commit
be1cae48bb
@ -1,4 +1,5 @@
|
||||
import Ky from 'ky-universal';
|
||||
import FormData from 'form-data';
|
||||
import { decamelizeKeys } from 'humps';
|
||||
import { stringify } from 'query-string';
|
||||
import { skipAllCaps } from './Utils';
|
||||
@ -23,6 +24,10 @@ function defaultRequest(service: any, { body, query, sudo, method }) {
|
||||
const headers = new Headers(service.headers);
|
||||
|
||||
if (sudo) headers.append('sudo', `${sudo}`);
|
||||
|
||||
if (typeof body === 'object' && !(body instanceof FormData)){
|
||||
body = JSON.stringify(decamelizeKeys(body, skipAllCaps));
|
||||
}
|
||||
|
||||
return {
|
||||
timeout: service.requestTimeout,
|
||||
@ -31,7 +36,7 @@ function defaultRequest(service: any, { body, query, sudo, method }) {
|
||||
onProgress: (method === 'stream') ? () => {} : undefined,
|
||||
searchParams: stringify(decamelizeKeys(query || {}) as any, { arrayFormat: 'bracket' }),
|
||||
prefixUrl: service.url,
|
||||
json: typeof body === 'object' ? decamelizeKeys(body, skipAllCaps) : body,
|
||||
body,
|
||||
agent: new Agent({
|
||||
rejectUnauthorized: service.rejectUnauthorized
|
||||
})
|
||||
|
||||
@ -15,7 +15,7 @@ class ProjectImportExport extends BaseService {
|
||||
return RequestHelper.get(this, `projects/${pId}/export`, options);
|
||||
}
|
||||
|
||||
import(content: string, path: string, options?: Sudo) {
|
||||
import(content: string, path: string) {
|
||||
const form = new FormData();
|
||||
|
||||
form.append('file', content, {
|
||||
@ -23,7 +23,7 @@ class ProjectImportExport extends BaseService {
|
||||
contentType: 'application/octet-stream',
|
||||
});
|
||||
|
||||
return RequestHelper.post(this, 'projects/import', { ...options, form });
|
||||
return RequestHelper.post(this, 'projects/import', form);
|
||||
}
|
||||
|
||||
importStatus(projectId: ProjectId, options?: Sudo) {
|
||||
|
||||
@ -131,7 +131,7 @@ class Projects extends BaseService {
|
||||
return RequestHelper.put(this, `projects/${pId}/push_rule`, options);
|
||||
}
|
||||
|
||||
upload(projectId, content, metadata: ProjectUploadMetadata = {}, options?: Sudo) {
|
||||
upload(projectId, content, metadata: ProjectUploadMetadata = {}) {
|
||||
const pId = encodeURIComponent(projectId);
|
||||
const form = new FormData();
|
||||
|
||||
@ -142,7 +142,7 @@ class Projects extends BaseService {
|
||||
|
||||
form.append('file', content, Object.assign(defaultMetadata, metadata));
|
||||
|
||||
return RequestHelper.post(this, `projects/${pId}/uploads`, { ...options, form });
|
||||
return RequestHelper.post(this, `projects/${pId}/uploads`, form);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user