Skip to content

Commit 866bb4e

Browse files
author
David Echelberger
authored
Merge pull request #47 from kaleido-io/publish
Add publishData and publishDataBlob
2 parents f3bb944 + 059247a commit 866bb4e

File tree

3 files changed

+897
-141
lines changed

3 files changed

+897
-141
lines changed

lib/firefly.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ import {
6565
FireFlyGroupResponse,
6666
FireFlyBlockchainEventFilter,
6767
FireFlyBlockchainEventResponse,
68+
FireFlyDataBlobRequest,
69+
FireFlyDataBlobRequestDefaults,
6870
} from './interfaces';
6971
import { FireFlyWebSocket, FireFlyWebSocketCallback } from './websocket';
7072
import HttpBase, { mapConfig } from './http';
@@ -190,27 +192,24 @@ export default class FireFly extends HttpBase {
190192
return this.createOne<FireFlyDataResponse>('/data', data, options);
191193
}
192194

195+
publishData(id: string, options?: FireFlyCreateOptions): Promise<FireFlyDataResponse> {
196+
return this.createOne<FireFlyDataResponse>(`/data/${id}/value/publish`, {}, options);
197+
}
198+
193199
async uploadDataBlob(
194200
blob: string | Buffer | Readable,
195-
filename: string,
201+
blobOptions?: FormData.AppendOptions,
202+
dataOptions?: FireFlyDataBlobRequest,
196203
): Promise<FireFlyDataResponse> {
204+
dataOptions = { ...FireFlyDataBlobRequestDefaults, ...dataOptions };
197205
const formData = new FormData();
198-
formData.append('autometa', 'true');
199-
formData.append('file', blob, { filename });
200-
const response = await this.wrapError(
201-
this.http.post<FireFlyDataResponse>('/data', formData, {
202-
headers: {
203-
...formData.getHeaders(),
204-
'Content-Length': formData.getLengthSync(),
205-
},
206-
}),
207-
);
208-
return response.data;
209-
}
210-
211-
async uploadDataBlobWithFormData(
212-
formData: FormData
213-
): Promise<FireFlyDataResponse> {
206+
for (const key in dataOptions) {
207+
const val = dataOptions[key as keyof FireFlyDataBlobRequest];
208+
if (val !== undefined) {
209+
formData.append(key, val);
210+
}
211+
}
212+
formData.append('file', blob, blobOptions);
214213
const response = await this.wrapError(
215214
this.http.post<FireFlyDataResponse>('/data', formData, {
216215
headers: {
@@ -222,13 +221,8 @@ export default class FireFly extends HttpBase {
222221
return response.data;
223222
}
224223

225-
async publishDataBlobToSharedStorage(
226-
dataid: string
227-
): Promise<FireFlyDataResponse> {
228-
const response = await this.wrapError(
229-
this.http.post<FireFlyDataResponse>(`/data/${dataid}/blob/publish`, {dataid}),
230-
);
231-
return response.data;
224+
publishDataBlob(id: string, options?: FireFlyCreateOptions): Promise<FireFlyDataResponse> {
225+
return this.createOne<FireFlyDataResponse>(`/data/${id}/blob/publish`, {}, options);
232226
}
233227

234228
getBatches(

lib/interfaces.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,17 @@ export type FireFlyDataFilter = operations['getData']['parameters']['query'];
159159

160160
export type FireFlyDataRequest =
161161
operations['postData']['requestBody']['content']['application/json'];
162+
export type FireFlyDataBlobRequest =
163+
operations['postData']['requestBody']['content']['multipart/form-data'];
162164

163165
export type FireFlyDataResponse = Required<
164166
operations['getDataByID']['responses']['200']['content']['application/json']
165167
>;
166168

169+
export const FireFlyDataBlobRequestDefaults: FireFlyDataBlobRequest = {
170+
autometa: 'true',
171+
};
172+
167173
// Messages
168174

169175
export type FireFlyMessageFilter = operations['getMsgs']['parameters']['query'];

0 commit comments

Comments
 (0)