فهرست منبع

Add download button for mobile

nagadomi 9 سال پیش
والد
کامیت
26f0d61bb1
4فایلهای تغییر یافته به همراه10 افزوده شده و 1 حذف شده
  1. 1 0
      assets/index.html
  2. 1 0
      assets/index.ja.html
  3. 1 0
      assets/index.ru.html
  4. 7 1
      web.lua

+ 1 - 0
assets/index.html

@@ -48,6 +48,7 @@
         <label><input type="radio" name="scale" value="2"> 2x</label>
       </fieldset>
       <input type="submit"/>
+      <input type="submit" name="download" value="Download"/>
     </form>
     <div class="help">
       <ul class="padding-left">

+ 1 - 0
assets/index.ja.html

@@ -45,6 +45,7 @@
         <label><input type="radio" name="scale" value="2"> 2x</label>
       </fieldset>
       <input type="submit" value="実行"/>
+      <input type="submit" name="download" value="ダウンロード"/>
     </form>
     <div class="help">
       <ul class="padding-left">

+ 1 - 0
assets/index.ru.html

@@ -47,6 +47,7 @@
         <label><input type="radio" name="scale" value="2"> 2x</label>
       </fieldset>
       <input type="submit"/>
+      <input type="submit" name="download" value="Download"/>
     </form>
     <div class="help">
       <ul class="padding-left">

+ 7 - 1
web.lua

@@ -156,6 +156,8 @@ function APIHandler:post()
    local noise = tonumber(self:get_argument("noise", "0"))
    local white_noise = tonumber(self:get_argument("white_noise", "0"))
    local style = self:get_argument("style", "art")
+   local download = (self:get_argument("download", "")):len()
+
    if style ~= "art" then
       style = "photo" -- style must be art or photo
    end
@@ -189,8 +191,12 @@ function APIHandler:post()
       local name = uuid() .. ".png"
       local blob = image_loader.encode_png(x, alpha)
       self:set_header("Content-Disposition", string.format('filename="%s"', name))
-      self:set_header("Content-Type", "image/png")
       self:set_header("Content-Length", string.format("%d", #blob))
+      if download > 0 then
+	 self:set_header("Content-Type", "application/octet-stream")
+      else
+	 self:set_header("Content-Type", "image/png")
+      end
       self:write(blob)
    else
       if not x then