Skip to content

Commit a0db691

Browse files
DimitarTachevFatme
authored andcommitted
feat: use the playground shortener in order to get smaller QR codes
1 parent 9c34235 commit a0db691

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

config/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"ANDROID_DEBUG_UI_MAC": "Google Chrome",
66
"USE_POD_SANDBOX": false,
77
"DISABLE_HOOKS": false,
8-
"UPLOAD_PLAYGROUND_FILES_ENDPOINT": "https://play.nativescript.org/api/files"
8+
"UPLOAD_PLAYGROUND_FILES_ENDPOINT": "https://play.nativescript.org/api/files" ,
9+
"SHORTEN_URL_ENDPOINT": "https://play.nativescript.org/api/shortenurl?longUrl=%s"
910
}

lib/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class Configuration extends ConfigBase implements IConfiguration { // Use
99
ANDROID_DEBUG_UI: string = null;
1010
USE_POD_SANDBOX: boolean = false;
1111
UPLOAD_PLAYGROUND_FILES_ENDPOINT: string = null;
12+
SHORTEN_URL_ENDPOINT: string = null;
1213

1314
/*don't require logger and everything that has logger as dependency in config.js due to cyclic dependency*/
1415
constructor(protected $fs: IFileSystem) {

lib/declarations.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ interface IConfiguration extends Config.IConfig {
383383
ANDROID_DEBUG_UI: string;
384384
USE_POD_SANDBOX: boolean;
385385
UPLOAD_PLAYGROUND_FILES_ENDPOINT: string;
386+
SHORTEN_URL_ENDPOINT: string;
386387
}
387388

388389
interface IApplicationPackage {

lib/services/livesync/playground/qr-code-generator.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { PlaygroundStoreUrls } from "./preview-app-constants";
2+
import * as util from "util";
23

34
export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator {
45
constructor(private $previewSdkService: IPreviewSdkService,
5-
private $qrCodeTerminalService: IQrCodeTerminalService) { }
6+
private $httpClient: Server.IHttpClient,
7+
private $qrCodeTerminalService: IQrCodeTerminalService,
8+
private $config: IConfiguration) {
9+
}
610

711
public async generateQrCodeForiOS(): Promise<void> {
812
await this.generateQrCode(PlaygroundStoreUrls.APP_STORE_URL);
@@ -17,7 +21,15 @@ export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator {
1721
}
1822

1923
private async generateQrCode(url: string): Promise<void> {
20-
// TODO: Shorten url before generate QR code
24+
const shortenUrlEndpoint = util.format(this.$config.SHORTEN_URL_ENDPOINT, url);
25+
try {
26+
const response = await this.$httpClient.httpRequest(shortenUrlEndpoint);
27+
const responseBody = JSON.parse(response.body);
28+
url = responseBody.shortURL || url;
29+
} catch (e) {
30+
// use the longUrl
31+
}
32+
2133
this.$qrCodeTerminalService.generate(url);
2234
}
2335
}

0 commit comments

Comments
 (0)