Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
095ba7820d | ||
|
|
96cce88aed | ||
|
|
baf739658e | ||
|
|
0c6d3a6c6a | ||
|
|
e8ea8d8abf | ||
|
|
79009305a1 | ||
|
|
03f5742a91 | ||
|
|
4ad68109d2 | ||
|
|
61f97f2f0a | ||
|
|
31ebc8ffbc | ||
|
|
567c74bb57 | ||
|
|
c4161c9db6 | ||
|
|
fd67e7033b |
@@ -20,6 +20,7 @@ var (
|
|||||||
OAuthServer string
|
OAuthServer string
|
||||||
VersionInterval time.Duration
|
VersionInterval time.Duration
|
||||||
ReadOnly bool
|
ReadOnly bool
|
||||||
|
MaxSizeMB int
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -38,6 +39,7 @@ func Refresh() {
|
|||||||
as.Append(args.STRING, "oauth", "oauth URL", "")
|
as.Append(args.STRING, "oauth", "oauth URL", "")
|
||||||
as.Append(args.DURATION, "version", "duration to mark versions", "0s")
|
as.Append(args.DURATION, "version", "duration to mark versions", "0s")
|
||||||
as.Append(args.BOOL, "ro", "read-only mode", false)
|
as.Append(args.BOOL, "ro", "read-only mode", false)
|
||||||
|
as.Append(args.INT, "max-v-size", "max size in mb for versioning", 2)
|
||||||
if err := as.Parse(); err != nil {
|
if err := as.Parse(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -67,6 +69,7 @@ func Refresh() {
|
|||||||
OAuthServer = as.GetString("oauth")
|
OAuthServer = as.GetString("oauth")
|
||||||
VersionInterval = as.GetDuration("version")
|
VersionInterval = as.GetDuration("version")
|
||||||
ReadOnly = as.GetBool("ro")
|
ReadOnly = as.GetBool("ro")
|
||||||
|
MaxSizeMB = as.GetInt("max-v-size")
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultWrapper = `
|
const defaultWrapper = `
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ func (s *Server) htmlAttachments(w http.ResponseWriter, urlPath string) {
|
|||||||
dir := path.Dir(urlPath)
|
dir := path.Dir(urlPath)
|
||||||
f := "." + path.Base(urlPath) + ".attachments"
|
f := "." + path.Base(urlPath) + ".attachments"
|
||||||
_, files, _ := s.Notes.Dir(path.Join(dir, f))
|
_, files, _ := s.Notes.Dir(path.Join(dir, f))
|
||||||
// TODO replace <a with <a download UNLESS img, then... hrm
|
|
||||||
form := fmt.Sprintf(`
|
form := fmt.Sprintf(`
|
||||||
<form enctype="multipart/form-data" action="/attach/%s" method="post">
|
<form enctype="multipart/form-data" action="/attach/%s" method="post">
|
||||||
<input type="file" name="file" required/>
|
<input type="file" name="file" required/>
|
||||||
|
|||||||
35
versions/max_file_size.go
Normal file
35
versions/max_file_size.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package versions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"local/notes-server/config"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getScript() string {
|
||||||
|
return strings.ReplaceAll(script, "{{{MAXSIZE}}}", fmt.Sprint(config.MaxSizeMB<<20))
|
||||||
|
}
|
||||||
|
|
||||||
|
const script = `
|
||||||
|
#!/bin/bash
|
||||||
|
function main() {
|
||||||
|
local maxsize={{{MAXSIZE}}}
|
||||||
|
if [[ "$maxsize" == 0 ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
(
|
||||||
|
git diff --name-only --cached
|
||||||
|
git diff --name-only
|
||||||
|
git ls-files --others --exclude-standard
|
||||||
|
) 2>&1 \
|
||||||
|
| sort -u \
|
||||||
|
| while read -r file; do
|
||||||
|
local size="$(du -sk "$file" | awk '{print $1}')000"
|
||||||
|
if [ "$size" -gt "$maxsize" ]; then
|
||||||
|
echo "file=$file, size=$size, max=$maxsize" >&2
|
||||||
|
git reset HEAD -- "$file"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
main
|
||||||
|
`
|
||||||
@@ -2,8 +2,13 @@ package versions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"local/notes-server/config"
|
"local/notes-server/config"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,7 +20,9 @@ func New() (*Versions, error) {
|
|||||||
v.cmd("git", "init")
|
v.cmd("git", "init")
|
||||||
v.cmd("git", "config", "user.email", "user@user.user")
|
v.cmd("git", "config", "user.email", "user@user.user")
|
||||||
v.cmd("git", "config", "user.name", "user")
|
v.cmd("git", "config", "user.name", "user")
|
||||||
return v, nil
|
s := getScript()
|
||||||
|
err := ioutil.WriteFile(path.Join(config.Root, "./.git/hooks/pre-commit"), []byte(s), os.ModePerm)
|
||||||
|
return v, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Versions) Gitmmit() error {
|
func (v *Versions) Gitmmit() error {
|
||||||
@@ -39,6 +46,9 @@ func (v *Versions) Commit() error {
|
|||||||
func (v *Versions) cmd(cmd string, args ...string) error {
|
func (v *Versions) cmd(cmd string, args ...string) error {
|
||||||
command := exec.Command(cmd, args...)
|
command := exec.Command(cmd, args...)
|
||||||
command.Dir = config.Root
|
command.Dir = config.Root
|
||||||
_, err := command.CombinedOutput()
|
out, err := command.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Println(cmd, args, ":", strings.TrimSpace(string(out)))
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user