fix PR review suggestions

This commit is contained in:
f0x 2021-09-13 14:00:39 +02:00
commit 781d7b8584
3 changed files with 15 additions and 13 deletions

View file

@ -25,7 +25,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/oauth"
) )
type StatusLink struct { type statusLink struct {
User string `uri:"user" binding:"required"` User string `uri:"user" binding:"required"`
ID string `uri:"id" binding:"required"` ID string `uri:"id" binding:"required"`
} }
@ -34,40 +34,42 @@ func (m *Module) threadTemplateHandler(c *gin.Context) {
l := m.log.WithField("func", "threadTemplateGET") l := m.log.WithField("func", "threadTemplateGET")
l.Trace("rendering thread template") l.Trace("rendering thread template")
var statusLink StatusLink ctx := c.Request.Context()
if err := c.ShouldBindUri(&statusLink); err != nil { var uriParts statusLink
if err := c.ShouldBindUri(&uriParts); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "status not found"}) c.JSON(http.StatusBadRequest, gin.H{"error": "status not found"})
return return
} }
authed, err := oauth.Authed(c, false, false, false, false) // we don't really need an app here but we want everything else authed, err := oauth.Authed(c, false, false, false, false)
if err != nil { if err != nil {
l.Errorf("error authing status GET request: %s", err) l.Errorf("error authing status GET request: %s", err)
c.JSON(http.StatusBadRequest, gin.H{"error": "status not found"}) c.JSON(http.StatusBadRequest, gin.H{"error": "status not found"})
return return
} }
instance, err := m.processor.InstanceGet(c.Request.Context(), m.config.Host) instance, err := m.processor.InstanceGet(ctx, m.config.Host)
if err != nil { if err != nil {
l.Debugf("error getting instance from processor: %s", err) l.Debugf("error getting instance from processor: %s", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"}) c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
return return
} }
status, err := m.processor.StatusGet(c.Request.Context(), authed, statusLink.ID) status, err := m.processor.StatusGet(ctx, authed, uriParts.ID)
if err != nil { if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "status not found"}) c.JSON(http.StatusBadRequest, gin.H{"error": "status not found"})
return return
} }
println(statusLink.User[:1], statusLink.User, status.Account.Username) println(uriParts.User[:1], uriParts.User, status.Account.Username)
if statusLink.User[:1] != "@" || statusLink.User[1:] != status.Account.Username { if uriParts.User[:1] != "@" || uriParts.User[1:] != status.Account.Username {
c.JSON(http.StatusBadRequest, gin.H{"error": "status not found"}) c.JSON(http.StatusBadRequest, gin.H{"error": "status not found"})
return return
} }
context, err := m.processor.StatusGetContext(c.Request.Context(), authed, statusLink.ID) context, err := m.processor.StatusGetContext(ctx, authed, uriParts.ID)
if err != nil { if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "status not found"}) c.JSON(http.StatusBadRequest, gin.H{"error": "status not found"})
return return

View file

@ -302,7 +302,7 @@ func NewTestAccounts() map[string]*gtsmodel.Account {
Username: "admin", Username: "admin",
AvatarMediaAttachmentID: "", AvatarMediaAttachmentID: "",
HeaderMediaAttachmentID: "", HeaderMediaAttachmentID: "",
DisplayName: "Admin", DisplayName: "",
Fields: []gtsmodel.Field{}, Fields: []gtsmodel.Field{},
Note: "", Note: "",
Memorial: false, Memorial: false,
@ -540,7 +540,7 @@ func NewTestAttachments() map[string]*gtsmodel.MediaAttachment {
}, },
}, },
AccountID: "01F8MH1H7YV1Z7D2C8K2730QBF", AccountID: "01F8MH1H7YV1Z7D2C8K2730QBF",
Description: "", Description: "90's Trent Reznor turning to the camera",
ScheduledStatusID: "", ScheduledStatusID: "",
Blurhash: "LEDara58O=t5EMSOENEN9]}?aK%0", Blurhash: "LEDara58O=t5EMSOENEN9]}?aK%0",
Processing: 2, Processing: 2,

View file

@ -1,5 +1,5 @@
<a href="{{.Account.URL}}" class="avatar"><img src="{{.Account.Avatar}}"></a> <a href="{{.Account.URL}}" class="avatar"><img src="{{.Account.Avatar}}"></a>
<a href="{{.Account.URL}}" class="displayname">{{.Account.DisplayName}}</a> <a href="{{.Account.URL}}" class="displayname">{{if .Account.DisplayName}}{{.Account.DisplayName}}{{else}}{{.Account.Username}}{{end}}</a>
<a href="{{.Account.URL}}" class="username">@{{.Account.Username}}</a> <a href="{{.Account.URL}}" class="username">@{{.Account.Username}}</a>
<div class="text"> <div class="text">
{{if .SpoilerText}} {{if .SpoilerText}}
@ -17,7 +17,7 @@
{{range .}} {{range .}}
<a href="{{.URL}}" target="_blank" title="{{.Description}}"> <a href="{{.URL}}" target="_blank" title="{{.Description}}">
{{if not .Description}} {{if not .Description}}
<div class="no-image-desc" aria-hidden="true" >(!)<span>Missing image description</span></div> <div class="no-image-desc" aria-hidden="true" ><i class="fa fa-info-circle"></i><span>Missing image description</span></div>
{{end}} {{end}}
<img src="{{.PreviewURL}}" alt="{{.Description}}"/> <img src="{{.PreviewURL}}" alt="{{.Description}}"/>
</a> </a>