⬆️ Using the latest version of paperclip

This commit is contained in:
LittleSheep 2024-05-20 22:41:54 +08:00
parent ee4f929d6c
commit a502f11ebc
11 changed files with 207 additions and 211 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +1,2 @@
#n:public
!<md> [7186, 0, null, null, -2147483648, -2147483648]
!<md> [7430, 0, null, null, -2147483648, -2147483648]

View File

@ -4,10 +4,18 @@
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":recycle: Use paperclip to store avatar and more">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Bug fixes in update avatar">
<change beforePath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25/storage_v2/_src_/database/hy_passport.gNOKQQ/schema/public.abK9xQ.meta" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25/storage_v2/_src_/database/hy_passport.gNOKQQ/schema/public.abK9xQ.meta" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/cmd/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/cmd/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/grpc/auth.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/grpc/auth.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/models/accounts.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/models/accounts.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/accounts_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/accounts_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/avatar_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/avatar_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/ui/accounts.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/ui/accounts.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/ui/directory.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/ui/directory.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/views/users/directory/userinfo.gohtml" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/views/users/directory/userinfo.gohtml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/views/users/me.gohtml" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/views/users/me.gohtml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -140,7 +148,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value=":lipstick: Fix ui design" />
<MESSAGE value=":bug: Bug fixes of design" />
<MESSAGE value=":sparkles: Bug fixes" />
<MESSAGE value=":sparkles: Batch mark notify as read API" />
@ -165,7 +172,8 @@
<MESSAGE value=":sparkles: Bug fixes of permission check" />
<MESSAGE value=":sparkles: Check permissions GRPC method" />
<MESSAGE value=":recycle: Use paperclip to store avatar and more" />
<option name="LAST_COMMIT_MESSAGE" value=":recycle: Use paperclip to store avatar and more" />
<MESSAGE value=":bug: Bug fixes in update avatar" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Bug fixes in update avatar" />
</component>
<component name="VgoProject">
<settings-migrated>true</settings-migrated>

View File

@ -30,8 +30,8 @@ func (v *Server) Authenticate(_ context.Context, in *proto.AuthRequest) (*proto.
Name: user.Name,
Nick: user.Nick,
Email: user.GetPrimaryEmail().Content,
Avatar: fmt.Sprintf("%s/api/attachments/%s", viper.GetString("paperclip.endpoint"), user.Avatar),
Banner: fmt.Sprintf("%s/api/attachments/%s", viper.GetString("paperclip.endpoint"), user.Banner),
Avatar: fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), user.Avatar),
Banner: fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), user.Banner),
Description: &user.Description,
},
}, nil

View File

@ -13,8 +13,8 @@ type Account struct {
Name string `json:"name" gorm:"uniqueIndex"`
Nick string `json:"nick"`
Description string `json:"description"`
Avatar string `json:"avatar"`
Banner string `json:"banner"`
Avatar *uint `json:"avatar"`
Banner *uint `json:"banner"`
ConfirmedAt *time.Time `json:"confirmed_at"`
PermNodes datatypes.JSONMap `json:"perm_nodes"`

View File

@ -37,8 +37,8 @@ func getUserinfo(c *fiber.Ctx) error {
resp["email"] = data.GetPrimaryEmail().Content
resp["preferred_username"] = data.Nick
if len(data.Avatar) > 0 {
resp["picture"] = fmt.Sprintf("%s/api/attachments/%s", viper.GetString("paperclip.endpoint"), data.Avatar)
if data.Avatar != nil {
resp["picture"] = fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), data.Avatar)
}
return c.JSON(resp)

View File

@ -16,7 +16,7 @@ func setAvatar(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account)
var data struct {
AttachmentID string `json:"attachment" validate:"required"`
AttachmentID uint `json:"attachment" validate:"required"`
}
if err := utils.BindAndValidate(c, &data); err != nil {
@ -24,13 +24,13 @@ func setAvatar(c *fiber.Ctx) error {
}
if _, err := grpc.Attachments.CheckAttachmentExists(context.Background(), &pcpb.AttachmentLookupRequest{
Uuid: &data.AttachmentID,
Id: lo.ToPtr(uint64(data.AttachmentID)),
Usage: lo.ToPtr("p.avatar"),
}); err != nil {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("avatar was not found in repository: %v", err))
}
user.Avatar = data.AttachmentID
user.Avatar = &data.AttachmentID
if err := database.C.Save(&user).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
@ -43,7 +43,7 @@ func setBanner(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account)
var data struct {
AttachmentID string `json:"attachment" validate:"required"`
AttachmentID uint `json:"attachment" validate:"required"`
}
if err := utils.BindAndValidate(c, &data); err != nil {
@ -51,13 +51,13 @@ func setBanner(c *fiber.Ctx) error {
}
if _, err := grpc.Attachments.CheckAttachmentExists(context.Background(), &pcpb.AttachmentLookupRequest{
Uuid: &data.AttachmentID,
Id: lo.ToPtr(uint64(data.AttachmentID)),
Usage: lo.ToPtr("p.banner"),
}); err != nil {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("banner was not found in repository: %v", err))
}
user.Banner = data.AttachmentID
user.Banner = &data.AttachmentID
if err := database.C.Save(&user).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())

View File

@ -45,7 +45,7 @@ func selfUserinfoPage(c *fiber.Ctx) error {
"birthday_at": birthday,
"personal_page": template.HTML(markdown.Render(doc, renderer)),
"userinfo": data,
"avatar": fmt.Sprintf("%s/api/attachments/%s", viper.GetString("paperclip.endpoint"), data.Avatar),
"banner": fmt.Sprintf("%s/api/attachments/%s", viper.GetString("paperclip.endpoint"), data.Banner),
"avatar": fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), data.Avatar),
"banner": fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), data.Banner),
}, "views/layouts/user-center")
}

View File

@ -45,7 +45,7 @@ func otherUserinfoPage(c *fiber.Ctx) error {
"birthday_at": birthday,
"personal_page": template.HTML(markdown.Render(doc, renderer)),
"userinfo": data,
"avatar": fmt.Sprintf("%s/api/attachments/%s", viper.GetString("paperclip.endpoint"), data.Avatar),
"banner": fmt.Sprintf("%s/api/attachments/%s", viper.GetString("paperclip.endpoint"), data.Banner),
"avatar": fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), data.Avatar),
"banner": fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), data.Banner),
}, "views/layouts/user-center")
}

View File

@ -4,13 +4,13 @@
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@1.4.6/dist/utilities.min.css">
<div class="banner-container">
{{if gt (len .userinfo.Banner) 0}}
{{if ne .userinfo.Banner nil}}
<img src="{{.banner}}" alt="Banner" class="banner">
{{end}}
</div>
<div class="left-part name-card">
{{if gt (len .userinfo.Avatar) 0}}
{{if ne .userinfo.Avatar nil}}
<img src="{{.avatar}}" alt="Avatar" class="avatar">
{{else}}
<div class="avatar empty">

View File

@ -4,13 +4,13 @@
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@1.4.6/dist/utilities.min.css">
<div class="banner-container">
{{if gt (len .userinfo.Banner) 0}}
{{if ne .userinfo.Banner nil}}
<img src="{{.banner}}" alt="Banner" class="banner">
{{end}}
</div>
<div class="left-part name-card">
{{if gt (len .userinfo.Avatar) 0}}
{{if ne .userinfo.Avatar nil}}
<img src="{{.avatar}}" alt="Avatar" class="avatar">
{{else}}
<div class="avatar empty">