feat: add wxshare
This commit is contained in:
@@ -21,8 +21,9 @@ type TokenResponse struct {
|
||||
}
|
||||
|
||||
// Login
|
||||
// @Router /admin/auth [post]
|
||||
// @Bind body body
|
||||
//
|
||||
// @Router /admin/auth [post]
|
||||
// @Bind body body
|
||||
func (ctl *auth) Login(ctx fiber.Ctx, body *AuthBody) (*TokenResponse, error) {
|
||||
if body.Username == "pl.yang" && body.Password == "Xixi@0202" {
|
||||
claim := ctl.jwt.CreateClaims(jwt.BaseClaims{
|
||||
|
||||
@@ -14,17 +14,19 @@ type medias struct {
|
||||
}
|
||||
|
||||
// List medias
|
||||
// @Router /admin/medias [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
//
|
||||
// @Router /admin/medias [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
func (ctl *medias) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
|
||||
cond := models.Medias.BuildConditionWithKey(query.Keyword)
|
||||
return models.Medias.List(ctx.Context(), pagination, cond)
|
||||
}
|
||||
|
||||
// Show media
|
||||
// @Router /admin/medias/:id [get]
|
||||
// @Bind id path
|
||||
//
|
||||
// @Router /admin/medias/:id [get]
|
||||
// @Bind id path
|
||||
func (ctl *medias) Show(ctx fiber.Ctx, id int64) error {
|
||||
media, err := models.Medias.GetByID(ctx.Context(), id)
|
||||
if err != nil {
|
||||
@@ -40,8 +42,9 @@ func (ctl *medias) Show(ctx fiber.Ctx, id int64) error {
|
||||
}
|
||||
|
||||
// Delete
|
||||
// @Router /admin/medias/:id [delete]
|
||||
// @Bind id path
|
||||
//
|
||||
// @Router /admin/medias/:id [delete]
|
||||
// @Bind id path
|
||||
func (ctl *medias) Delete(ctx fiber.Ctx, id int64) error {
|
||||
media, err := models.Medias.GetByID(ctx.Context(), id)
|
||||
if err != nil {
|
||||
|
||||
@@ -16,9 +16,10 @@ type OrderListQuery struct {
|
||||
type orders struct{}
|
||||
|
||||
// List users
|
||||
// @Router /admin/orders [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
//
|
||||
// @Router /admin/orders [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
func (ctl *orders) List(ctx fiber.Ctx, pagination *requests.Pagination, query *OrderListQuery) (*requests.Pager, error) {
|
||||
cond := models.Orders.BuildConditionWithKey(query.OrderNumber, query.UserID)
|
||||
return models.Orders.List(ctx.Context(), pagination, cond)
|
||||
|
||||
@@ -18,9 +18,10 @@ type ListQuery struct {
|
||||
type posts struct{}
|
||||
|
||||
// List posts
|
||||
// @Router /admin/posts [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
//
|
||||
// @Router /admin/posts [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
|
||||
cond := models.Posts.BuildConditionWithKey(query.Keyword)
|
||||
pager, err := models.Posts.List(ctx.Context(), pagination, cond)
|
||||
@@ -63,8 +64,9 @@ type PostForm struct {
|
||||
}
|
||||
|
||||
// Create
|
||||
// @Router /admin/posts [post]
|
||||
// @Bind form body
|
||||
//
|
||||
// @Router /admin/posts [post]
|
||||
// @Bind form body
|
||||
func (ctl *posts) Create(ctx fiber.Ctx, form *PostForm) error {
|
||||
post := model.Posts{
|
||||
Title: form.Title,
|
||||
@@ -100,9 +102,10 @@ func (ctl *posts) Create(ctx fiber.Ctx, form *PostForm) error {
|
||||
}
|
||||
|
||||
// Update posts
|
||||
// @Router /admin/posts/:id [put]
|
||||
// @Bind id path
|
||||
// @Bind form body
|
||||
//
|
||||
// @Router /admin/posts/:id [put]
|
||||
// @Bind id path
|
||||
// @Bind form body
|
||||
func (ctl *posts) Update(ctx fiber.Ctx, id int64, form *PostForm) error {
|
||||
oldPost, err := models.Posts.GetByID(ctx.Context(), id)
|
||||
if err != nil {
|
||||
@@ -148,8 +151,9 @@ func (ctl *posts) Update(ctx fiber.Ctx, id int64, form *PostForm) error {
|
||||
}
|
||||
|
||||
// Delete posts
|
||||
// @Router /admin/posts/:id [delete]
|
||||
// @Bind id path
|
||||
//
|
||||
// @Router /admin/posts/:id [delete]
|
||||
// @Bind id path
|
||||
func (ctl *posts) Delete(ctx fiber.Ctx, id int64) error {
|
||||
post, err := models.Posts.GetByID(ctx.Context(), id)
|
||||
if err != nil {
|
||||
@@ -172,8 +176,9 @@ type PostItem struct {
|
||||
}
|
||||
|
||||
// Show posts by id
|
||||
// @Router /admin/posts/:id [get]
|
||||
// @Bind id path
|
||||
//
|
||||
// @Router /admin/posts/:id [get]
|
||||
// @Bind id path
|
||||
func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) {
|
||||
post, err := models.Posts.GetByID(ctx.Context(), id)
|
||||
if err != nil {
|
||||
@@ -193,9 +198,10 @@ func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) {
|
||||
}
|
||||
|
||||
// SendTo
|
||||
// @Router /admin/posts/:id/send-to/:userId [post]
|
||||
// @Bind id path
|
||||
// @Bind userId path
|
||||
//
|
||||
// @Router /admin/posts/:id/send-to/:userId [post]
|
||||
// @Bind id path
|
||||
// @Bind userId path
|
||||
func (ctl *posts) SendTo(ctx fiber.Ctx, id, userId int64) error {
|
||||
if _, err := models.Posts.GetByID(ctx.Context(), id); err != nil {
|
||||
return err
|
||||
|
||||
@@ -22,7 +22,8 @@ type StatisticsResponse struct {
|
||||
}
|
||||
|
||||
// dashboard statistics
|
||||
// @Router /admin/statistics [get]
|
||||
//
|
||||
// @Router /admin/statistics [get]
|
||||
func (s *statistics) statistics(ctx fiber.Ctx) (*StatisticsResponse, error) {
|
||||
statistics := &StatisticsResponse{}
|
||||
|
||||
|
||||
@@ -33,10 +33,11 @@ type PreCheckResp struct {
|
||||
}
|
||||
|
||||
// PreUploadCheck
|
||||
// @Router /admin/uploads/pre-uploaded-check/:md5.:ext [get]
|
||||
// @Bind md5 path
|
||||
// @Bind ext path
|
||||
// @Bind mime query
|
||||
//
|
||||
// @Router /admin/uploads/pre-uploaded-check/:md5.:ext [get]
|
||||
// @Bind md5 path
|
||||
// @Bind ext path
|
||||
// @Bind mime query
|
||||
func (up *uploads) PreUploadCheck(ctx fiber.Ctx, md5, ext, mime string) (*PreCheckResp, error) {
|
||||
_, err := models.Medias.GetByHash(ctx.Context(), md5)
|
||||
if err != nil && errors.Is(err, qrm.ErrNoRows) {
|
||||
@@ -59,8 +60,9 @@ type PostUploadedForm struct {
|
||||
}
|
||||
|
||||
// PostUploadedAction
|
||||
// @Router /admin/uploads/post-uploaded-action [post]
|
||||
// @Bind body body
|
||||
//
|
||||
// @Router /admin/uploads/post-uploaded-action [post]
|
||||
// @Bind body body
|
||||
func (up *uploads) PostUploadedAction(ctx fiber.Ctx, body *PostUploadedForm) error {
|
||||
m, err := models.Medias.GetByHash(ctx.Context(), body.Md5)
|
||||
if err != nil && !errors.Is(err, qrm.ErrNoRows) {
|
||||
|
||||
@@ -16,25 +16,28 @@ type UserListQuery struct {
|
||||
type users struct{}
|
||||
|
||||
// List users
|
||||
// @Router /admin/users [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
//
|
||||
// @Router /admin/users [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
func (ctl *users) List(ctx fiber.Ctx, pagination *requests.Pagination, query *UserListQuery) (*requests.Pager, error) {
|
||||
cond := models.Users.BuildConditionWithKey(query.Keyword)
|
||||
return models.Users.List(ctx.Context(), pagination, cond)
|
||||
}
|
||||
|
||||
// Show user
|
||||
// @Router /admin/users/:id [get]
|
||||
// @Bind id path
|
||||
//
|
||||
// @Router /admin/users/:id [get]
|
||||
// @Bind id path
|
||||
func (ctl *users) Show(ctx fiber.Ctx, id int64) (*model.Users, error) {
|
||||
return models.Users.GetByID(ctx.Context(), id)
|
||||
}
|
||||
|
||||
// Articles show user bought articles
|
||||
// @Router /admin/users/:id/articles [get]
|
||||
// @Bind id path
|
||||
// @Bind pagination query
|
||||
//
|
||||
// @Router /admin/users/:id/articles [get]
|
||||
// @Bind id path
|
||||
// @Bind pagination query
|
||||
func (ctl *users) Articles(ctx fiber.Ctx, id int64, pagination *requests.Pagination) (*requests.Pager, error) {
|
||||
return models.Posts.Bought(ctx.Context(), id, pagination)
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ type auth struct {
|
||||
jwt *jwt.JWT
|
||||
}
|
||||
|
||||
// @Router /auth/login [get]
|
||||
// @Bind code query
|
||||
// @Bind state query
|
||||
// @Bind redirect query
|
||||
// @Router /auth/login [get]
|
||||
// @Bind code query
|
||||
// @Bind state query
|
||||
// @Bind redirect query
|
||||
func (ctl *auth) Login(ctx fiber.Ctx, code, state, redirect string) error {
|
||||
log.Debugf("code: %s, state: %s", code, state)
|
||||
|
||||
@@ -100,7 +100,7 @@ func (ctl *auth) Login(ctx fiber.Ctx, code, state, redirect string) error {
|
||||
}
|
||||
|
||||
// @Router /auth/wechat [get]
|
||||
// @Bind redirect query
|
||||
// @Bind redirect query
|
||||
func (ctl *auth) Wechat(ctx fiber.Ctx, redirect string) error {
|
||||
log.Debugf("%s, query: %v", ctx.OriginalURL(), ctx.Queries())
|
||||
|
||||
|
||||
@@ -22,8 +22,9 @@ type pays struct {
|
||||
}
|
||||
|
||||
// Callback
|
||||
// @Router /pay/callback/:channel [get]
|
||||
// @Bind channel path
|
||||
//
|
||||
// @Router /pay/callback/:channel [get]
|
||||
// @Bind channel path
|
||||
func (ctl *pays) Callback(ctx fiber.Ctx, channel string) error {
|
||||
log := log.WithField("method", "pays.Callback")
|
||||
|
||||
|
||||
@@ -29,10 +29,11 @@ type posts struct {
|
||||
}
|
||||
|
||||
// List posts
|
||||
// @Router /posts [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
// @Bind user local
|
||||
//
|
||||
// @Router /posts [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
// @Bind user local
|
||||
func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery, user *model.Users) (*requests.Pager, error) {
|
||||
log.Infof("ok", pagination, query.Keyword, user.ID)
|
||||
|
||||
@@ -99,9 +100,10 @@ type PostItem struct {
|
||||
}
|
||||
|
||||
// Show
|
||||
// @Router /posts/:id/show [get]
|
||||
// @Bind id path
|
||||
// @Bind user local
|
||||
//
|
||||
// @Router /posts/:id/show [get]
|
||||
// @Bind id path
|
||||
// @Bind user local
|
||||
func (ctl *posts) Show(ctx fiber.Ctx, id int64, user *model.Users) (*PostItem, error) {
|
||||
log.Infof("Fetching post with ID: %d", id)
|
||||
post, err := models.Posts.GetByID(ctx.Context(), id)
|
||||
@@ -148,9 +150,10 @@ type PlayUrl struct {
|
||||
}
|
||||
|
||||
// Play
|
||||
// @Router /posts/:id/play [get]
|
||||
// @Bind id path
|
||||
// @Bind user local
|
||||
//
|
||||
// @Router /posts/:id/play [get]
|
||||
// @Bind id path
|
||||
// @Bind user local
|
||||
func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, error) {
|
||||
log.Infof("Fetching play URL for post ID: %d", id)
|
||||
post, err := models.Posts.GetByID(ctx.Context(), id)
|
||||
@@ -181,10 +184,11 @@ func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, er
|
||||
}
|
||||
|
||||
// Mine posts
|
||||
// @Router /posts/mine [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
// @Bind user local
|
||||
//
|
||||
// @Router /posts/mine [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
// @Bind user local
|
||||
func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery, user *model.Users) (*requests.Pager, error) {
|
||||
log.Infof("Fetching posts for user with pagination: %+v and keyword: %v", pagination, query.Keyword)
|
||||
|
||||
@@ -236,9 +240,10 @@ func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *Li
|
||||
}
|
||||
|
||||
// Buy
|
||||
// @Router /posts/:id/buy [get]
|
||||
// @Bind id path
|
||||
// @Bind user local
|
||||
//
|
||||
// @Router /posts/:id/buy [get]
|
||||
// @Bind id path
|
||||
// @Bind user local
|
||||
func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPIPayParams, error) {
|
||||
post, err := models.Posts.GetByID(ctx.Context(), id)
|
||||
if err != nil {
|
||||
|
||||
@@ -58,12 +58,14 @@ func Provide(opts ...opt.Option) error {
|
||||
pays *pays,
|
||||
posts *posts,
|
||||
users *users,
|
||||
wechats *wechats,
|
||||
) (contracts.HttpRoute, error) {
|
||||
obj := &Routes{
|
||||
auth: auth,
|
||||
pays: pays,
|
||||
posts: posts,
|
||||
users: users,
|
||||
auth: auth,
|
||||
pays: pays,
|
||||
posts: posts,
|
||||
users: users,
|
||||
wechats: wechats,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -14,11 +14,12 @@ import (
|
||||
|
||||
// @provider contracts.HttpRoute atom.GroupRoutes
|
||||
type Routes struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
auth *auth
|
||||
pays *pays
|
||||
posts *posts
|
||||
users *users
|
||||
log *log.Entry `inject:"false"`
|
||||
auth *auth
|
||||
pays *pays
|
||||
posts *posts
|
||||
users *users
|
||||
wechats *wechats
|
||||
}
|
||||
|
||||
func (r *Routes) Prepare() error {
|
||||
@@ -95,4 +96,11 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
Body[ProfileForm]("form"),
|
||||
))
|
||||
|
||||
// 注册路由组: wechats
|
||||
router.Get("/wechats/js-sdk", DataFunc2(
|
||||
r.wechats.GetJsSDK,
|
||||
QueryParam[string]("url"),
|
||||
Local[*model.Users]("user"),
|
||||
))
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ type UserInfo struct {
|
||||
Username string `json:"username,omitempty"`
|
||||
}
|
||||
|
||||
// @Router /users/profile [get]
|
||||
// @Bind user local
|
||||
// @Router /users/profile [get]
|
||||
// @Bind user local
|
||||
func (ctl *users) Profile(ctx fiber.Ctx, user *model.Users) (*UserInfo, error) {
|
||||
return &UserInfo{
|
||||
ID: user.ID,
|
||||
@@ -34,9 +34,10 @@ type ProfileForm struct {
|
||||
}
|
||||
|
||||
// Update
|
||||
// @Router /users/username [put]
|
||||
// @Bind user local
|
||||
// @Bind form body
|
||||
//
|
||||
// @Router /users/username [put]
|
||||
// @Bind user local
|
||||
// @Bind form body
|
||||
func (ctl *users) Update(ctx fiber.Ctx, user *model.Users, form *ProfileForm) error {
|
||||
username := strings.TrimSpace(form.Username)
|
||||
if len([]rune(username)) > 12 {
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/providers/wechat"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type wechats struct {
|
||||
wechat *wechat.Client
|
||||
}
|
||||
|
||||
// @Router /wechat/js-ticket [get]
|
||||
// @Bind user local
|
||||
func (ctl *wechats) GetTicket(ctx fiber.Ctx, user *model.Users) (string, error) {
|
||||
return ctl.wechat.GetJSTicket(user.AuthToken.Data.AccessToken)
|
||||
}
|
||||
21
backend/app/http/wechats.go
Normal file
21
backend/app/http/wechats.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/providers/wechat"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type wechats struct {
|
||||
wechat *wechat.Client
|
||||
}
|
||||
|
||||
// GetJsSDK
|
||||
// @Router /wechats/js-sdk [get]
|
||||
// @Bind url query
|
||||
// @Bind user local
|
||||
func (ctl *wechats) GetJsSDK(ctx fiber.Ctx, url string, user *model.Users) (*wechat.JsSDK, error) {
|
||||
return ctl.wechat.GetJsSDK(user.AuthToken.Data.StableAccessToken, url)
|
||||
}
|
||||
Reference in New Issue
Block a user