Skip to content

Commit 184253e

Browse files
committed
fix: Fixing project upload #355
closes: #355
1 parent dd7a35c commit 184253e

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/infrastructure/RequestHelper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ export async function post(
7474
endpoint: string,
7575
options: BaseRequestOptions = {},
7676
): Promise<PostResponse> {
77-
const { sudo, ...body } = options;
77+
const { sudo, form, ...body } = options;
78+
7879
const response = await service.requester.post(service, endpoint, {
79-
body,
80+
body: form || body,
8081
sudo,
8182
});
8283

src/services/Projects.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
RequestHelper,
88
Sudo,
99
} from '../infrastructure';
10-
import { ProjectId, UserId, EventOptions, GroupId, NamespaceId, ProjectUploadMetadata } from '.';
10+
import { ProjectId, UserId, EventOptions, GroupId, NamespaceId, UploadMetadata } from '.';
1111

1212
class Projects extends BaseService {
1313
all(options?: PaginatedRequestOptions) {
@@ -131,18 +131,18 @@ class Projects extends BaseService {
131131
return RequestHelper.put(this, `projects/${pId}/push_rule`, options);
132132
}
133133

134-
upload(projectId, content, metadata: ProjectUploadMetadata = {}) {
134+
upload(projectId, content, { metadata, sudo }: { metadata?: UploadMetadata } & Sudo = {}) {
135135
const pId = encodeURIComponent(projectId);
136136
const form = new FormData();
137137

138-
const defaultMetadata: ProjectUploadMetadata = {
138+
const defaultMetadata: UploadMetadata = {
139139
filename: randomstring.generate(8),
140140
contentType: 'application/octet-stream',
141141
};
142142

143143
form.append('file', content, Object.assign(defaultMetadata, metadata));
144144

145-
return RequestHelper.post(this, `projects/${pId}/uploads`, form);
145+
return RequestHelper.post(this, `projects/${pId}/uploads`, { sudo, form });
146146
}
147147
}
148148

src/services/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export type SnippetVisibility = 'private' | 'public' | 'internal';
266266
export type ImpersonationTokenScope = 'api' | 'read_user';
267267

268268
// Project upload metadata
269-
export interface ProjectUploadMetadata {
269+
export interface UploadMetadata {
270270
filename?: string;
271271
contentType?: string;
272272
}

0 commit comments

Comments
 (0)