feat: add frpc
This commit is contained in:
@@ -80,6 +80,7 @@ func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *Li
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PostItem struct {
|
type PostItem struct {
|
||||||
|
Bought bool `json:"bought"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
@@ -94,7 +95,8 @@ type PostItem struct {
|
|||||||
// Show
|
// Show
|
||||||
// @Router /api/posts/:id [get]
|
// @Router /api/posts/:id [get]
|
||||||
// @Bind id path
|
// @Bind id path
|
||||||
func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) {
|
// @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)
|
log.Infof("Fetching post with ID: %d", id)
|
||||||
post, err := models.Posts.GetByID(ctx.Context(), id)
|
post, err := models.Posts.GetByID(ctx.Context(), id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -102,6 +104,11 @@ func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bought, err := models.Users.HasBought(ctx.Context(), user.ID, post.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
medias, err := models.Posts.GetMediaByIds(ctx.Context(), post.HeadImages.Data)
|
medias, err := models.Posts.GetMediaByIds(ctx.Context(), post.HeadImages.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -125,6 +132,7 @@ func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) {
|
|||||||
Likes: post.Likes,
|
Likes: post.Likes,
|
||||||
Tags: post.Tags.Data,
|
Tags: post.Tags.Data,
|
||||||
HeadImages: mediaUrls,
|
HeadImages: mediaUrls,
|
||||||
|
Bought: bought,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,9 +58,10 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
Local[*model.Users]("user"),
|
Local[*model.Users]("user"),
|
||||||
))
|
))
|
||||||
|
|
||||||
router.Get("/api/posts/:id", DataFunc1(
|
router.Get("/api/posts/:id", DataFunc2(
|
||||||
r.posts.Show,
|
r.posts.Show,
|
||||||
PathParam[int64]("id"),
|
PathParam[int64]("id"),
|
||||||
|
Local[*model.Users]("user"),
|
||||||
))
|
))
|
||||||
|
|
||||||
router.Get("/api/posts/:id/play", DataFunc2(
|
router.Get("/api/posts/:id/play", DataFunc2(
|
||||||
|
|||||||
9
backend/frpc.toml
Normal file
9
backend/frpc.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
serverAddr = "39.105.111.158"
|
||||||
|
serverPort = 1422
|
||||||
|
|
||||||
|
[[proxies]]
|
||||||
|
name = "test-http"
|
||||||
|
type = "tcp"
|
||||||
|
localIP = "127.0.0.1"
|
||||||
|
localPort = 8088
|
||||||
|
remotePort = 1423
|
||||||
@@ -120,14 +120,14 @@ onUnmounted(() => {
|
|||||||
<div class="animate-spin rounded-full h-8 w-8 border-4 border-gray-200 border-t-blue-600"></div>
|
<div class="animate-spin rounded-full h-8 w-8 border-4 border-gray-200 border-t-blue-600"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="article && !article.purchased"
|
<div v-if="article && !article.bought"
|
||||||
class="fixed bottom-0 left-0 right-0 bg-white border-t border-gray-200 p-4">
|
class="fixed bottom-0 left-0 right-0 bg-white border-t border-gray-200 p-4">
|
||||||
<div class="flex items-center justify-between max-w-md mx-auto">
|
<div class="flex items-center justify-between max-w-md mx-auto">
|
||||||
<div class="text-red-600 font-bold text-xl">
|
<div class="text-orange-600 font-bold text-xl">
|
||||||
¥{{ article.price }}
|
¥{{ (article.price / 100).toFixed(2) }}
|
||||||
</div>
|
</div>
|
||||||
<button @click="handleBuy" :disabled="buying"
|
<button @click="handleBuy" :disabled="buying"
|
||||||
class="bg-blue-600 text-white px-8 py-3 rounded-full hover:bg-blue-700 active:bg-blue-800 transition-colors disabled:opacity-50">
|
class="bg-orange-600 text-white px-8 py-3 rounded-full hover:bg-orange-500 active:bg-orange-600 transition-colors disabled:opacity-50">
|
||||||
<span v-if="buying">处理中...</span>
|
<span v-if="buying">处理中...</span>
|
||||||
<span v-else>立即购买</span>
|
<span v-else>立即购买</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user