mirror of
https://github.com/gtsteffaniak/filebrowser.git
synced 2026-11-26 00:19:41 -05:00
end day 11 march progresses on bug fix
This commit is contained in:
1 parent
063ff180f7
commit
3fd60e487a
6 files changed
+87
-43
No files matched your search
+1
-1
@@ -67,7 +67,7 @@ module.exports = function(grunt) {
|
||||
},
|
||||
main: {
|
||||
files: {
|
||||
'assets/public/js/app.min.js': ['assets/src/js/**/*.js']
|
||||
'assets/public/js/app.min.js': ['assets/public_src/js/**/*.js']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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(){if(4==d.readyState){var c=JSON.parse(d.responseText),e="success",f=5e3;$(a).fadeOut(200),b.form.fadeOut(200),b.row.fadeOut(200),200!=d.status&&(e="error",f=!1),notification({text:c.message,type:e,timeout:f})}},!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){var a=JSON.parse(h.responseText),b="success",c=5e3;200!=h.status&&(b="error",c=!1),notification({text:a.message,type:b,timeout:c}),200==h.status&&$.pjax({url:data.Location,container:"#content"})}},!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(){if(4==e.readyState){var a=JSON.parse(e.responseText),b="success",c=5e3;200!=e.status&&(b="error",c=!1),$.pjax({url:window.location.pathname,container:"#content"}),notification({text:a.message,type:b,timeout:c})}},!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").on("keypress",e.input,function(a){return 13==a.keyCode?(a.preventDefault(),$(e.form).submit(),!1):void 0}),$("#content").on("submit",e.selector,function(aLine 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(){if(4==d.readyState){var c=JSON.parse(d.responseText),e="success",f=5e3;$(a).fadeOut(200),b.form.fadeOut(200),b.row.fadeOut(200),200!=d.status&&(e="error",f=!1),notification({text:c.message,type:e,timeout:f})}},!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){var a=JSON.parse(h.responseText),b="success",c=5e3;200!=h.status&&(b="error",c=!1),notification({text:a.message,type:b,timeout:c}),200==h.status&&$.pjax({url:data.Location,container:"#content"})}},!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(){if(4==e.readyState){var a=JSON.parse(e.responseText),b="success",c=5e3;200!=e.status&&(b="error",c=!1),$.pjax({url:window.location.pathname,container:"#content"}),notification({text:a.message,type:b,timeout:c})}},!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").on("keypress",e.input,function(a){return 13==a.keyCode?(a.preventDefault(),$(e.form).submit(),!1):void 0}),$("#content").on("submit",e.selector,function(aLine truncated
|
||||
@@ -89,31 +89,38 @@ $(document).on('page:editor', function() {
|
||||
editor.fadeIn();
|
||||
}
|
||||
|
||||
var data = JSON.stringify($(this).serializeJSON()),
|
||||
button = $(this).find("input[type=submit]:focus");
|
||||
var button = $(this).find("input[type=submit]:focus");
|
||||
var data = {
|
||||
content: $(this).serializeJSON(),
|
||||
type: button.data("type"),
|
||||
schedule: button.data("schedule"),
|
||||
regenerate: button.data("regenerate")
|
||||
}
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
request.open("POST", window.location);
|
||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
request.setRequestHeader("X-Regenerate", button.data("regenerate"));
|
||||
request.setRequestHeader("X-Schedule", button.data("schedule"));
|
||||
request.setRequestHeader("X-Content-Type", button.data("type"));
|
||||
request.send(data);
|
||||
request.send(JSON.stringify(data));
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState == 4) {
|
||||
var response = JSON.parse(request.responseText),
|
||||
type = "success",
|
||||
timeout = 5000;
|
||||
|
||||
if (request.status == 200) {
|
||||
notification({
|
||||
text: button.data("message"),
|
||||
type: 'success',
|
||||
timeout: 5000
|
||||
});
|
||||
} else {
|
||||
notification({
|
||||
text: 'Something went wrong.',
|
||||
type: 'error'
|
||||
});
|
||||
console.log(request.responseText);
|
||||
response.message = button.data("message");
|
||||
}
|
||||
|
||||
if (request.status != 200) {
|
||||
type = "error";
|
||||
timeout = false;
|
||||
}
|
||||
|
||||
notification({
|
||||
text: response.message,
|
||||
type: type,
|
||||
timeout: timeout
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,10 @@
|
||||
{{ end }}
|
||||
|
||||
<p class="toolbar">
|
||||
<input type="submit" data-type="{{ .Class }}" data-message="{{ if eq .Class "frontmatter-only" }}The fields were put on their way.{{ else if eq .Class "content-only" }}Every byte was saved.{{ else }}Post saved with pomp and circumstance.{{ end }}" data-regenerate="false" value="Save">
|
||||
<input type="submit" data-type="{{ .Class }}" data-regenerate="false" data-schedule="false" data-message="{{ if eq .Class "frontmatter-only" }}The fields were put on their way.{{ else if eq .Class "content-only" }}Every byte was saved.{{ else }}Post saved with pomp and circumstance.{{ end }}" value="Save">
|
||||
<span class="right">
|
||||
{{ if and (eq .Class "complete") ( .IsPost ) }}<input type="submit" data-type="{{ .Class }}" data-message="Post scheduled." data-schedule="true" value="Schedule"> {{ end }}
|
||||
<input type="submit" data-type="{{ .Class }}" data-message="{{ if eq .Class "frontmatter-only" }}Saved and regenerated.{{ else if eq .Class "content-only" }}Done. What do you want more?{{ else }}Post published. Go and share it!{{ end }}" data-regenerate="true" class="default" value="Publish">
|
||||
{{ if and (eq .Class "complete") ( .IsPost ) }}<input type="submit" data-type="{{ .Class }}" data-schedule="true" data-regenerate="false" data-message="Post scheduled." value="Schedule"> {{ end }}
|
||||
<input type="submit" data-type="{{ .Class }}" data-regenerate="true" data-schedule="true" data-message="{{ if eq .Class "frontmatter-only" }}Saved and regenerated.{{ else if eq .Class "content-only" }}Done. What do you want more?{{ else }}Post published. Go and share it!{{ end }}" class="default" value="Publish">
|
||||
</span>
|
||||
</p>
|
||||
</main>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:generate go get github.com/jteeuwen/go-bindata
|
||||
//go:generate go install github.com/jteeuwen/go-bindata/go-bindata
|
||||
//go:generate go-bindata -prefix assets/ -pkg assets -o routes/assets/assets.go assets/templates/ assets/public/...
|
||||
//go:generate go-bindata -debug -prefix assets/ -pkg assets -o routes/assets/assets.go assets/templates/ assets/public/...
|
||||
|
||||
// Package hugo makes the bridge between the static website generator Hugo
|
||||
// and the webserver Caddy, also providing an administrative user interface.
|
||||
@@ -143,15 +143,9 @@ func (h CaddyHugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
|
||||
code, err = git.ServeHTTP(w, r, h.Config)
|
||||
}
|
||||
|
||||
// Whenever the header "X-Regenerate" is true, the website should be
|
||||
// regenerated. Used in edit and settings, for example.
|
||||
if r.Header.Get("X-Regenerate") == "true" {
|
||||
go hugo.Run(h.Config, false)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
/* if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
} */
|
||||
|
||||
/*
|
||||
|
||||
|
||||
+55
-12
@@ -12,29 +12,64 @@ import (
|
||||
|
||||
"github.com/hacdias/caddy-hugo/config"
|
||||
"github.com/hacdias/caddy-hugo/tools/hugo"
|
||||
"github.com/hacdias/caddy-hugo/tools/server"
|
||||
"github.com/robfig/cron"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/spf13/hugo/parser"
|
||||
)
|
||||
|
||||
var schedule, contentType, regenerate string
|
||||
|
||||
// POST handles the POST method on editor page
|
||||
func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename string) (int, error) {
|
||||
// Get the JSON information sent using a buffer
|
||||
rawBuffer := new(bytes.Buffer)
|
||||
rawBuffer.ReadFrom(r.Body)
|
||||
|
||||
// Creates the raw file "map" using the JSON
|
||||
var rawFile map[string]interface{}
|
||||
json.Unmarshal(rawBuffer.Bytes(), &rawFile)
|
||||
// Creates the data map using the JSON
|
||||
var data map[string]interface{}
|
||||
json.Unmarshal(rawBuffer.Bytes(), &data)
|
||||
|
||||
// Checks if all the all data is defined
|
||||
if _, ok := data["type"]; !ok {
|
||||
return server.RespondJSON(w, map[string]string{
|
||||
"message": "Content type not set.",
|
||||
}, http.StatusBadRequest, nil)
|
||||
}
|
||||
|
||||
if _, ok := data["content"]; !ok {
|
||||
return server.RespondJSON(w, map[string]string{
|
||||
"message": "Content not sent.",
|
||||
}, http.StatusBadRequest, nil)
|
||||
}
|
||||
|
||||
if _, ok := data["schedule"]; !ok {
|
||||
return server.RespondJSON(w, map[string]string{
|
||||
"message": "Schedule information not sent.",
|
||||
}, http.StatusBadRequest, nil)
|
||||
}
|
||||
|
||||
if _, ok := data["regenerate"]; !ok {
|
||||
return server.RespondJSON(w, map[string]string{
|
||||
"message": "Regenerate information not sent.",
|
||||
}, http.StatusBadRequest, nil)
|
||||
}
|
||||
|
||||
rawFile := data["content"].(map[string]interface{})
|
||||
contentType = data["type"].(string)
|
||||
schedule = data["schedule"].(string)
|
||||
regenerate = data["regenerate"].(string)
|
||||
|
||||
// Initializes the file content to write
|
||||
var file []byte
|
||||
|
||||
switch r.Header.Get("X-Content-Type") {
|
||||
switch contentType {
|
||||
case "frontmatter-only":
|
||||
f, code, err := parseFrontMatterOnlyFile(rawFile, filename)
|
||||
if err != nil {
|
||||
return code, err
|
||||
return server.RespondJSON(w, map[string]string{
|
||||
"message": err.Error(),
|
||||
}, code, err)
|
||||
}
|
||||
|
||||
file = f
|
||||
@@ -47,24 +82,32 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
|
||||
case "complete":
|
||||
f, code, err := parseCompleteFile(r, c, rawFile, filename)
|
||||
if err != nil {
|
||||
return code, err
|
||||
return server.RespondJSON(w, map[string]string{
|
||||
"message": err.Error(),
|
||||
}, code, err)
|
||||
}
|
||||
|
||||
file = f
|
||||
default:
|
||||
return http.StatusBadRequest, errors.New("X-Content-Type header not defined")
|
||||
return server.RespondJSON(w, map[string]string{
|
||||
"message": "Invalid content type.",
|
||||
}, http.StatusBadRequest, nil)
|
||||
}
|
||||
|
||||
// Write the file
|
||||
err := ioutil.WriteFile(filename, file, 0666)
|
||||
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
return server.RespondJSON(w, map[string]string{
|
||||
"message": err.Error(),
|
||||
}, http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte("{}"))
|
||||
return http.StatusOK, nil
|
||||
if regenerate == "true" {
|
||||
go hugo.Run(c, false)
|
||||
}
|
||||
|
||||
return server.RespondJSON(w, map[string]string{}, http.StatusOK, nil)
|
||||
}
|
||||
|
||||
func parseFrontMatterOnlyFile(rawFile map[string]interface{}, filename string) ([]byte, int, error) {
|
||||
@@ -114,7 +157,7 @@ func parseCompleteFile(r *http.Request, c *config.Config, rawFile map[string]int
|
||||
delete(rawFile, "content")
|
||||
|
||||
// Schedule the post
|
||||
if r.Header.Get("X-Schedule") == "true" {
|
||||
if schedule == "true" {
|
||||
t := cast.ToTime(rawFile["date"].(string))
|
||||
|
||||
scheduler := cron.New()
|
||||
|
||||
Reference in new issue
Block a user