Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c3a508b84 | ||
|
|
6733ccd4b8 | ||
|
|
2f0c09ff72 | ||
|
|
ff3ed3a57e |
@@ -61,6 +61,18 @@ func ToStrArr(k string) []string {
|
||||
}
|
||||
|
||||
func ToTime(s string) time.Time {
|
||||
v, _ := time.Parse("2006-01-02 15:04:05", s)
|
||||
v, err := time.Parse("2006-01-02 15:04:05", s)
|
||||
if err != nil || v.IsZero() {
|
||||
v, err = time.Parse("2006-01-02", s)
|
||||
}
|
||||
if err != nil || v.IsZero() {
|
||||
v, err = time.Parse("1/2/06", s)
|
||||
}
|
||||
if err != nil || v.IsZero() {
|
||||
v, err = time.Parse("02 Jan 2006 3:04 PM", s)
|
||||
}
|
||||
if err != nil || v.IsZero() {
|
||||
v, err = time.Parse("02 Jan 2006 3:04 PM", strings.ReplaceAll(s, "+", " "))
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -79,6 +79,18 @@ func TestToTime(t *testing.T) {
|
||||
in: "5",
|
||||
out: "0001-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
in: "1/2/03",
|
||||
out: "2003-01-02 00:00:00",
|
||||
},
|
||||
{
|
||||
in: "11/12/03",
|
||||
out: "2003-11-12 00:00:00",
|
||||
},
|
||||
{
|
||||
in: "01+Jan+2020+12:00+PM",
|
||||
out: "2020-01-01 12:00:00",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
|
||||
@@ -94,6 +94,7 @@ func (a *Ajax) storageListTasks(listID string, filters ...func(t *task.Task) boo
|
||||
}
|
||||
}
|
||||
if filtered {
|
||||
//task.Title = fmt.Sprintf("[%d] %s", task.Index, task.Title)
|
||||
tasks = append(tasks, task)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ func filterTags(tags []string) func(t *task.Task) bool {
|
||||
|
||||
func filterSubstr(substr string) func(t *task.Task) bool {
|
||||
return func(t *task.Task) bool {
|
||||
return substr == "" || strings.Contains(fmt.Sprintf("%+v", t), substr)
|
||||
found := substr == "" || strings.Contains(fmt.Sprintf("%+v %+v", t.Title, t.Tags), substr)
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ func New(r *http.Request) (*Task, error) {
|
||||
UUID: form.NewUUID(),
|
||||
Title: form.Get(r, "title"),
|
||||
Priority: form.ToInt(form.Get(r, "prio")),
|
||||
Tags: StrList(form.ToStrArr(form.Get(r, "tags"))),
|
||||
Tags: append(StrList(form.ToStrArr(form.Get(r, "tag"))), StrList(form.ToStrArr(form.Get(r, "tags")))...),
|
||||
Created: time.Now(),
|
||||
Edited: time.Now(),
|
||||
|
||||
@@ -110,6 +110,13 @@ func (t *Task) MarshalJSON() ([]byte, error) {
|
||||
"dueInt": t.Due.Unix(),
|
||||
"dueTitle": "Due ",
|
||||
}
|
||||
if t.Due.IsZero() {
|
||||
for k := range m {
|
||||
if strings.HasPrefix(k, "due") {
|
||||
delete(m, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
if t.Complete {
|
||||
m["dateCompleted"] = t.Completed.Format(fullFormat)
|
||||
m["dateCompletedInline"] = t.Completed.Format(shortFormat)
|
||||
|
||||
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"local/gziphttp"
|
||||
"local/router"
|
||||
"local/todo-server/config"
|
||||
"log"
|
||||
@@ -20,78 +21,20 @@ func (s *Server) Routes() error {
|
||||
}{
|
||||
{
|
||||
path: "/",
|
||||
handler: s.index,
|
||||
handler: s.gzip(s.index),
|
||||
},
|
||||
{
|
||||
path: "/mytinytodo_lang.php",
|
||||
handler: s.lang,
|
||||
handler: s.gzip(s.lang),
|
||||
},
|
||||
{
|
||||
path: fmt.Sprintf("%s%s", router.Wildcard, router.Wildcard),
|
||||
handler: s.phpProxy,
|
||||
handler: s.gzip(s.phpProxy),
|
||||
},
|
||||
{
|
||||
path: "/ajax.php",
|
||||
handler: s.HandleAjax,
|
||||
handler: s.gzip(s.HandleAjax),
|
||||
},
|
||||
/*
|
||||
{
|
||||
path: "db/index.html",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "jquery/index.html",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "lang/index.html",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "themes/index.html",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "tmp/index.html",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "jquery/jquery-1.4.4.min.js",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "jquery/jquery-ui-1.8.7.custom.min.js",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "jquery/jquery.autocomplete-1.1.js",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "mytinytodo.js",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "mytinytodo_ajax_storage.js",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "testdata/mytinytodo2/themes/default/pda.css",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "testdata/mytinytodo2/themes/default/print.css",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "testdata/mytinytodo2/themes/default/style.css",
|
||||
handler: s.static,
|
||||
},
|
||||
{
|
||||
path: "testdata/mytinytodo2/themes/default/style_rtl.css",
|
||||
handler: s.static,
|
||||
},
|
||||
*/
|
||||
}
|
||||
|
||||
for _, route := range routes {
|
||||
@@ -152,7 +95,8 @@ func (s *Server) phpProxy(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
log.Println("proxying", url.String(), r.URL.Path)
|
||||
log.Println("WOULD proxy", url.String(), r.URL.Path)
|
||||
s.index(w, r)
|
||||
//proxy := httputil.NewSingleHostReverseProxy(url)
|
||||
//proxy.ServeHTTP(w, r)
|
||||
}
|
||||
@@ -161,3 +105,17 @@ func (s *Server) phpProxy(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *Server) static(w http.ResponseWriter, r *http.Request) {
|
||||
s.fileServer.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (s *Server) gzip(h http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if gziphttp.Can(r) {
|
||||
gz := gziphttp.New(w)
|
||||
defer gz.Close()
|
||||
w = gz
|
||||
}
|
||||
if filepath.Ext(r.URL.Path) == ".css" {
|
||||
w.Header().Set("Content-Type", "text/css; charset=utf-8")
|
||||
}
|
||||
h(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user