|
|
@@ -4,7 +4,7 @@ import RsaPrivateKey = crypto.keys;
|
|
|
import { Storage } from './storage';
|
|
|
import { IWebClient } from './webclient';
|
|
|
const TextEncoder = util.TextEncoder;
|
|
|
-
|
|
|
+import { UploadItemParameters } from './upload-item-parameters';
|
|
|
import { encodeHex } from './util';
|
|
|
import WebClientNode from './webclient-node';
|
|
|
|
|
|
@@ -95,8 +95,39 @@ export class BankClient {
|
|
|
});
|
|
|
return postResponse.balance;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ public async upload(recip: string, params: UploadItemParameters) {
|
|
|
+ const url = this.urlBase + '/bank/upload';
|
|
|
+ const formData: any = {};
|
|
|
+ if (params.fileData) {
|
|
|
+ formData.file = {
|
|
|
+ value: params.fileData,
|
|
|
+ options: {
|
|
|
+ filename: params.fileName
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (params.thumbFileData) {
|
|
|
+ formData.thumb = {
|
|
|
+ value: params.thumbFileData,
|
|
|
+ options: {
|
|
|
+ filename: params.thumbFileName
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ for (const attr of ['title', 'text', 'type']) {
|
|
|
+ if (params[attr] != null) {
|
|
|
+ formData[attr] = params[attr];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const uploadResponse: any = await this.webClient.requestJSON({
|
|
|
+ formData,
|
|
|
+ method: 'POST',
|
|
|
+ url
|
|
|
+ });
|
|
|
+ console.log('uploadResponse', uploadResponse);
|
|
|
+ return uploadResponse.hash;
|
|
|
+ }
|
|
|
|
|
|
private getPriv(): RsaPrivateKey {
|
|
|
if (!this.privateKey) {
|
|
|
@@ -134,4 +165,6 @@ export class BankClient {
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|