13 Commits
v1.13 ... v1.15

Author SHA1 Message Date
Bel LaPointe
095ba7820d jsut in case 2021-02-25 22:17:32 -06:00
Bel LaPointe
96cce88aed no more todo 2021-02-25 22:10:18 -06:00
Bel LaPointe
baf739658e create pre-commit file to skip big files 2021-02-25 22:09:50 -06:00
Bel LaPointe
0c6d3a6c6a script 2021-02-25 21:53:48 -06:00
Bel LaPointe
e8ea8d8abf try 2021-02-25 20:56:07 -06:00
Bel LaPointe
79009305a1 mm 2021-02-25 20:46:50 -06:00
Bel LaPointe
03f5742a91 grrr 2021-02-25 20:46:19 -06:00
Bel LaPointe
4ad68109d2 gr 2021-02-25 20:34:53 -06:00
Bel LaPointe
61f97f2f0a big 2021-02-25 20:34:08 -06:00
Bel LaPointe
31ebc8ffbc big 2021-02-25 20:33:45 -06:00
Bel LaPointe
567c74bb57 big file 2021-02-25 20:33:30 -06:00
Bel LaPointe
c4161c9db6 big file 2021-02-25 20:32:54 -06:00
Bel LaPointe
fd67e7033b making a big file 2021-02-25 20:19:44 -06:00
4 changed files with 50 additions and 3 deletions

View File

@@ -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 = `

View File

@@ -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
View 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
`

View File

@@ -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
} }