diff --git a/server/notes.go b/server/notes.go
index 48efd6d..6eadf03 100755
--- a/server/notes.go
+++ b/server/notes.go
@@ -4,8 +4,10 @@ import (
"fmt"
"local/notes-server/config"
"local/notes-server/filetree"
+ "log"
"net/http"
"path"
+ "regexp"
"strings"
)
@@ -83,7 +85,7 @@ func (s *Server) htmlAttachments(w http.ResponseWriter, urlPath string) {
dir := path.Dir(urlPath)
f := "." + path.Base(urlPath) + ".attachments"
_, files, _ := s.Notes.Dir(path.Join(dir, f))
- // TODO: direct DL via link
+ // TODO replace
@@ -93,6 +95,16 @@ func (s *Server) htmlAttachments(w http.ResponseWriter, urlPath string) {
if config.ReadOnly {
form = ""
}
+ lines := strings.Split(files, "\n")
+ for i := range lines {
+ pattern := regexp.MustCompile(`\.(png|jpg|jpeg|gif)">`)
+ if !pattern.MatchString(lines[i]) {
+ lines[i] = strings.ReplaceAll(lines[i], "
diff --git a/server/raw.go b/server/raw.go
new file mode 100755
index 0000000..655a23b
--- /dev/null
+++ b/server/raw.go
@@ -0,0 +1,33 @@
+package server
+
+import (
+ "io"
+ "local/notes-server/filetree"
+ "local/simpleserve/simpleserve"
+ "net/http"
+ "os"
+)
+
+func (s *Server) raw(w http.ResponseWriter, r *http.Request) {
+ if err := s._raw(w, r); err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ }
+}
+
+func (s *Server) _raw(w http.ResponseWriter, r *http.Request) error {
+ simpleserve.SetContentTypeIfMedia(w, r)
+ p := filetree.NewPathFromURL(r.URL.Path)
+ if !p.IsFile() {
+ http.NotFound(w, r)
+ return nil
+ }
+ f, err := os.Open(p.Local)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+ if _, err := io.Copy(w, f); err != nil {
+ return err
+ }
+ return nil
+}
diff --git a/server/routes.go b/server/routes.go
index c075401..d110a59 100755
--- a/server/routes.go
+++ b/server/routes.go
@@ -18,6 +18,9 @@ func (s *Server) Routes() error {
"/": {
handler: s.root,
},
+ fmt.Sprintf("raw/%s%s", wildcard, wildcard): {
+ handler: s.gzip(s.authenticate(s.raw)),
+ },
fmt.Sprintf("notes/%s%s", wildcard, wildcard): {
handler: s.gzip(s.authenticate(s.notes)),
},