fix package, adapt to proper Route structure

This commit is contained in:
f0x 2021-06-21 18:58:32 +02:00
parent 8041fd04e1
commit 9d7659948d
7 changed files with 60 additions and 27 deletions

1
go.mod
View File

@ -15,6 +15,7 @@ require (
github.com/dsoprea/go-utility v0.0.0-20200717064901-2fccff4aa15e // indirect
github.com/gin-contrib/cors v1.3.1
github.com/gin-contrib/sessions v0.0.3
github.com/gin-contrib/static v0.0.1 // indirect
github.com/gin-gonic/gin v1.7.2
github.com/go-errors/errors v1.4.0 // indirect
github.com/go-fed/activity v1.0.1-0.20210426194615-e0de0863dcc1

4
go.sum
View File

@ -66,7 +66,10 @@ github.com/gin-contrib/sessions v0.0.3 h1:PoBXki+44XdJdlgDqDrY5nDVe3Wk7wDV/UCOuL
github.com/gin-contrib/sessions v0.0.3/go.mod h1:8C/J6cad3Il1mWYYgtw0w+hqasmpvy25mPkXdOgeB9I=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-contrib/static v0.0.1 h1:JVxuvHPuUfkoul12N7dtQw7KRn/pSMq7Ue1Va9Swm1U=
github.com/gin-contrib/static v0.0.1/go.mod h1:CSxeF+wep05e0kCOsqWdAWbSszmc31zTIbD8TvWl7Hs=
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.7.2 h1:Tg03T9yM2xa8j6I3Z3oqLaQRSmKvxPd6g/2HJ6zICFA=
github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
@ -95,6 +98,7 @@ github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTM
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-playground/validator/v10 v10.6.1 h1:W6TRDXt4WcWp4c4nf/G+6BkGdhiIo0k417gfr+V6u4I=
github.com/go-playground/validator/v10 v10.6.1/go.mod h1:xm76BBt941f7yWdGnI2DVPFFg1UK3YY04qifoXU3lOk=

View File

@ -43,7 +43,7 @@ import (
timelineprocessing "github.com/superseriousbusiness/gotosocial/internal/timeline"
"github.com/superseriousbusiness/gotosocial/internal/transport"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/internal/web/base"
"github.com/superseriousbusiness/gotosocial/internal/web"
)
var models []interface{} = []interface{}{
@ -123,7 +123,7 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
appsModule := app.New(c, processor, log)
followRequestsModule := followrequest.New(c, processor, log)
webfingerModule := webfinger.New(c, processor, log)
webBaseModule := webBase.new(c, log)
webBaseModule := web.New(c, processor, log)
usersModule := user.New(c, processor, log)
timelineModule := timeline.New(c, processor, log)
notificationModule := notification.New(c, processor, log)

View File

@ -16,47 +16,70 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package base
package web
import (
"fmt"
"net/http"
"os"
"path/filepath"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
type Module struct {
config *config.Config
log *logrus.Logger
config *config.Config
processor processing.Processor
log *logrus.Logger
}
func New(config *config.Config, log *logrus.Logger) {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
log: log,
config: config,
log: log,
processor: processor,
}
}
func (m *Module) baseHandler(c *gin.Context) {
l := m.log.WithField("func", "BaseGETHandler")
l.Trace("serving index html")
instance, err := m.processor.InstanceGet(m.config.Host)
if err != nil {
l.Debugf("error getting instance from processor: %s", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
return
}
// FIXME: fill in more variables?
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"instance": instance,
"countUsers": 3,
"countStatuses": 42069,
"version": "1.0.0",
"adminUsername": "@admin",
})
}
// Route satisfies the RESTAPIModule interface
func (m *Module) Route(s router.Router) error {
l := m.log.WithField("func", "BaseGETHandler")
// serve static files from /assets
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("error getting current working directory: %s", err)
}
assetPath := filepath.Join(cwd, m.config.TemplateConfig.AssetBaseDir)
s.Static("/assets", assetPath)
s.AttachMiddleware(static.Serve("/assets", static.LocalFile(assetPath, false)))
// serve front-page
s.GET("/", func(c *gin.Context) {
l.Trace("serving index html")
// FIXME: actual variables
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"instancename": "GoToSocial Test Instance",
"countUsers": 3,
"countStatuses": 42069,
"version": "1.0.0",
"adminUsername": "@admin",
})
})
s.AttachHandler(http.MethodGet, "/", m.baseHandler)
return nil
}

View File

@ -1,12 +1,12 @@
<!-- footer.tmpl -->
<footer>
<div id="version">
Running GoToSocial version: <span class="accent">{{.version}}</span><br>
Running GoToSocial version: <span class="accent">{{.instance.Version}}</span><br>
<a href="https://github.com/superseriousbusiness/gotosocial">Source Code</a>
</div>
<div id="contact">
Administrated by: <a href="/{{.adminUsername}}" class="nounderline">{{.adminUsername}}</a><br>
<a href="/moderation">Moderation team</a>
Contact: <a href="/{{.instance.ContactAccount}}" class="nounderline">{{.instance.ContactAccount}}</a><br>
<!-- <a href="/moderation">Moderation team</a> -->
</div>
</footer>
</body>

View File

@ -6,11 +6,11 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/assets/bundle.css">
<title>{{.instancename}} - GoToSocial</title>
<title>{{.instance.Title}} - GoToSocial</title>
</head>
<body>
<header>
<h1>
{{.instancename}}
{{.instance.Title}}
</h1>
</header>

View File

@ -3,7 +3,12 @@
<img src="/assets/sloth.png" alt="Clipart styled sloth logo">
</aside>
<section>
<h1>Home to <span class="count">{{.countUsers}}</span> users who posted <span class="count">{{.countStatuses}}</span> statuses.</h1>
<!-- <h1>Home to <span class="count">{ {.instance.Stats.UserCount}}</span> users
who posted <span class="count">{ {.instance.Stats.StatusCount}}</span> statuses,
federating with <span class="count">{ {.instance.Stats.DomainCount}}</span> other instances.</h1> -->
<h1>Home to <span class="count">3</span> users
who posted <span class="count">42069</span> statuses,
federating with <span class="count">9001</span> other instances.</h1>
<h3>This is the default landing page, you can edit it from <span class="accent">./web/template/index.tmpl</span></h1>
<ul>