Added API to presentation raw file content.

This commit is contained in:
David Russell 2017-08-28 13:46:26 +07:00
parent 7a294929b0
commit fe53cf81bb
4 changed files with 56 additions and 11 deletions

View File

@ -406,6 +406,39 @@ public class PitchController extends Controller {
return ok(com.gitpitch.views.html.Gist.render(gid, deps));
} // gist action
/*
* Raw returns file content identified by path.
*/
public CompletionStage<Result> raw(String grs,
String user,
String repo,
String branch,
String path) {
PitchParams pp =
PitchParams.build(grsOnCall(grs), user, repo, branch);
log.debug("raw: pp={}, path={}", pp, path);
String offline = request().getQueryString("offline");
log.debug("raw: pp={}, path={}, offline={}", pp, path, offline != null);
Optional<File> fileo = pitchService.raw(pp, path);
if (fileo.isPresent()) {
log.debug("raw: pp={}, path={} file is found.");
File file = fileo.get();
return CompletableFuture.completedFuture(ok(file));
} else {
log.debug("raw: pp={}, path={} file not found.");
return CompletableFuture.completedFuture(notFound());
}
} // raw action
/*
* Determine GRS on call, explicitly defined or default.
*/

View File

@ -280,4 +280,13 @@ public class PitchService {
return zip;
}
/*
* Return file at path, else Optional.empty.
*/
public Optional<File> raw(PitchParams pp, String path) {
File rawFile = diskService.asFile(pp, path);
return rawFile.exists() ? Optional.of(rawFile) : Optional.empty();
}
}

View File

@ -5,6 +5,9 @@
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
# Serve GitPitch raw file content.
GET /pitchme/raw/:grs/:user/:repo/:b/*path com.gitpitch.controllers.PitchController.raw(grs: String, user: String, repo: String, b: String, path: String)
# Serve GitPitch GIST iFrame for {gid}.
GET /pitchme/gist/:gid com.gitpitch.controllers.PitchController.gist(gid:String)