Skip to content

Commit

Permalink
Merge pull request #37 from SRGSSR/develop
Browse files Browse the repository at this point in the history
DeepLink V2
  • Loading branch information
StaehliJ authored Sep 3, 2019
2 parents 73d2f82 + 25adf47 commit eb9a295
Show file tree
Hide file tree
Showing 13 changed files with 963 additions and 55 deletions.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Binary file added docs/README-images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Playfff
=============
[![SRG Logger logo](README-images/logo.png)](https://github.com/SRGSSR/pfff)

[![Build Status](https://travis-ci.org/SRGSSR/pfff.svg?branch=master)](https://travis-ci.org/SRGSSR/pfff) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/SRGSSR/pfff)](https://github.com/SRGSSR/pfff/releases) [![GitHub license](https://img.shields.io/github/license/SRGSSR/pfff)](https://github.com/SRGSSR/pfff/blob/master/LICENSE)


## About

Expand Down Expand Up @@ -50,7 +52,8 @@ A wide list of parameters are available.

#### Deep link

* `/api/v1/deeplink/parsePlayUrl.js` (GET): Get the Play web URL to mobile application scheme URL script (deep link script). The HTTP ETag caching is supported.
* `/api/v1/deeplink/parsePlayUrl.js` (GET): Get the Play web URL to mobile application scheme URL (v1) script (deep link script). The HTTP ETag caching is supported.
* `/api/v2/deeplink/parsePlayUrl.js` (GET): Get the Play web URL to mobile application scheme URL (v2) script (deep link script). The HTTP ETag caching is supported.
* `/api/v1/deeplink/report` (POST) : create or update a new deep link report object from the JSON body object. Send a report only if the script returns `[scheme]://unsupported`. The JSON object must contains:
* `clientTime` (string): date of the parsing execution in `yyyy-MM-dd'T'HH:mm:ssXXX` format.
* `clientId` (string): Bundle id or package name.
Expand Down Expand Up @@ -93,4 +96,4 @@ Private APIs need a user authentification.

## License

To be defined.
See the [LICENSE](../LICENSE) file for more information.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>ch.srgssr</groupId>
<artifactId>playfff</artifactId>
<version>16</version>
<version>17</version>
<packaging>jar</packaging>

<name>pfff</name>
Expand Down
9 changes: 7 additions & 2 deletions portal-app/src/app/deeplink/deeplink.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ <h2 class="text-center">
</thead>
<tbody>
<tr *ngFor="let deeplinkReport of deeplinkReports">
<td *ngFor="let col of columns">
{{deeplinkReport[col]}}
<td *ngFor="let column of columns; let idx=index">
<span *ngIf="idx == 5">
<a href="{{deeplinkReport[column]}}" target="_blank">{{deeplinkReport[column]}}</a>
</span>
<span *ngIf="idx != 5">
{{deeplinkReport[column]}}
</span>
</td>
<td>
<button class="btn btn-danger" (click)="deleteDeeplinkReport(deeplinkReport)">Delete</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void configure(HttpSecurity http) throws Exception {
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/api/v1/deeplink/parsePlayUrl.js")
.antMatchers("/api/v{[0-9]+}/deeplink/parsePlayUrl.js")
.antMatchers(HttpMethod.POST, "/api/v1/deeplink/report");
}

Expand Down
24 changes: 19 additions & 5 deletions src/main/java/ch/srgssr/playfff/controller/DeepLinkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,31 @@ public ResponseEntity<DeepLinkReport> create(@RequestBody DeepLinkReport deepLin
}

// Public API
@RequestMapping(value="/api/v1/deeplink/parsePlayUrl.js")
@RequestMapping(value="/api/v{version}/deeplink/parsePlayUrl.js")
@ResponseBody
public ResponseEntity<String> parsePlayUrlJavascript() {
public ResponseEntity<String> parsePlayUrlJavascript(@PathVariable("version") int version) {

DeepLinkJSContent deepLinkJSContent = service.getParsePlayUrlJSContent();

if (deepLinkJSContent != null) {
String content = null;
String hash = null;

switch (version) {
case 1:
content = deepLinkJSContent.getContentV1();
hash = deepLinkJSContent.getHashV1();
break;
case 2:
content = deepLinkJSContent.getContentV2();
hash = deepLinkJSContent.getHashV2();
break;
}

if (content != null && hash != null) {
return ResponseEntity.ok()
.cacheControl(CacheControl.empty().cachePublic())
.eTag(deepLinkJSContent.getHash())
.body(deepLinkJSContent.getContent());
.eTag(hash)
.body(content);
} else {
return ResponseEntity.notFound().build();
}
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/ch/srgssr/playfff/model/DeepLinkJSContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,32 @@
*/
public class DeepLinkJSContent {

private String content;
private String hash;
private String contentV1;
private String hashV1;

public DeepLinkJSContent(String content, String hash) {
this.content = content;
this.hash = hash;
private String contentV2;
private String hashV2;

public DeepLinkJSContent(String contentV1, String hashV1, String contentV2, String hashV2) {
this.contentV1 = contentV1;
this.hashV1 = hashV1;
this.contentV2 = contentV2;
this.hashV2 = hashV2;
}

public String getContentV1() {
return contentV1;
}

public String getHashV1() {
return hashV1;
}

public String getContent() {
return content;
public String getContentV2() {
return contentV2;
}

public String getHash() {
return hash;
public String getHashV2() {
return hashV2;
}
}
26 changes: 18 additions & 8 deletions src/main/java/ch/srgssr/playfff/service/DeepLinkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public DeepLinkJSContent getParsePlayUrlJSContent() {

@CachePut(DeepLinkCacheName)
public synchronized DeepLinkJSContent refreshParsePlayUrlJSContent() {
String javascript = BaseResourceString.getString(applicationContext, "parsePlayUrl.js");
String javascriptV1 = BaseResourceString.getString(applicationContext, "deeplink/v1/parsePlayUrl.js");
String javascriptV2 = BaseResourceString.getString(applicationContext, "deeplink/v2/parsePlayUrl.js");

Map<String, String> buProdMap = new HashMap<>();
buProdMap.put("srf", "www.srf.ch");
Expand Down Expand Up @@ -125,7 +126,8 @@ public synchronized DeepLinkJSContent refreshParsePlayUrlJSContent() {
}

if (tvTopics != null) {
javascript = javascript.replaceAll("\\/\\* INJECT TVTOPICS OBJECT \\*\\/", "var tvTopics = " + tvTopics + ";");
javascriptV1 = javascriptV1.replaceAll("\\/\\* INJECT TVTOPICS OBJECT \\*\\/", "var tvTopics = " + tvTopics + ";");
javascriptV2 = javascriptV2.replaceAll("\\/\\* INJECT TVTOPICS OBJECT \\*\\/", "var tvTopics = " + tvTopics + ";");
}

String tvEvents = null;
Expand All @@ -136,23 +138,31 @@ public synchronized DeepLinkJSContent refreshParsePlayUrlJSContent() {
}

if (tvEvents != null) {
javascript = javascript.replaceAll("\\/\\* INJECT TVEVENTS OBJECT \\*\\/", "var tvEvents = " + tvEvents + ";");
javascriptV1 = javascriptV1.replaceAll("\\/\\* INJECT TVEVENTS OBJECT \\*\\/", "var tvEvents = " + tvEvents + ";");
javascriptV2 = javascriptV2.replaceAll("\\/\\* INJECT TVEVENTS OBJECT \\*\\/", "var tvEvents = " + tvEvents + ";");
}

String buildHash = "NO_SHA1";
String buildHashV1 = "NO_SHA1";
try {
buildHash = Sha1.sha1(javascript);
buildHashV1 = Sha1.sha1(javascriptV1);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
logger.warn("sha1", e);
logger.warn("sha1 v1", e);
}
String buildHashV2 = "NO_SHA1";
try {
buildHashV2 = Sha1.sha1(javascriptV2);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
logger.warn("sha1 v2", e);
}
Date buildDate = new Date();

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
dateFormat.setTimeZone(TimeZone.getTimeZone("Europe/Zurich"));
String strDate = dateFormat.format(buildDate);
javascript = javascript.replaceAll("var parsePlayUrlBuild = \"mmf\";", "var parsePlayUrlBuild = \"" + buildHash + "\";\nvar parsePlayUrlBuildDate = \"" + strDate + "\";");
javascriptV1 = javascriptV1.replaceAll("var parsePlayUrlBuild = \"mmf\";", "var parsePlayUrlBuild = \"" + buildHashV1 + "\";\nvar parsePlayUrlBuildDate = \"" + strDate + "\";");
javascriptV2 = javascriptV2.replaceAll("var parsePlayUrlBuild = \"mmf\";", "var parsePlayUrlBuild = \"" + buildHashV2 + "\";\nvar parsePlayUrlBuildDate = \"" + strDate + "\";");

return new DeepLinkJSContent(javascript, buildHash);
return new DeepLinkJSContent(javascriptV1, buildHashV1, javascriptV2, buildHashV2);
}

private Map<String, Map<String, String>> getTvTopicMap(Map<String, String> buMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@
var parsePlayUrlVersion = 21;
var parsePlayUrlBuild = "mmf";

function parsePlayUrl(urlString) {
var url = urlString;
try {
url = new URL(urlString);
}
catch(error) {
console.log("Can't read URL: " + error);
return null;
}

var queryParams = {};
for (var queryItem of url.searchParams) {
queryParams[queryItem[0]] = queryItem[1];
}

return parseForPlayApp(url.protocol.replace(':', ''), url.hostname, url.pathname, queryParams, url.hash.replace('#', ''));
if(! console) {
var console = {
log:function(){}
}
}

function parseForPlayApp(scheme, hostname, pathname, queryParams, anchor) {
Expand Down
Loading

0 comments on commit eb9a295

Please sign in to comment.