added nim compilation task to sbt deploy task

switched to fake form with POST method for file download
This commit is contained in:
2017-09-28 22:11:29 +02:00
parent 7de186084d
commit ce06721e79
5 changed files with 43 additions and 22 deletions

View File

@@ -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")
}
}

View File

@@ -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()

View File

@@ -1 +1,2 @@
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.0.0")

View File

@@ -363,8 +363,10 @@ public class PacmanWebService
@POST
@Path("/downloadTar")
@Produces("application/x-tar")
public Response downloadTar(List<String> 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));