]> Untitled Git - public.git/blobdiff - lua/publish.lua
Updated to 1.3.0
[public.git] / lua / publish.lua
index 5fa18c0785a80cacc0e0caf0d6f480ea6934f300..afe2fed871cf46c3ffc98e4b0efbd073d014e42c 100644 (file)
@@ -1,7 +1,7 @@
 require "apache2"
 
 function publish(dir, pattern)
-    local cmd = ("%s/publish.sh %s"):format(dir, pattern)
+    local cmd = ("%s/publish.sh '%s'"):format(dir, pattern)
     local handle = io.popen(cmd)
     local output = handle:read('*a')
     handle:close()
@@ -21,14 +21,23 @@ function handle(r)
     r.content_type = "text/html"
 
     local args = r:parseargs()
-    local pattern = args.pattern 
+    local pattern = string.gsub(args.pattern, '+', ' ')
 
     if pattern then
         local nonce = publish(r.context_document_root, pattern)
-        local uri = ("%s://%s:%s/%s"):format(
-            r.is_https and "https" or "http", 
-            r.server_name, r.port, nonce)
-        r:puts( ([[<a href="%s">%s</a>]]):format(uri, uri) )
+        if nonce == "" then
+            r:puts( "No links created" )
+        else
+            -- if FQDN override is set,
+            -- use override instead of my own server name and port number
+            local fqdn = os.getenv('PUBLIC_FQDN_OVERRIDE')
+            fqdn = fqdn or
+                (r.is_https and "https" or "http") ..
+                "://" .. r.server_name .. ":" ..r.port
+
+            local uri = ("%s/%s/"):format(fqdn, nonce)
+            r:puts( ([[<a href="%s">%s</a>]]):format(uri, uri) )
+        end
     else
         local template = get_form(r.context_document_root)
         r:puts( template )