Skip to content

Commit affbbea

Browse files
DimitarTachevFatme
authored andcommitted
fix: handle bigger files upload (temporary reuse the playground endpoint)
1 parent d46fec2 commit affbbea

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/services/livesync/playground/preview-sdk-service.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { FilePayload, MessagingService, Config, Device, DeviceConnectedMessage, SdkCallbacks, ConnectedDevices } from "nativescript-preview-sdk";
22
import { EventEmitter } from "events";
33
import { PreviewSdkEventNames, PubnubKeys } from "./preview-app-constants";
4+
const pako = require("pako");
45

56
export class PreviewSdkService extends EventEmitter implements IPreviewSdkService {
67
private messagingService: MessagingService = null;
78
private instanceId: string = null;
89
public connectedDevices: Device[] = [];
910

1011
constructor(private $errors: IErrors,
11-
private $logger: ILogger) {
12+
private $logger: ILogger,
13+
private $httpClient: Server.IHttpClient) {
1214
super();
1315
}
1416

@@ -70,7 +72,24 @@ export class PreviewSdkService extends EventEmitter implements IPreviewSdkServic
7072
}
7173
},
7274
onDevicesPresence: (devices: Device[]) => ({ }),
73-
onSendingChange: (sending: boolean) => ({ })
75+
onSendingChange: (sending: boolean) => ({ }),
76+
onBiggerFilesUpload: async (filesContent, callback) => {
77+
// TODO: stop using the playground endpoint when we have a direct Amazon one
78+
const gzippedContent = new Buffer(pako.gzip(filesContent));
79+
const playgroundUploadResponse = await this.$httpClient.httpRequest({
80+
url: "https://play.telerik.rocks/api/files",
81+
method: "POST",
82+
body: gzippedContent,
83+
headers: {
84+
"Content-Encoding": "gzip",
85+
"Content-Type": "text/plain"
86+
}
87+
});
88+
89+
const responseBody = JSON.parse(playgroundUploadResponse.body);
90+
const location = responseBody && responseBody.location;
91+
callback(location, playgroundUploadResponse.error);
92+
}
7493
};
7594
}
7695
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"ora": "2.0.0",
6060
"osenv": "0.1.3",
6161
"pacote": "8.1.6",
62+
"pako": "^1.0.6",
6263
"pbxproj-dom": "1.0.11",
6364
"plist": "1.1.0",
6465
"plist-merge-patch": "0.1.1",

0 commit comments

Comments
 (0)