progresses on #49
This commit is contained in:
1 parent
bec1c3c510
commit
b97ef80596
7 files changed
+78
-12
No files matched your search
Vendored
+1
-1
@@ -1 +1 @@
|
||||
$(document).ready(function(){$("#logout").click(function(a){return a.preventDefault(),$.ajax({type:"GET",url:"/admin",async:!1,username:"username",password:"password",headers:{Authorization:"Basic xxx"}}).fail(function(){window.location="/"}),!1}),$(document).pjax("a[data-pjax]","#content")}),$(document).on("ready pjax:end",function(){function a(){this.style.height="5px",this.style.height=this.scrollHeight+"px"}return $("#content").off(),document.title=document.getElementById("site-title").innerHTML,$("textarea").each(a),$("textarea").keyup(a),$(window).resize(function(){$("textarea").each(a)}),$("main").hasClass("browse")&&$(document).trigger("page:browse"),$(".editor")[0]&&$(document).trigger("page:editor"),!1}),$(document).on("page:browse",function(){var a="#foreground",b=new Object;b.selector="form#delete",b.form=$(b.selector),b.row="",b.button="",b.url="",$("#content").on("click",".delete",function(c){return c.preventDefault(),b.button=$(this),b.row=$(this).parent().parent(),$(a).fadeIn(200),b.url=b.row.find(".filename").text(),b.form.find("span").text(b.url),b.form.fadeIn(200),!1}),$("#content").on("submit",b.selector,function(c){c.preventDefault();var d=new XMLHttpRequest;return d.open("DELETE",b.button.data("file")),d.send(),d.onreadystatechange=function(){4==d.readyState&&(200==d.status?($(a).fadeOut(200),b.form.fadeOut(200),b.row.fadeOut(200),notification({text:b.button.data("message"),type:"success",timeout:5e3})):(notification({text:"Something went wrong.",type:"error"}),console.log(d.responseText)))},!1}),$("#content").on("change",'input[type="file"]',function(a){a.preventDefault(),files=a.target.files;var b=new FormData;return $.each(files,function(a,c){b.append(a,c)}),$.ajax({url:window.location.pathname,type:"POST",data:b,cache:!1,dataType:"json",headers:{"X-Upload":"true"},processData:!1,contentType:!1}).done(function(a){notification({text:"File(s) uploaded successfully.",type:"success",timeout:5e3}),$.pjax({url:window.location.pathname,container:"#content"})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("#content").on("click","#upload",function(a){return a.preventDefault(),$('.actions input[type="file"]').click(),!1});var c=new Object;c.selector="form#new",c.form=$(c.selector),c.input=c.selector+' input[type="text"]',c.button="",c.url="",$("#content").on("click",".new",function(b){return b.preventDefault(),c.button=$(this),$(a).fadeIn(200),c.form.fadeIn(200),!1}),$("#content").on("keypress",c.input,function(a){return 13==a.keyCode?(a.preventDefault(),$(c.form).submit(),!1):void 0}),$("#content").on("submit",c.selector,function(a){a.preventDefault();var b=c.form.find('input[type="text"]').val(),d=b.split(":"),e="",f="";if(""==b)return notification({text:"You have to write something. If you want to close the box, click the button again.",type:"warning",timeout:5e3}),!1;if(1==d.length)e=b;else{if(2!=d.length)return notification({text:"Hmm... I don't understand you. Try writing something like 'name[:archetype]'.",type:"error"}),!1;e=d[0],f=d[1]}var g={filename:e,archetype:f},h=new XMLHttpRequest;return h.open("POST",window.location.pathname),h.setRequestHeader("Content-Type","application/json;charset=UTF-8"),h.send(JSON.stringify(g)),h.onreadystatechange=function(){if(4==h.readyState)if(200==h.status){var a=JSON.parse(h.responseText);notification({text:"File created successfully.",type:"success",timeout:5e3}),$.pjax({url:a.Location,container:"#content"})}else notification({text:"Something went wrong.",type:"error"}),console.log(h.responseText)},!1});var d=new Object;d.selector="form#rename",d.form=$(d.selector),d.input=d.selector+' input[type="text"]',d.button="",d.url="",$("#content").on("click",".rename",function(b){return b.preventDefault(),d.button=$(this),$(a).fadeIn(200),d.url=$(this).parent().parent().find(".filename").text(),d.form.fadeIn(200),d.form.find("span").text(d.url),d.form.find('input[type="text"]').val(d.url),!1}),$("#content").on("keypress",d.input,function(a){return 13==a.keyCode?(a.preventDefault(),$(d.form).submit(),!1):void 0}),$("#content").on("submit",d.selector,function(a){a.preventDefault();var b=d.form.find('input[type="text"]').val();if(""===b)return!1;"/"!=b.substring(0,1)&&(b=window.location.pathname.replace("/admin/browse/","")+"/"+b);var c={filename:b},e=new XMLHttpRequest;return e.open("PUT",d.url),e.setRequestHeader("Content-Type","application/json;charset=UTF-8"),e.send(JSON.stringify(c)),e.onreadystatechange=function(){4==e.readyState&&(200==e.status?($.pjax({url:window.location.pathname,container:"#content"}),notification({text:d.button.data("message"),type:"success",timeout:5e3})):(notification({text:"Something went wrong.",type:"error"}),console.log(e.responseText)))},!1});var e=new Object;e.selector="form#git",e.form=$(e.selector),e.input=e.selector+' input[type="text"]',$("#content").on("click","button.git",function(b){return b.preventDefault(),$(a).fadeIn(200),e.form.fadeIn(200),!1}),$("#content"Line truncated
|
||||
$(document).ready(function(){$("#logout").click(function(a){return a.preventDefault(),$.ajax({type:"GET",url:"/admin",async:!1,username:"username",password:"password",headers:{Authorization:"Basic xxx"}}).fail(function(){window.location="/"}),!1}),$(document).pjax("a[data-pjax]","#content")}),$(document).on("ready pjax:end",function(){function a(){this.style.height="5px",this.style.height=this.scrollHeight+"px"}return $("#content").off(),document.title=document.getElementById("site-title").innerHTML,$("textarea").each(a),$("textarea").keyup(a),$(window).resize(function(){$("textarea").each(a)}),$("main").hasClass("browse")&&$(document).trigger("page:browse"),$(".editor")[0]&&$(document).trigger("page:editor"),!1}),$(document).on("page:browse",function(){var a="#foreground",b=new Object;b.selector="form#delete",b.form=$(b.selector),b.row="",b.button="",b.url="",$("#content").on("click",".delete",function(c){return c.preventDefault(),b.button=$(this),b.row=$(this).parent().parent(),$(a).fadeIn(200),b.url=b.row.find(".filename").text(),b.form.find("span").text(b.url),b.form.fadeIn(200),!1}),$("#content").on("submit",b.selector,function(c){c.preventDefault();var d=new XMLHttpRequest;return d.open("DELETE",b.button.data("file")),d.send(),d.onreadystatechange=function(){4==d.readyState&&(200==d.status?($(a).fadeOut(200),b.form.fadeOut(200),b.row.fadeOut(200),notification({text:b.button.data("message"),type:"success",timeout:5e3})):(notification({text:"Something went wrong.",type:"error"}),console.log(d.responseText)))},!1}),$("#content").on("change",'input[type="file"]',function(a){a.preventDefault(),files=a.target.files;var b=new FormData;return $.each(files,function(a,c){b.append(a,c)}),$.ajax({url:window.location.pathname,type:"POST",data:b,cache:!1,dataType:"json",headers:{"X-Upload":"true"},processData:!1,contentType:!1}).done(function(a){notification({text:"File(s) uploaded successfully.",type:"success",timeout:5e3}),$.pjax({url:window.location.pathname,container:"#content"})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("#content").on("click","#upload",function(a){return a.preventDefault(),$('.actions input[type="file"]').click(),!1});var c=new Object;c.selector="form#new",c.form=$(c.selector),c.input=c.selector+' input[type="text"]',c.button="",c.url="",$("#content").on("click",".new",function(b){return b.preventDefault(),c.button=$(this),$(a).fadeIn(200),c.form.fadeIn(200),!1}),$("#content").on("keypress",c.input,function(a){return 13==a.keyCode?(a.preventDefault(),$(c.form).submit(),!1):void 0}),$("#content").on("submit",c.selector,function(a){a.preventDefault();var b=c.form.find('input[type="text"]').val(),d=b.split(":"),e="",f="";if(""==b)return notification({text:"You have to write something. If you want to close the box, click the button again.",type:"warning",timeout:5e3}),!1;if(1==d.length)e=b;else{if(2!=d.length)return notification({text:"Hmm... I don't understand you. Try writing something like 'name[:archetype]'.",type:"error"}),!1;e=d[0],f=d[1]}var g={filename:e,archetype:f},h=new XMLHttpRequest;return h.open("POST",window.location.pathname),h.setRequestHeader("Content-Type","application/json;charset=UTF-8"),h.send(JSON.stringify(g)),h.onreadystatechange=function(){if(4==h.readyState)if(200==h.status){var a=JSON.parse(h.responseText);notification({text:"File created successfully.",type:"success",timeout:5e3}),$.pjax({url:a.Location,container:"#content"})}else notification({text:"Something went wrong.",type:"error"}),console.log(h.responseText)},!1});var d=new Object;d.selector="form#rename",d.form=$(d.selector),d.input=d.selector+' input[type="text"]',d.button="",d.url="",$("#content").on("click",".rename",function(b){return b.preventDefault(),d.button=$(this),$(a).fadeIn(200),d.url=$(this).parent().parent().find(".filename").text(),d.form.fadeIn(200),d.form.find("span").text(d.url),d.form.find('input[type="text"]').val(d.url),!1}),$("#content").on("keypress",d.input,function(a){return 13==a.keyCode?(a.preventDefault(),$(d.form).submit(),!1):void 0}),$("#content").on("submit",d.selector,function(a){a.preventDefault();var b=d.form.find('input[type="text"]').val();if(""===b)return!1;"/"!=b.substring(0,1)&&(b=window.location.pathname.replace("/admin/browse/","")+"/"+b);var c={filename:b},e=new XMLHttpRequest;return e.open("PUT",d.url),e.setRequestHeader("Content-Type","application/json;charset=UTF-8"),e.send(JSON.stringify(c)),e.onreadystatechange=function(){4==e.readyState&&(200==e.status?($.pjax({url:window.location.pathname,container:"#content"}),notification({text:d.button.data("message"),type:"success",timeout:5e3})):(notification({text:"Something went wrong.",type:"error"}),console.log(e.responseText)))},!1});var e=new Object;e.selector="form#git",e.form=$(e.selector),e.input=e.selector+' input[type="text"]',$("#content").on("click","button.git",function(b){return b.preventDefault(),$(a).fadeIn(200),e.form.fadeIn(200),!1}),$("#content"Line truncated
|
||||
+14
-5
@@ -312,14 +312,23 @@ $(document).on('page:browse', function() {
|
||||
}));
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState == 4) {
|
||||
var data = JSON.parse(request.responseText);
|
||||
var type = "success"
|
||||
var timeout = 5000
|
||||
|
||||
if (request.status == 200) {
|
||||
|
||||
} else {
|
||||
if (data.success == "false") {
|
||||
type = "error"
|
||||
timeout = false
|
||||
}
|
||||
|
||||
notification({
|
||||
text: 'Something went wrong.',
|
||||
type: 'error'
|
||||
text: data.message,
|
||||
type: type,
|
||||
timeout: timeout
|
||||
});
|
||||
console.log(request.responseText);
|
||||
} else {
|
||||
console.log(request.responseText)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,6 +25,6 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, e
|
||||
case "PUT":
|
||||
return PUT(w, r, c)
|
||||
default:
|
||||
return 400, errors.New("Invalid method.")
|
||||
return http.StatusMethodNotAllowed, errors.New("Invalid method.")
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -19,6 +19,6 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, e
|
||||
case "GET":
|
||||
return GET(w, r, c, filename)
|
||||
default:
|
||||
return 400, errors.New("Invalid method.")
|
||||
return http.StatusMethodNotAllowed, errors.New("Invalid method.")
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -13,6 +13,6 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, e
|
||||
case "POST":
|
||||
return POST(w, r, c)
|
||||
default:
|
||||
return 400, errors.New("Invalid method.")
|
||||
return http.StatusMethodNotAllowed, errors.New("Invalid method.")
|
||||
}
|
||||
}
|
||||
+59
-2
@@ -1,15 +1,72 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/config"
|
||||
)
|
||||
|
||||
// POST handles the POST method on GIT page which is only an API.
|
||||
func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
||||
if _, err := exec.LookPath("git"); err != nil {
|
||||
jsonMessage(w, "Git is not installed on your computer.", false)
|
||||
return 200, nil
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte("{}"))
|
||||
// Get the JSON information sent using a buffer
|
||||
buff := new(bytes.Buffer)
|
||||
buff.ReadFrom(r.Body)
|
||||
|
||||
// Creates the raw file "map" using the JSON
|
||||
var info map[string]interface{}
|
||||
json.Unmarshal(buff.Bytes(), &info)
|
||||
|
||||
if _, ok := info["command"]; !ok {
|
||||
jsonMessage(w, "Command not specified.", false)
|
||||
return 200, nil
|
||||
}
|
||||
|
||||
command := info["command"].(string)
|
||||
args := strings.Split(command, " ")
|
||||
|
||||
if len(args) > 0 && args[0] == "git" {
|
||||
args = append(args[:0], args[1:]...)
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
jsonMessage(w, "Command not specified.", false)
|
||||
return 200, nil
|
||||
}
|
||||
|
||||
cmd := exec.Command("git", args...)
|
||||
cmd.Dir = c.Path
|
||||
output, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
jsonMessage(w, err.Error(), false)
|
||||
return 200, nil
|
||||
}
|
||||
|
||||
jsonMessage(w, string(output), true)
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
|
||||
type jsonMSG struct {
|
||||
Message string `json:"message"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
func jsonMessage(w http.ResponseWriter, message string, success bool) {
|
||||
msg := &jsonMSG{
|
||||
Message: message,
|
||||
Success: success,
|
||||
}
|
||||
|
||||
m, _ := json.Marshal(msg)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(m)
|
||||
}
|
||||
Reference in new issue
Block a user