diff --git a/build.sbt b/build.sbt index 3f9bdaa..972a86a 100644 --- a/build.sbt +++ b/build.sbt @@ -1,3 +1,5 @@ +import xsbti.compile.CompileAnalysis + name := "jpacrepo" organization := "com.oggio88" @@ -44,6 +46,26 @@ artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) => //javacOptions += "-g" +val compileNim = TaskKey[File]("compileNim", "Compile nim code of web interface", KeyRanks.ATask) +compileNim := { + val result = new File("src/main/webapp/jpacrepo.js") + val cmd = s"nim js -d:release -d:serverURL= -o:${result.getPath} nim/jpacrepo.nim" + println(cmd) + sys.process.stringToProcess(cmd).! match + { + case 0 => + case _ => throw new RuntimeException("Error occurred during deploy") + } + result +} + +//compile in Compile <+= compileNim +packagedArtifact in(Compile, Keys.`package`) := { + val res = (packagedArtifact in(Compile, Keys.`package`)).value + val res2 = compileNim.value + res +} + val wildflyUsername = SettingKey[String]("wildfly-username", "The account username to use to connect to wildfly with jboss-cli.sh") val wildflyPassword = SettingKey[String]("wildfly-password", "The account password to use to connect to wildfly with jboss-cli.sh") val wildflyURL = SettingKey[String]("wildfly-url", "The username to use to connect to wildfly with jboss-cli.sh") @@ -54,7 +76,6 @@ wildflyURL := "localhost:1234" val deploy2Wildfly = TaskKey[Unit]("deploy2Wildfly", "Deploy to a wildfly server instance", KeyRanks.ATask) - deploy2Wildfly := { val cmd = s"/opt/wildfly/bin/jboss-cli.sh " + s"--controller='${wildflyURL.value}' " + @@ -64,7 +85,7 @@ deploy2Wildfly := { println(cmd) sys.process.stringToProcess(cmd).! match { - case 0 => "OK" + case 0 => case _ => throw new RuntimeException("Error occurred during deploy") } } diff --git a/nim/htmlutils b/nim/htmlutils index 4e52526..366e6f0 160000 --- a/nim/htmlutils +++ b/nim/htmlutils @@ -1 +1 @@ -Subproject commit 4e52526abb2c7bfbaeb2642eec7b0456390d47dc +Subproject commit 366e6f0be1c4b448345b32a37fad344b756b4624 diff --git a/nim/jpacrepo.nim b/nim/jpacrepo.nim index 7aa83c0..a2589b7 100644 --- a/nim/jpacrepo.nim +++ b/nim/jpacrepo.nim @@ -9,6 +9,8 @@ from sequtils import map, apply var pkgMap : JsonNode +const serverURL {.strdefine.}: string = "http://oggio88.soon.it/jpacrepo/" + type DownloadPanel = ref object badge : Node listgroup : Node @@ -52,22 +54,18 @@ proc newDownloadPanel(parent : Node) : DownloadPanel = node.appendChild(document.createTextNode(" Download")) let clickHandler = proc(e : Event) = let pkglist : seq[string] = sequtils.toSeq(dp.pkgs.items()) - let r = newXMLHTTPRequest() - let load_cb = proc(e : Event) = - var blob : Blob = r.responseAsBlob #newBlob(r.response, "application/x-tar") - let anchor = document.createElement("a") - let url = createObjectURL(blob) - anchor.setAttribute("href", url) - anchor.setAttribute("download", "archive.tar") - anchor.click() - revokeObjectURL(url) - r.addEventListener("load", load_cb) - r.open("post", "rest/pkg/downloadTar") - r.responseType = "blob" - r.setRequestHeader("Accept", "application/x-tar") - r.setRequestHeader("Content-Type", "application/json") - r.send($(%*pkglist)) - + let form = cast[Formelement](document.createElement("form")) + form.style.display = "none" + form.setAttribute("method", "post") + form.setAttribute("action", serverURL & "rest/pkg/downloadTar") + let tf= document.createElement("input") + tf.setAttribute("name", "pkgs") + let txt = sequtils.foldl(pkglist, a & " " & b) + echo txt + tf.value(txt) + form.appendChild(tf) + document.body.appendChild(form) + form.submit() node.addEventListener("click", clickHandler) cb: dp.footer = node @@ -269,7 +267,6 @@ htmlDocument document, document.body: class ["col-sm-9"] cb: table = node - @@ -277,6 +274,6 @@ let r = newXMLHTTPRequest() let load_cb = proc(e : Event) = pkgMap = parseJson($r.responseText) r.addEventListener("load", load_cb) -r.open("get", "rest/pkg/map") +r.open("get", serverURL & "rest/pkg/map") r.setRequestHeader("Accept", "application/json") r.send() diff --git a/project/plugins.sbt b/project/plugins.sbt index fa93a14..ca3d16c 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1,2 @@ addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.0.0") + diff --git a/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java b/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java index dab3fae..eb84652 100644 --- a/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java +++ b/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java @@ -363,8 +363,10 @@ public class PacmanWebService @POST @Path("/downloadTar") @Produces("application/x-tar") - public Response downloadTar(List files) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public Response downloadTar(@FormParam("pkgs") String formData) { + String[] files = formData.split(" "); for(String fname : files) { if(!ctx.getFile(fname).exists()) throw new NotFoundException(String.format("Package file '%s' does not exist", fname));