From fb407bcbce92f4eddc6756665dd35897edbdfd5c Mon Sep 17 00:00:00 2001
From: jolheiser
Date: Fri, 16 Jun 2023 11:08:33 -0500
Subject: [PATCH 01/32] feat: non-cgo sqlite
Signed-off-by: jolheiser
---
go.mod | 21 ++++++++++++++---
go.sum | 55 ++++++++++++++++++++++++++++++++++---------
internal/models/db.go | 11 +++++----
3 files changed, 68 insertions(+), 19 deletions(-)
diff --git a/go.mod b/go.mod
index a68dfe1..11bbacf 100644
--- a/go.mod
+++ b/go.mod
@@ -3,21 +3,23 @@ module github.com/thomiceli/opengist
go 1.19
require (
+ github.com/glebarez/sqlite v1.8.0
github.com/go-playground/validator/v10 v10.11.0
github.com/google/uuid v1.3.0
github.com/gorilla/sessions v1.2.1
github.com/labstack/echo/v4 v4.10.0
github.com/markbates/goth v1.77.0
- github.com/mattn/go-sqlite3 v1.14.13
github.com/rs/zerolog v1.29.0
golang.org/x/crypto v0.2.0
golang.org/x/text v0.7.0
gopkg.in/yaml.v3 v3.0.1
- gorm.io/driver/sqlite v1.3.2
- gorm.io/gorm v1.23.5
+ gorm.io/gorm v1.24.6
+ modernc.org/sqlite v1.21.1
)
require (
+ github.com/dustin/go-humanize v1.0.1 // indirect
+ github.com/glebarez/go-sqlite v1.21.1 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
@@ -27,16 +29,29 @@ require (
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
+ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
+ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
+ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/time v0.2.0 // indirect
+ golang.org/x/tools v0.1.12 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.25.0 // indirect
+ lukechampine.com/uint128 v1.2.0 // indirect
+ modernc.org/cc/v3 v3.40.0 // indirect
+ modernc.org/ccgo/v3 v3.16.13 // indirect
+ modernc.org/libc v1.22.3 // indirect
+ modernc.org/mathutil v1.5.0 // indirect
+ modernc.org/memory v1.5.0 // indirect
+ modernc.org/opt v0.1.3 // indirect
+ modernc.org/strutil v1.1.3 // indirect
+ modernc.org/token v1.0.1 // indirect
)
diff --git a/go.sum b/go.sum
index 75daec6..407b717 100644
--- a/go.sum
+++ b/go.sum
@@ -47,10 +47,16 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.0-20210816181553-5444fa50b93d/go.mod h1:tmAIfUFEirG/Y8jhZ9M+h36obRZAk/1fcSpXwAVlfqE=
+github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
+github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
+github.com/glebarez/go-sqlite v1.21.1 h1:7MZyUPh2XTrHS7xNEHQbrhfMZuPSzhkm2A1qgg0y5NY=
+github.com/glebarez/go-sqlite v1.21.1/go.mod h1:ISs8MF6yk5cL4n/43rSOmVMGJJjHYr7L2MbZZ5Q4E2E=
+github.com/glebarez/sqlite v1.8.0 h1:02X12E2I/4C1n+v90yTqrjRa8yuo7c3KeHI3FRznCvc=
+github.com/glebarez/sqlite v1.8.0/go.mod h1:bpET16h1za2KOOMb8+jCp6UBP/iahDpfPQqSaYLTLx8=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@@ -101,8 +107,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
@@ -113,6 +119,7 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/google/pprof v0.0.0-20200905233945-acf8798be1f7/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
+github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -134,11 +141,12 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/jarcoal/httpmock v0.0.0-20180424175123-9c70cfe4a1da/go.mod h1:ks+b9deReOc7jgqp+e7LuFiCBH6Rm5hL32cLcEAArb4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
-github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
+github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
+github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -171,15 +179,16 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
-github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
-github.com/mattn/go-sqlite3 v1.14.13 h1:1tj15ngiFfcZzii7yd82foL+ks+ouQcj8j/TPq3fk1I=
-github.com/mattn/go-sqlite3 v1.14.13/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
+github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mrjones/oauth v0.0.0-20180629183705-f4e24b6d100c/go.mod h1:skjdDftzkFALcuGzYSklqYd8gvat6F1gZJ4YPVbkZpM=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
+github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
+github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
+github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
@@ -247,6 +256,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
+golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -386,10 +397,11 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
golang.org/x/tools v0.0.0-20200929161345-d7fc70abf50f/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
+golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
+golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
@@ -481,11 +493,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gorm.io/driver/sqlite v1.3.2 h1:nWTy4cE52K6nnMhv23wLmur9Y3qWbZvOBz+V4PrGAxg=
-gorm.io/driver/sqlite v1.3.2/go.mod h1:B+8GyC9K7VgzJAcrcXMRPdnMcck+8FgJynEehEPM16U=
-gorm.io/gorm v1.23.4/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
-gorm.io/gorm v1.23.5 h1:TnlF26wScKSvknUC/Rn8t0NLLM22fypYBlvj1+aH6dM=
-gorm.io/gorm v1.23.5/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
+gorm.io/gorm v1.24.6 h1:wy98aq9oFEetsc4CAbKD2SoBCdMzsbSIvSUUFJuHi5s=
+gorm.io/gorm v1.24.6/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
@@ -493,6 +502,30 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
+lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
+lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
+modernc.org/cc/v3 v3.40.0 h1:P3g79IUS/93SYhtoeaHW+kRCIrYaxJ27MFPv+7kaTOw=
+modernc.org/cc/v3 v3.40.0/go.mod h1:/bTg4dnWkSXowUO6ssQKnOV0yMVxDYNIsIrzqTFDGH0=
+modernc.org/ccgo/v3 v3.16.13 h1:Mkgdzl46i5F/CNR/Kj80Ri59hC8TKAhZrYSaqvkwzUw=
+modernc.org/ccgo/v3 v3.16.13/go.mod h1:2Quk+5YgpImhPjv2Qsob1DnZ/4som1lJTodubIcoUkY=
+modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
+modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
+modernc.org/libc v1.22.3 h1:D/g6O5ftAfavceqlLOFwaZuA5KYafKwmr30A6iSqoyY=
+modernc.org/libc v1.22.3/go.mod h1:MQrloYP209xa2zHome2a8HLiLm6k0UT8CoHpV74tOFw=
+modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
+modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
+modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
+modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
+modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
+modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
+modernc.org/sqlite v1.21.1 h1:GyDFqNnESLOhwwDRaHGdp2jKLDzpyT/rNLglX3ZkMSU=
+modernc.org/sqlite v1.21.1/go.mod h1:XwQ0wZPIh1iKb5mkvCJ3szzbhk+tykC8ZWqTRTgYRwI=
+modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
+modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
+modernc.org/tcl v1.15.1 h1:mOQwiEK4p7HruMZcwKTZPw/aqtGM4aY00uzWhlKKYws=
+modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg=
+modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
+modernc.org/z v1.7.0 h1:xkDw/KepgEjeizO2sNco+hqYkU12taxQFqPEmgm1GWE=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
diff --git a/internal/models/db.go b/internal/models/db.go
index a3fc124..cfd7370 100644
--- a/internal/models/db.go
+++ b/internal/models/db.go
@@ -2,14 +2,15 @@ package models
import (
"errors"
- "github.com/mattn/go-sqlite3"
+ "strings"
+
+ "github.com/glebarez/sqlite"
"github.com/rs/zerolog/log"
"github.com/thomiceli/opengist/internal/config"
"github.com/thomiceli/opengist/internal/utils"
- "gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
- "strings"
+ msqlite "modernc.org/sqlite"
)
var db *gorm.DB
@@ -50,8 +51,8 @@ func CountAll(table interface{}) (int64, error) {
}
func IsUniqueConstraintViolation(err error) bool {
- var sqliteErr sqlite3.Error
- if errors.As(err, &sqliteErr) && sqliteErr.ExtendedCode == sqlite3.ErrConstraintUnique {
+ var sqliteErr *msqlite.Error
+ if errors.As(err, &sqliteErr) && sqliteErr.Code() == 2067 {
return true
}
return false
From af3aab21e3233cc188888e58d0fe05d558e9414d Mon Sep 17 00:00:00 2001
From: jolheiser
Date: Fri, 16 Jun 2023 11:13:25 -0500
Subject: [PATCH 02/32] chore: use glebarez mirror
Signed-off-by: jolheiser
---
go.mod | 14 +++-----------
go.sum | 24 +-----------------------
internal/models/db.go | 2 +-
3 files changed, 5 insertions(+), 35 deletions(-)
diff --git a/go.mod b/go.mod
index 11bbacf..be5ab58 100644
--- a/go.mod
+++ b/go.mod
@@ -3,6 +3,7 @@ module github.com/thomiceli/opengist
go 1.19
require (
+ github.com/glebarez/go-sqlite v1.21.1
github.com/glebarez/sqlite v1.8.0
github.com/go-playground/validator/v10 v10.11.0
github.com/google/uuid v1.3.0
@@ -14,22 +15,20 @@ require (
golang.org/x/text v0.7.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/gorm v1.24.6
- modernc.org/sqlite v1.21.1
)
require (
github.com/dustin/go-humanize v1.0.1 // indirect
- github.com/glebarez/go-sqlite v1.21.1 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.4.2 // indirect
+ github.com/google/go-cmp v0.5.9 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/mux v1.6.2 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
- github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
@@ -37,21 +36,14 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
- golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/time v0.2.0 // indirect
- golang.org/x/tools v0.1.12 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.25.0 // indirect
- lukechampine.com/uint128 v1.2.0 // indirect
- modernc.org/cc/v3 v3.40.0 // indirect
- modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.22.3 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
- modernc.org/opt v0.1.3 // indirect
- modernc.org/strutil v1.1.3 // indirect
- modernc.org/token v1.0.1 // indirect
+ modernc.org/sqlite v1.21.1 // indirect
)
diff --git a/go.sum b/go.sum
index 407b717..d555a3b 100644
--- a/go.sum
+++ b/go.sum
@@ -109,6 +109,7 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
+github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
@@ -145,8 +146,6 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
-github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
-github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -179,7 +178,6 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
-github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mrjones/oauth v0.0.0-20180629183705-f4e24b6d100c/go.mod h1:skjdDftzkFALcuGzYSklqYd8gvat6F1gZJ4YPVbkZpM=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -256,8 +254,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
-golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -397,8 +393,6 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
golang.org/x/tools v0.0.0-20200929161345-d7fc70abf50f/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
-golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
-golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -502,30 +496,14 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
-lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
-lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
-modernc.org/cc/v3 v3.40.0 h1:P3g79IUS/93SYhtoeaHW+kRCIrYaxJ27MFPv+7kaTOw=
-modernc.org/cc/v3 v3.40.0/go.mod h1:/bTg4dnWkSXowUO6ssQKnOV0yMVxDYNIsIrzqTFDGH0=
-modernc.org/ccgo/v3 v3.16.13 h1:Mkgdzl46i5F/CNR/Kj80Ri59hC8TKAhZrYSaqvkwzUw=
-modernc.org/ccgo/v3 v3.16.13/go.mod h1:2Quk+5YgpImhPjv2Qsob1DnZ/4som1lJTodubIcoUkY=
-modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
-modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
modernc.org/libc v1.22.3 h1:D/g6O5ftAfavceqlLOFwaZuA5KYafKwmr30A6iSqoyY=
modernc.org/libc v1.22.3/go.mod h1:MQrloYP209xa2zHome2a8HLiLm6k0UT8CoHpV74tOFw=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
-modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
-modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/sqlite v1.21.1 h1:GyDFqNnESLOhwwDRaHGdp2jKLDzpyT/rNLglX3ZkMSU=
modernc.org/sqlite v1.21.1/go.mod h1:XwQ0wZPIh1iKb5mkvCJ3szzbhk+tykC8ZWqTRTgYRwI=
-modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
-modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
-modernc.org/tcl v1.15.1 h1:mOQwiEK4p7HruMZcwKTZPw/aqtGM4aY00uzWhlKKYws=
-modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg=
-modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
-modernc.org/z v1.7.0 h1:xkDw/KepgEjeizO2sNco+hqYkU12taxQFqPEmgm1GWE=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
diff --git a/internal/models/db.go b/internal/models/db.go
index cfd7370..b97fd4c 100644
--- a/internal/models/db.go
+++ b/internal/models/db.go
@@ -4,13 +4,13 @@ import (
"errors"
"strings"
+ msqlite "github.com/glebarez/go-sqlite"
"github.com/glebarez/sqlite"
"github.com/rs/zerolog/log"
"github.com/thomiceli/opengist/internal/config"
"github.com/thomiceli/opengist/internal/utils"
"gorm.io/gorm"
"gorm.io/gorm/logger"
- msqlite "modernc.org/sqlite"
)
var db *gorm.DB
From 89685bfac61f9e272ca952c19bcb3b7620781393 Mon Sep 17 00:00:00 2001
From: Thomas Miceli
Date: Wed, 26 Jul 2023 10:54:16 +0200
Subject: [PATCH 03/32] Remove CONFIG env var
---
internal/config/config.go | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/internal/config/config.go b/internal/config/config.go
index c1c3745..27dd9d2 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -15,7 +15,7 @@ import (
"gopkg.in/yaml.v3"
)
-var OpengistVersion = "1.4.2"
+var OpengistVersion = "1.5-dev"
var C *config
@@ -175,17 +175,6 @@ func loadConfigFromYaml(c *config, configPath string) error {
fmt.Println("No YAML config file specified.")
}
- // Override default values with environment variables (as yaml)
- configEnv := os.Getenv("CONFIG")
- if configEnv != "" {
- fmt.Println("Using config from environment variable: CONFIG")
- fmt.Println("!! This method of setting the config is deprecated and will be removed in a future version of Opengist")
- d := yaml.NewDecoder(strings.NewReader(configEnv))
- if err := d.Decode(&c); err != nil {
- return err
- }
- }
-
return nil
}
From b5cd49db4c4bc1f4c4c339230c2a36cb20965624 Mon Sep 17 00:00:00 2001
From: Thomas Miceli <27960254+thomiceli@users.noreply.github.com>
Date: Wed, 26 Jul 2023 15:43:07 +0200
Subject: [PATCH 04/32] Download file, button groups, fix unknown file reading
(#84)
---
internal/git/commands.go | 12 ++++++++++--
internal/web/gist.go | 24 ++++++++++++++++++++++++
internal/web/run.go | 1 +
public/main.ts | 2 +-
templates/pages/gist.html | 28 ++++++++++++++++++++++------
5 files changed, 58 insertions(+), 9 deletions(-)
diff --git a/internal/git/commands.go b/internal/git/commands.go
index b3cc687..c93b70f 100644
--- a/internal/git/commands.go
+++ b/internal/git/commands.go
@@ -99,9 +99,17 @@ func GetFileContent(user string, gist string, revision string, filename string,
if err != nil {
return "", false, err
}
- defer cmd.Wait()
- return truncateCommandOutput(stdout, maxBytes)
+ output, truncated, err := truncateCommandOutput(stdout, maxBytes)
+ if err != nil {
+ return "", false, err
+ }
+
+ if err := cmd.Wait(); err != nil {
+ return "", false, err
+ }
+
+ return output, truncated, nil
}
func GetLog(user string, gist string, skip int) ([]*Commit, error) {
diff --git a/internal/web/gist.go b/internal/web/gist.go
index e3e1d67..6080fde 100644
--- a/internal/web/gist.go
+++ b/internal/web/gist.go
@@ -517,6 +517,30 @@ func rawFile(ctx echo.Context) error {
return plainText(ctx, 200, file.Content)
}
+func downloadFile(ctx echo.Context) error {
+ gist := getData(ctx, "gist").(*models.Gist)
+ file, err := gist.File(ctx.Param("revision"), ctx.Param("file"), false)
+
+ if err != nil {
+ return errorRes(500, "Error getting file content", err)
+ }
+
+ if file == nil {
+ return notFound("File not found")
+ }
+
+ ctx.Response().Header().Set("Content-Type", "text/plain")
+ ctx.Response().Header().Set("Content-Disposition", "attachment; filename="+file.Filename)
+ ctx.Response().Header().Set("Content-Length", strconv.Itoa(len(file.Content)))
+ _, err = ctx.Response().Write([]byte(file.Content))
+
+ if err != nil {
+ return errorRes(500, "Error downloading the file", err)
+ }
+
+ return nil
+}
+
func edit(ctx echo.Context) error {
var gist = getData(ctx, "gist").(*models.Gist)
diff --git a/internal/web/run.go b/internal/web/run.go
index 0d92733..14e8b9c 100644
--- a/internal/web/run.go
+++ b/internal/web/run.go
@@ -213,6 +213,7 @@ func Start() {
g3.POST("/visibility", toggleVisibility, logged, writePermission)
g3.POST("/delete", deleteGist, logged, writePermission)
g3.GET("/raw/:revision/:file", rawFile)
+ g3.GET("/download/:revision/:file", downloadFile)
g3.GET("/edit", edit, logged, writePermission)
g3.POST("/edit", processCreate, logged, writePermission)
g3.POST("/like", like, logged)
diff --git a/public/main.ts b/public/main.ts
index 8992039..c354e35 100644
--- a/public/main.ts
+++ b/public/main.ts
@@ -178,7 +178,7 @@ document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.copy-gist-btn').forEach((e: HTMLElement) => {
e.onclick = () => {
- navigator.clipboard.writeText(e.parentNode!.querySelector('.gist-content')!.textContent || '').catch((err) => {
+ navigator.clipboard.writeText(e.parentNode!.parentNode!.querySelector('.gist-content')!.textContent || '').catch((err) => {
console.error('Could not copy text: ', err);
});
};
diff --git a/templates/pages/gist.html b/templates/pages/gist.html
index e72cdf9..ff5932a 100644
--- a/templates/pages/gist.html
+++ b/templates/pages/gist.html
@@ -7,13 +7,29 @@
{{ if $file.Truncated }}
From 4f623881acc76ce9c27868d80ae7320387ac8425 Mon Sep 17 00:00:00 2001
From: joe
Date: Sat, 12 Aug 2023 15:53:17 -0500
Subject: [PATCH 05/32] fix typo on admin index page (#85)
---
templates/pages/admin_index.html | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/templates/pages/admin_index.html b/templates/pages/admin_index.html
index 88bda09..27e9d69 100644
--- a/templates/pages/admin_index.html
+++ b/templates/pages/admin_index.html
@@ -59,13 +59,13 @@
From 25316d7bf2fb082063aaffa0802e000abf43b52d Mon Sep 17 00:00:00 2001
From: Thomas Miceli <27960254+thomiceli@users.noreply.github.com>
Date: Sat, 2 Sep 2023 03:58:37 +0200
Subject: [PATCH 06/32] Added private visibility
* Changed gist type and added HTML button on creation
* Adapted label and edit button
* Changed rules for git HTTP and SSH
* Adapt Readme features
---
README.md | 2 +-
internal/models/gist.go | 14 +++++++-------
internal/ssh/git_ssh.go | 13 +++++++++++--
internal/web/gist.go | 20 ++++++++++++++++++--
internal/web/git_http.go | 15 +++++++++++++--
internal/web/run.go | 22 ++++++++++++++++++----
public/main.ts | 16 ++++++++++++++++
templates/base/gist_header.html | 3 +--
templates/pages/all.html | 2 +-
templates/pages/create.html | 21 +++++++++++++++++++--
templates/pages/edit.html | 19 +++++++++----------
11 files changed, 114 insertions(+), 33 deletions(-)
diff --git a/README.md b/README.md
index 30253ac..3d6a0c5 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ A self-hosted pastebin **powered by Git**. [Try it here](https://opengist.thomic
## Features
-* Create public or unlisted snippets
+* Create public, unlisted or private snippets
* Clone / Pull / Push snippets **via Git** over HTTP or SSH
* Revisions history
* Syntax highlighting ; markdown & CSV support
diff --git a/internal/models/gist.go b/internal/models/gist.go
index 3bcd1da..84e7591 100644
--- a/internal/models/gist.go
+++ b/internal/models/gist.go
@@ -15,7 +15,7 @@ type Gist struct {
Preview string
PreviewFilename string
Description string
- Private bool
+ Private int // 0: public, 1: unlisted, 2: private
UserID uint
User User
NbFiles int
@@ -89,7 +89,7 @@ func GetAllGists(offset int) ([]*Gist, error) {
func GetAllGistsFromSearch(currentUserId uint, query string, offset int, sort string, order string) ([]*Gist, error) {
var gists []*Gist
err := db.Preload("User").Preload("Forked.User").
- Where("((gists.private = 0) or (gists.private = 1 and gists.user_id = ?))", currentUserId).
+ Where("((gists.private = 0) or (gists.private > 0 and gists.user_id = ?))", currentUserId).
Where("gists.title like ? or gists.description like ?", "%"+query+"%", "%"+query+"%").
Limit(11).
Offset(offset * 10).
@@ -101,7 +101,7 @@ func GetAllGistsFromSearch(currentUserId uint, query string, offset int, sort st
func gistsFromUserStatement(fromUserId uint, currentUserId uint) *gorm.DB {
return db.Preload("User").Preload("Forked.User").
- Where("((gists.private = 0) or (gists.private = 1 and gists.user_id = ?))", currentUserId).
+ Where("((gists.private = 0) or (gists.private > 0 and gists.user_id = ?))", currentUserId).
Where("users.id = ?", fromUserId).
Joins("join users on gists.user_id = users.id")
}
@@ -124,7 +124,7 @@ func CountAllGistsFromUser(fromUserId uint, currentUserId uint) (int64, error) {
func likedStatement(fromUserId uint, currentUserId uint) *gorm.DB {
return db.Preload("User").Preload("Forked.User").
- Where("((gists.private = 0) or (gists.private = 1 and gists.user_id = ?))", currentUserId).
+ Where("((gists.private = 0) or (gists.private > 0 and gists.user_id = ?))", currentUserId).
Where("likes.user_id = ?", fromUserId).
Joins("join likes on gists.id = likes.gist_id").
Joins("join users on likes.user_id = users.id")
@@ -147,7 +147,7 @@ func CountAllGistsLikedByUser(fromUserId uint, currentUserId uint) (int64, error
func forkedStatement(fromUserId uint, currentUserId uint) *gorm.DB {
return db.Preload("User").Preload("Forked.User").
- Where("gists.forked_id is not null and ((gists.private = 0) or (gists.private = 1 and gists.user_id = ?))", currentUserId).
+ Where("gists.forked_id is not null and ((gists.private = 0) or (gists.private > 0 and gists.user_id = ?))", currentUserId).
Where("gists.user_id = ?", fromUserId).
Joins("join users on gists.user_id = users.id")
}
@@ -243,7 +243,7 @@ func (gist *Gist) GetForks(currentUserId uint, offset int) ([]*Gist, error) {
var gists []*Gist
err := db.Model(&gist).Preload("User").
Where("forked_id = ?", gist.ID).
- Where("(gists.private = 0) or (gists.private = 1 and gists.user_id = ?)", currentUserId).
+ Where("(gists.private = 0) or (gists.private > 0 and gists.user_id = ?)", currentUserId).
Limit(11).
Offset(offset * 10).
Order("updated_at desc").
@@ -379,7 +379,7 @@ func (gist *Gist) UpdatePreviewAndCount() error {
type GistDTO struct {
Title string `validate:"max=50" form:"title"`
Description string `validate:"max=150" form:"description"`
- Private bool `form:"private"`
+ Private int `validate:"number,min=0,max=2" form:"private"`
Files []FileDTO `validate:"min=1,dive"`
}
diff --git a/internal/ssh/git_ssh.go b/internal/ssh/git_ssh.go
index 54ca59b..e8ade42 100644
--- a/internal/ssh/git_ssh.go
+++ b/internal/ssh/git_ssh.go
@@ -42,12 +42,21 @@ func runGitCommand(ch ssh.Channel, gitCmd string, key string, ip string) error {
return errors.New("internal server error")
}
- if verb == "receive-pack" || requireLogin == "1" {
+ // Check for the key if :
+ // - user wants to push the gist
+ // - user wants to clone a private gist
+ // - gist is not found (obfuscation)
+ // - admin setting to require login is set to true
+ if verb == "receive-pack" ||
+ gist.Private == 2 ||
+ gist.ID == 0 ||
+ requireLogin == "1" {
+
pubKey, err := models.SSHKeyExistsForUser(key, gist.UserID)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
log.Warn().Msg("Invalid SSH authentication attempt from " + ip)
- return errors.New("unauthorized")
+ return errors.New("gist not found")
}
errorSsh("Failed to get user by SSH key id", err)
return errors.New("internal server error")
diff --git a/internal/web/gist.go b/internal/web/gist.go
index 6080fde..6a44623 100644
--- a/internal/web/gist.go
+++ b/internal/web/gist.go
@@ -80,7 +80,7 @@ func gistInit(next echo.HandlerFunc) echo.HandlerFunc {
setData(ctx, "hasLiked", hasLiked)
}
- if gist.Private {
+ if gist.Private > 0 {
setData(ctx, "NoIndex", true)
}
@@ -88,6 +88,22 @@ func gistInit(next echo.HandlerFunc) echo.HandlerFunc {
}
}
+// gistSoftInit try to load a gist (same as gistInit) but does not return a 404 if the gist is not found
+// useful for git clients using HTTP to obfuscate the existence of a private gist
+func gistSoftInit(next echo.HandlerFunc) echo.HandlerFunc {
+ return func(ctx echo.Context) error {
+ userName := ctx.Param("user")
+ gistName := ctx.Param("gistname")
+
+ gistName = strings.TrimSuffix(gistName, ".git")
+
+ gist, _ := models.GetGist(userName, gistName)
+ setData(ctx, "gist", gist)
+
+ return next(ctx)
+ }
+}
+
func allGists(ctx echo.Context) error {
var err error
var urlPage string
@@ -400,7 +416,7 @@ func processCreate(ctx echo.Context) error {
func toggleVisibility(ctx echo.Context) error {
var gist = getData(ctx, "gist").(*models.Gist)
- gist.Private = !gist.Private
+ gist.Private = (gist.Private + 1) % 3
if err := gist.Update(); err != nil {
return errorRes(500, "Error updating this gist", err)
}
diff --git a/internal/web/git_http.go b/internal/web/git_http.go
index 54e0649..61b01a0 100644
--- a/internal/web/git_http.go
+++ b/internal/web/git_http.go
@@ -47,16 +47,23 @@ func gitHttp(ctx echo.Context) error {
gist := getData(ctx, "gist").(*models.Gist)
+ // Shows basic auth if :
+ // - user wants to push the gist
+ // - user wants to clone a private gist
+ // - gist is not found (obfuscation)
+ // - admin setting to require login is set to true
noAuth := (ctx.QueryParam("service") == "git-upload-pack" ||
strings.HasSuffix(ctx.Request().URL.Path, "git-upload-pack") ||
ctx.Request().Method == "GET") &&
+ gist.Private != 2 &&
+ gist.ID != 0 &&
!getData(ctx, "RequireLogin").(bool)
repositoryPath := git.RepositoryPath(gist.User.Username, gist.Uuid)
if _, err := os.Stat(repositoryPath); os.IsNotExist(err) {
if err != nil {
- return errorRes(500, "Repository does not exist", err)
+ return errorRes(404, "Repository directory does not exist", err)
}
}
@@ -82,12 +89,16 @@ func gitHttp(ctx echo.Context) error {
return basicAuth(ctx)
}
+ if gist.ID == 0 {
+ return errorRes(404, "Not found", nil)
+ }
+
if ok, err := argon2id.verify(authPassword, gist.User.Password); !ok || gist.User.Username != authUsername {
if err != nil {
return errorRes(500, "Cannot verify password", err)
}
log.Warn().Msg("Invalid HTTP authentication attempt from " + ctx.RealIP())
- return errorRes(403, "Unauthorized", nil)
+ return errorRes(404, "Not found", nil)
}
return route.handler(ctx)
diff --git a/internal/web/run.go b/internal/web/run.go
index 14e8b9c..3b96b28 100644
--- a/internal/web/run.go
+++ b/internal/web/run.go
@@ -30,11 +30,11 @@ var re = regexp.MustCompile("[^a-z0-9]+")
var fm = template.FuncMap{
"split": strings.Split,
"indexByte": strings.IndexByte,
- "toInt": func(i string) int64 {
- val, _ := strconv.ParseInt(i, 10, 64)
+ "toInt": func(i string) int {
+ val, _ := strconv.Atoi(i)
return val
},
- "inc": func(i int64) int64 {
+ "inc": func(i int) int {
return i + 1
},
"splitGit": func(i string) []string {
@@ -88,6 +88,20 @@ var fm = template.FuncMap{
return config.C.ExternalUrl + "/" + manifestEntries[jsfile].File
},
"defaultAvatar": defaultAvatar,
+ "visibilityStr": func(visibility int, lowercase bool) string {
+ s := "Public"
+ switch visibility {
+ case 1:
+ s = "Unlisted"
+ case 2:
+ s = "Private"
+ }
+
+ if lowercase {
+ return strings.ToLower(s)
+ }
+ return s
+ },
}
var EmbedFS fs.FS
@@ -226,7 +240,7 @@ func Start() {
debugStr := ""
// Git HTTP routes
if config.C.HttpGit {
- e.Any("/:user/:gistname/*", gitHttp, gistInit)
+ e.Any("/:user/:gistname/*", gitHttp, gistSoftInit)
debugStr = " (with Git over HTTP)"
}
diff --git a/public/main.ts b/public/main.ts
index c354e35..0adb138 100644
--- a/public/main.ts
+++ b/public/main.ts
@@ -183,4 +183,20 @@ document.addEventListener('DOMContentLoaded', () => {
});
};
});
+
+ const gistmenuvisibility = document.getElementById('gist-menu-visibility');
+ if (gistmenuvisibility) {
+ let submitgistbutton = (document.getElementById('submit-gist') as HTMLInputElement);
+ document.getElementById('gist-visibility-menu-button')!.onclick = () => {
+ console.log("z");
+ gistmenuvisibility!.classList.toggle('hidden');
+ }
+ Array.from(document.querySelectorAll('.gist-visibility-option')).forEach((el) => {
+ (el as HTMLElement).onclick = () => {
+ submitgistbutton.textContent = "Create " + el.textContent.toLowerCase() + " gist";
+ submitgistbutton!.value = (el as HTMLElement).dataset.visibility || '0';
+ gistmenuvisibility!.classList.add('hidden');
+ }
+ });
+ }
});
diff --git a/templates/base/gist_header.html b/templates/base/gist_header.html
index f0f5d60..cffadbe 100644
--- a/templates/base/gist_header.html
+++ b/templates/base/gist_header.html
@@ -92,8 +92,7 @@
Forked from {{ .gist.Forked.User.Username }}/{{ .gist.Forked.Title }}
{{ end }}
Last active {{ .gist.UpdatedAt }}
- {{ if .gist.Private }} • Unlisted {{ end }}
-
+ {{ if .gist.Private }} • {{ visibilityStr .gist.Private false }} {{ end }}
{{ .gist.Description }}
diff --git a/templates/pages/all.html b/templates/pages/all.html
index 6e8402d..d5b619d 100644
--- a/templates/pages/all.html
+++ b/templates/pages/all.html
@@ -137,7 +137,7 @@
Last active {{ $gist.UpdatedAt }}
{{ if $gist.Forked }} • Forked from {{ $gist.Forked.User.Username }}/{{ $gist.Forked.Title }} {{ end }}
- {{ if $gist.Private }} • Unlisted {{ end }}
+ {{ if $gist.Private }} • {{ visibilityStr $gist.Private false }} {{ end }}
{{ $gist.Description }}
diff --git a/templates/pages/create.html b/templates/pages/create.html
index a0c2169..4dc0dbc 100644
--- a/templates/pages/create.html
+++ b/templates/pages/create.html
@@ -56,8 +56,25 @@
Add file
-
Create unlisted gist
-
Create public gist
+
+
+
Create public gist
+
+
+
+
+ Public
+ Unlisted
+ Private
+
+
+
+
{{ .csrfHtml }}
diff --git a/templates/pages/edit.html b/templates/pages/edit.html
index fb7f868..2aa05dd 100644
--- a/templates/pages/edit.html
+++ b/templates/pages/edit.html
@@ -11,18 +11,17 @@
+
From d4eed91130ef06d4160772e9b269f84824637b60 Mon Sep 17 00:00:00 2001
From: Thomas Miceli <27960254+thomiceli@users.noreply.github.com>
Date: Tue, 5 Sep 2023 15:22:09 +0200
Subject: [PATCH 09/32] Split hljs into a new file; improved dev vite server
system (#91)
---
internal/web/run.go | 9 ++++--
public/hljs.ts | 50 +++++++++++++++++++++++++++++++
public/main.ts | 52 ++-------------------------------
templates/base/base_footer.html | 1 +
templates/base/base_header.html | 11 +++++--
vite.config.js | 2 +-
6 files changed, 69 insertions(+), 56 deletions(-)
create mode 100644 public/hljs.ts
diff --git a/internal/web/run.go b/internal/web/run.go
index 4fb827f..a4d1839 100644
--- a/internal/web/run.go
+++ b/internal/web/run.go
@@ -82,11 +82,14 @@ var fm = template.FuncMap{
return defaultAvatar()
},
- "asset": func(jsfile string) string {
+ "asset": func(file string) string {
if dev {
- return "http://localhost:16157/" + jsfile
+ return "http://localhost:16157/" + file
}
- return config.C.ExternalUrl + "/" + manifestEntries[jsfile].File
+ return config.C.ExternalUrl + "/" + manifestEntries[file].File
+ },
+ "dev": func() bool {
+ return dev
},
"defaultAvatar": defaultAvatar,
"visibilityStr": func(visibility int, lowercase bool) string {
diff --git a/public/hljs.ts b/public/hljs.ts
new file mode 100644
index 0000000..1edfb93
--- /dev/null
+++ b/public/hljs.ts
@@ -0,0 +1,50 @@
+import hljs from 'highlight.js';
+import md from 'markdown-it';
+
+document.querySelectorAll('.markdown').forEach((e: HTMLElement) => {
+ e.innerHTML = md({
+ html: true,
+ highlight: function (str, lang) {
+ if (lang && hljs.getLanguage(lang)) {
+ try {
+ return '' +
+ hljs.highlight(str, {language: lang, ignoreIllegals: true}).value +
+ '
';
+ } catch (__) {
+ }
+ }
+
+ return '' + md().utils.escapeHtml(str) + '
';
+ }
+ }).render(e.textContent);
+});
+
+document.querySelectorAll('.table-code').forEach((el) => {
+ const ext = el.dataset.filename?.split('.').pop() || '';
+
+ if (hljs.autoDetection(ext) && ext !== 'txt') {
+ el.querySelectorAll('td.line-code').forEach((ell) => {
+ ell.classList.add('language-' + ext);
+ hljs.highlightElement(ell);
+ });
+ }
+
+ el.addEventListener('click', event => {
+ if (event.target && (event.target as HTMLElement).matches('.line-num')) {
+ Array.from(document.querySelectorAll('.table-code .selected')).forEach((el) => el.classList.remove('selected'));
+
+ const nextSibling = (event.target as HTMLElement).nextSibling;
+ if (nextSibling instanceof HTMLElement) {
+ nextSibling.classList.add('selected');
+ }
+
+
+ const filename = el.dataset.filenameSlug;
+ const line = (event.target as HTMLElement).textContent;
+ const url = location.protocol + '//' + location.host + location.pathname;
+ const hash = '#file-' + filename + '-' + line;
+ window.history.pushState(null, null, url + hash);
+ location.hash = hash;
+ }
+ });
+});
diff --git a/public/main.ts b/public/main.ts
index 80d1a54..daacf34 100644
--- a/public/main.ts
+++ b/public/main.ts
@@ -34,11 +34,11 @@ document.addEventListener('DOMContentLoaded', () => {
checkTheme();
}
- document.getElementById('theme-btn')!.onclick = (e) => {
+ document.getElementById('theme-btn')!.onclick = () => {
themeMenu.classList.toggle('hidden');
}
- document.getElementById('user-btn')?.addEventListener("click" , (e) => {
+ document.getElementById('user-btn')?.addEventListener("click" , () => {
document.getElementById('user-menu').classList.toggle('hidden');
})
@@ -65,53 +65,6 @@ document.addEventListener('DOMContentLoaded', () => {
};
}
- document.querySelectorAll('.markdown').forEach((e: HTMLElement) => {
- e.innerHTML = md({
- html: true,
- highlight: function (str, lang) {
- if (lang && hljs.getLanguage(lang)) {
- try {
- return '' +
- hljs.highlight(str, {language: lang, ignoreIllegals: true}).value +
- '
';
- } catch (__) {
- }
- }
-
- return '' + md().utils.escapeHtml(str) + '
';
- }
- }).render(e.textContent);
- });
-
- document.querySelectorAll('.table-code').forEach((el) => {
- const ext = el.dataset.filename?.split('.').pop() || '';
-
- if (hljs.autoDetection(ext) && ext !== 'txt') {
- el.querySelectorAll('td.line-code').forEach((ell) => {
- ell.classList.add('language-' + ext);
- hljs.highlightElement(ell);
- });
- }
-
- el.addEventListener('click', event => {
- if (event.target && (event.target as HTMLElement).matches('.line-num')) {
- Array.from(document.querySelectorAll('.table-code .selected')).forEach((el) => el.classList.remove('selected'));
-
- const nextSibling = (event.target as HTMLElement).nextSibling;
- if (nextSibling instanceof HTMLElement) {
- nextSibling.classList.add('selected');
- }
-
-
- const filename = el.dataset.filenameSlug;
- const line = (event.target as HTMLElement).textContent;
- const url = location.protocol + '//' + location.host + location.pathname;
- const hash = '#file-' + filename + '-' + line;
- window.history.pushState(null, null, url + hash);
- location.hash = hash;
- }
- });
- });
const colorhash = () => {
Array.from(document.querySelectorAll('.table-code .selected')).forEach((el) => el.classList.remove('selected'));
@@ -191,7 +144,6 @@ document.addEventListener('DOMContentLoaded', () => {
if (gistmenuvisibility) {
let submitgistbutton = (document.getElementById('submit-gist') as HTMLInputElement);
document.getElementById('gist-visibility-menu-button')!.onclick = () => {
- console.log("z");
gistmenuvisibility!.classList.toggle('hidden');
}
Array.from(document.querySelectorAll('.gist-visibility-option')).forEach((el) => {
diff --git a/templates/base/base_footer.html b/templates/base/base_footer.html
index b393c16..a63f90f 100644
--- a/templates/base/base_footer.html
+++ b/templates/base/base_footer.html
@@ -15,6 +15,7 @@
+