This commit is contained in:
tobi 2021-09-30 11:16:23 +02:00 committed by GitHub
parent 36a09dd0df
commit 231075f28d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 40 deletions

View file

@ -16,30 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Package classification awesome.
//
// Documentation of our awesome AaaaaaaaaaPI.
//
// Schemes: http
// BasePath: /
// Version: 1.0.0
// Host: some-url.com
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// - basic
//
// SecurityDefinitions:
// basic:
// type: basic
//
// swagger:meta
package main
import (

View file

@ -7,7 +7,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
// statusCache is a wrapper around ttlcache.Cache to provide URL and URI lookups for gtsmodel.Status
// StatusCache is a wrapper around ttlcache.Cache to provide URL and URI lookups for gtsmodel.Status
type StatusCache struct {
cache *ttlcache.Cache // map of IDs -> cached statuses
urls map[string]string // map of status URLs -> IDs
@ -15,7 +15,7 @@ type StatusCache struct {
mutex sync.Mutex
}
// newStatusCache returns a new instantiated statusCache object
// NewStatusCache returns a new instantiated statusCache object
func NewStatusCache() *StatusCache {
c := StatusCache{
cache: ttlcache.NewCache(),

View file

@ -45,6 +45,8 @@ import (
"github.com/uptrace/bun/dialect/pgdialect"
"github.com/uptrace/bun/dialect/sqlitedialect"
"github.com/uptrace/bun/migrate"
// blank import for the sqlite driver for bun
_ "modernc.org/sqlite"
)

View file

@ -10,7 +10,7 @@ import (
"github.com/uptrace/bun/dialect"
)
// dbConn wrapps a bun.DB conn to provide SQL-type specific additional functionality
// DBConn wrapps a bun.DB conn to provide SQL-type specific additional functionality
type DBConn struct {
// TODO: move *Config here, no need to be in each struct type
@ -37,6 +37,7 @@ func WrapDBConn(dbConn *bun.DB, log *logrus.Logger) *DBConn {
}
}
// RunInTx wraps execution of the supplied transaction function.
func (conn *DBConn) RunInTx(ctx context.Context, fn func(bun.Tx) error) db.Error {
// Acquire a new transaction
tx, err := conn.BeginTx(ctx, nil)

View file

@ -46,9 +46,8 @@ func loadTemplates(cfg *config.Config, engine *gin.Engine) error {
func oddOrEven(n int) string {
if n%2 == 0 {
return "even"
} else {
return "odd"
}
return "odd"
}
func noescape(str string) template.HTML {
@ -60,24 +59,24 @@ func timestamp(stamp string) string {
return t.Format("January 2, 2006, 15:04:05")
}
type IconWithLabel struct {
type iconWithLabel struct {
faIcon string
label string
}
func visibilityIcon(visibility model.Visibility) template.HTML {
var icon IconWithLabel
var icon iconWithLabel
if visibility == model.VisibilityPublic {
icon = IconWithLabel{"globe", "public"}
icon = iconWithLabel{"globe", "public"}
} else if visibility == model.VisibilityUnlisted {
icon = IconWithLabel{"unlock", "unlisted"}
icon = iconWithLabel{"unlock", "unlisted"}
} else if visibility == model.VisibilityPrivate {
icon = IconWithLabel{"lock", "private"}
icon = iconWithLabel{"lock", "private"}
} else if visibility == model.VisibilityMutualsOnly {
icon = IconWithLabel{"handshake-o", "mutuals only"}
icon = iconWithLabel{"handshake-o", "mutuals only"}
} else if visibility == model.VisibilityDirect {
icon = IconWithLabel{"envelope", "direct"}
icon = iconWithLabel{"envelope", "direct"}
}
return template.HTML(fmt.Sprintf(`<i aria-label="Visiblity: %v" class="fa fa-%v"></i>`, icon.label, icon.faIcon))

View file

@ -32,12 +32,14 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/router"
)
// Module implements the api.ClientModule interface for web pages.
type Module struct {
config *config.Config
processor processing.Processor
log *logrus.Logger
}
// New returns a new api.ClientModule for web pages.
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
@ -62,6 +64,7 @@ func (m *Module) baseHandler(c *gin.Context) {
})
}
// NotFoundHandler serves a 404 html page instead of a blank 404 error.
func (m *Module) NotFoundHandler(c *gin.Context) {
l := m.log.WithField("func", "404")
l.Trace("serving 404 html")
@ -87,11 +90,11 @@ func (m *Module) Route(s router.Router) error {
return fmt.Errorf("error getting current working directory: %s", err)
}
assetPath := filepath.Join(cwd, m.config.TemplateConfig.AssetBaseDir)
s.AttachStaticFS("/assets", FileSystem{http.Dir(assetPath)})
s.AttachStaticFS("/assets", fileSystem{http.Dir(assetPath)})
// Admin panel route, if it exists
adminPath := filepath.Join(cwd, m.config.TemplateConfig.AssetBaseDir, "/admin")
s.AttachStaticFS("/admin", FileSystem{http.Dir(adminPath)})
s.AttachStaticFS("/admin", fileSystem{http.Dir(adminPath)})
// serve front-page
s.AttachHandler(http.MethodGet, "/", m.baseHandler)

View file

@ -23,13 +23,13 @@ import (
"strings"
)
type FileSystem struct {
type fileSystem struct {
fs http.FileSystem
}
// FileSystem server that only accepts directory listings when an index.html is available
// from https://gist.github.com/hauxe/f2ea1901216177ccf9550a1b8bd59178
func (fs FileSystem) Open(path string) (http.File, error) {
func (fs fileSystem) Open(path string) (http.File, error) {
f, err := fs.fs.Open(path)
if err != nil {
return nil, err