fix: issues

This commit is contained in:
Rogee
2024-12-11 15:25:31 +08:00
parent 50bb28e90b
commit fefc9b2402
20 changed files with 2926 additions and 78 deletions

BIN
backend/__debug_bin457628671 Executable file

Binary file not shown.

View File

@@ -27,7 +27,7 @@ DevMode = true
[JWT]
ExpiresTime = "168h"
SignKey = "LiXi.Y@140202"
SigningKey = "LiXi.Y@140202"
[HashIDs]
Salt = "LiXi.Y@140202"

View File

@@ -15,6 +15,7 @@ type ListFilter struct {
type ListItem struct {
ID int64 `json:"-"`
Poster string `json:"poster"`
Hash string `json:"hash"`
Title string `json:"title"`
Description string `json:"description"`

View File

@@ -83,6 +83,7 @@ func (svc *Service) GetMediaByID(ctx context.Context, tenantId, userId, id int64
func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListItem {
return &ListItem{
ID: m.ID,
Poster: fmt.Sprintf("/static/%s/poster.jpg", m.Hash),
Hash: m.Hash,
Title: m.Title,
Description: m.Description,
@@ -96,7 +97,7 @@ func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListI
}
// List
func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *ListFilter) ([]ListItem, error) {
func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *ListFilter) ([]*ListItem, error) {
log := svc.log.WithField("method", "List")
boughtIDs, err := svc.GetUserBoughtMedias(ctx, tenantId, userId)
@@ -144,21 +145,8 @@ func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *Li
return nil, errors.Wrap(err, "query medias")
}
items := lo.Map(dest, func(m model.Medias, _ int) ListItem {
item := ListItem{
ID: m.ID,
Hash: m.Hash,
Title: m.Title,
Description: m.Description,
Duration: m.Duration,
Price: m.Price,
Discount: m.Discount,
Resources: m.Resources,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
Bought: lo.Contains(boughtIDs, m.ID),
}
return item
items := lo.Map(dest, func(m model.Medias, _ int) *ListItem {
return svc.ModelToListItem(ctx, &m)
})
return items, nil

View File

@@ -14,12 +14,15 @@ import (
)
func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("Begin")
defer log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("END")
// 如果请求存在 Authorization 头,则跳过
if len(c.GetReqHeaders()["Authorization"]) != 0 {
return c.Next()
}
log.WithField("module", "middleware.AuthUserInfo").Debugf("query: %v", c.Queries())
log.WithField("module", "middleware.AuthUserInfo").Debugf("%s, query: %v", c.OriginalURL(), c.Queries())
state := c.Query("state")
code := c.Query("code")

View File

@@ -11,6 +11,9 @@ import (
)
func (f *Middlewares) WeChatSilentAuth(c fiber.Ctx) error {
log.WithField("module", "middleware.WeChatSilentAuth").Debug("Begin")
defer log.WithField("module", "middleware.WeChatSilentAuth").Debug("END")
// if cookie not exists key "openid", then redirect to the wechat auth page
token := c.GetReqHeaders()["Authorization"]
if len(token) != 0 {
@@ -24,7 +27,7 @@ func (f *Middlewares) WeChatSilentAuth(c fiber.Ctx) error {
url = strings.ReplaceAll(url, c.BaseURL(), *f.app.BaseURI)
}
log.WithField("module", "middleware.SilentAuth").Debug("url:", url)
log.WithField("module", "middleware.SilentAuth").Debug("redirect_uri: ", url)
to, err := f.client.ScopeAuthorizeURL(
wechat.ScopeAuthorizeURLWithRedirectURI(url),

View File

@@ -7,6 +7,9 @@ import (
// 此方法用于微信首次接入时的数据验证
func (f *Middlewares) WeChatVerify(c fiber.Ctx) error {
log.WithField("module", "middleware.WeChatVerify").Debug("Begin")
defer log.WithField("module", "middleware.WeChatVerify").Debug("END")
// get the query parameters
signature := c.Query("signature")
timestamp := c.Query("timestamp")

View File

@@ -2,9 +2,12 @@ package middlewares
import (
"github.com/gofiber/fiber/v3"
log "github.com/sirupsen/logrus"
)
func (f *Middlewares) DebugMode(c fiber.Ctx) error {
log.WithField("module", "middleware.DebugMode").Debug("Begin")
defer log.WithField("module", "middleware.DebugMode").Debug("END")
// fullURI := c.Request().URI().FullURI()
// host := c.BaseURL()
// fmt.Println(strings.Split(c.Path(), "/"))

View File

@@ -8,6 +8,9 @@ import (
)
func (f *Middlewares) ProcessResponse(c fiber.Ctx) error {
log.WithField("module", "middleware.ProcessResponse").Debug("Begin")
defer log.WithField("module", "middleware.ProcessResponse").Debug("END")
if err := c.Next(); err != nil {
log.WithError(err).Error("process response error")
@@ -26,5 +29,5 @@ func (f *Middlewares) ProcessResponse(c fiber.Ctx) error {
return errorx.Wrap(err).Response(c)
}
return c.Next()
return nil
}

View File

@@ -15,6 +15,9 @@ import (
"git.ipao.vip/rogeecn/atom"
"git.ipao.vip/rogeecn/atom/container"
"git.ipao.vip/rogeecn/atom/contracts"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/favicon"
"github.com/gofiber/fiber/v3/middleware/static"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"go.uber.org/dig"
@@ -50,6 +53,7 @@ type Http struct {
dig.In
App *app.Config
Storage *storage.Config
Service *http.Service
Initials []contracts.Initial `group:"initials"`
Routes []contracts.HttpRoute `group:"routes"`
@@ -61,16 +65,31 @@ func Serve(cmd *cobra.Command, args []string) error {
if http.App.Mode == app.AppModeDevelopment {
log.SetLevel(log.DebugLevel)
}
engine := http.Service.Engine
mid := http.Middlewares
http.Service.Engine.Use(mid.DebugMode)
http.Service.Engine.Use(mid.ProcessResponse)
http.Service.Engine.Use(mid.WeChatVerify)
http.Service.Engine.Use(mid.WeChatAuthUserInfo)
http.Service.Engine.Use(mid.WeChatSilentAuth)
http.Service.Engine.Use(mid.ParseJWT)
engine.Use(mid.DebugMode)
engine.Use(mid.ProcessResponse)
wechatGroup := engine.Group("/t")
wechatGroup.Use(mid.WeChatVerify)
wechatGroup.Use(mid.WeChatAuthUserInfo)
wechatGroup.Use(mid.WeChatSilentAuth)
wechatGroup.Get("*", func(c fiber.Ctx) error {
return c.SendString("ok")
})
http.Service.Engine.Use(favicon.New(favicon.Config{
Data: []byte{},
}))
http.Service.Engine.Use("/static", static.New(http.Storage.Path, static.Config{
Browse: true,
}))
group := http.Service.Engine.Group("/v1")
group.Use(mid.ParseJWT)
for _, route := range http.Routes {
route.Register(group)
}

View File

@@ -7,6 +7,7 @@ import (
"backend/modules/medias"
"backend/modules/users"
"backend/providers/app"
"backend/providers/hashids"
"backend/providers/postgres"
"backend/providers/storage"
@@ -21,6 +22,7 @@ func defaultProviders(providers ...container.ProviderContainer) container.Provid
app.DefaultProvider(),
storage.DefaultProvider(),
postgres.DefaultProvider(),
hashids.DefaultProvider(),
}, providers...)
}

View File

@@ -1,4 +1,4 @@
@Token=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcGVuX2lkIjoib01MYTV0eUoydlJIYS1ISTRDTUVrSHp0cTNlVSIsInRlbmFudCI6InlwbCIsInVzZXJfaWQiOjEsInRlbmFudF9pZCI6MSwiZXhwIjoxNzM0MzQ5NDA3LCJuYmYiOjE3MzM3NDQ1OTd9.iQtyxfFDXht4mpCYSllv7opFjYuUHO22WwBl7hAzQYw
@Token=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcGVuX2lkIjoib01MYTV0eUoydlJIYS1ISTRDTUVrSHp0cTNlVSIsInRlbmFudCI6InlwbCIsInVzZXJfaWQiOjEsInRlbmFudF9pZCI6MiwiZXhwIjoxNzM0NDkxNzkwLCJuYmYiOjE3MzM4ODY5ODB9.qwG-Z3bkh1RD7wYVH7DTLRTdjHYrCW0aSnghhNlmOzo
@host=http://localhost:9600
### Get Medias

View File

@@ -5,9 +5,9 @@
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>动态曲谱</title>
<title>加载中...</title>
<script>
var __GA = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcGVuX2lkIjoib01MYTV0eUoydlJIYS1ISTRDTUVrSHp0cTNlVSIsInRlbmFudCI6InlwbCIsInVzZXJfaWQiOjEsInRlbmFudF9pZCI6MiwiZXhwIjoxNzM0NTAzMDQzLCJuYmYiOjE3MzM4OTgyMzN9.wl4c-4DdZ-qC7MJHMD8rP2zPiTwBK7J_YKw2im3ve9U"
</script>
</head>

2719
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -9,18 +9,19 @@
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.9",
"pinia": "^2.2.6",
"vant": "^4.9.9",
"vue": "^3.5.12",
"vue-router": "^4.4.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.1.4",
"vite": "^5.4.10",
"vite-plugin-vue-devtools": "^7.5.4",
"@vant/auto-import-resolver": "^1.1.0",
"@vitejs/plugin-vue": "^5.1.4",
"less": "^4.1.3",
"unplugin-auto-import": "^0.17.5",
"unplugin-vue-components": "^0.26.0"
"unplugin-auto-import": "^0.17.8",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.4.10",
"vite-plugin-vue-devtools": "^7.5.4"
}
}
}

View File

@@ -0,0 +1,30 @@
<template>
<van-card
v-for="item in list"
:key="item.Hash"
price="2.00"
desc="描述信息"
title="商品标题"
thumb="https://fastly.jsdelivr.net/van-listt/assets/ipad.jpeg"
lazy-load="true"
@click="play(item)"
>
<template #tags>
<van-space>
<van-tag plain type="primary">视频</van-tag>
<van-tag plain type="primary">音频</van-tag>
<van-tag plain type="primary">PDF</van-tag>
</van-space>
</template>
</van-card>
</template>
<script setup>
import { defineProps } from "vue";
const props = defineProps({
list: {
type: Array,
required: true,
},
});
</script>

View File

@@ -0,0 +1,30 @@
import axios from 'axios'; // 引入axios
console.log("__GA: ", __GA)
const service = axios.create({
baseURL: "/v1",
timeout: 30,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + __GA,
},
})
// http request 拦截器
service.interceptors.request.use(
(config) => {
return config
},
(error) => {
}
)
// http response 拦截器
service.interceptors.response.use(
(response) => {
return response
},
(error) => {
}
)
export default service

View File

@@ -3,27 +3,26 @@
<van-back-top bottom="80" />
<van-list
v-model:loading="loading"
:finished="finished"
finished-text="没有更多了"
@load="onLoad"
>
<van-card
v-for="item in list"
:key="item"
price="2.00"
desc="描述信息"
title="商品标题"
thumb="https://fastly.jsdelivr.net/van-listt/assets/ipad.jpeg"
lazy-load="true"
@click="play(item)"
>
<van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" offset="100" @load="loadData">
<van-card v-for="item in items" :key="item" :desc="item.title" :thumb="item.poster" @click="play(item)">
<template #title>
<span>{{ item.title }}</span>
</template>
<template #price>
<template v-if="item.discount == 100"> 价格{{ item.price }} </template>
<template v-else>
<del>{{ item.price }}</del>
<span>{{ (item.price * item.discount) / 100 }}</span>
</template>
</template>
<template #tags>
<van-space>
<van-tag plain type="primary">视频</van-tag>
<van-tag plain type="primary"></van-tag>
<van-tag plain type="primary">PDF</van-tag>
<van-tag v-for="resource in item.resources" plain type="primary">
<template v-if="resource == 'video'"></template>
<template v-if="resource == 'audio'">音频</template>
</van-tag>
</van-space>
</template>
</van-card>
@@ -33,35 +32,58 @@
<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import request from "@/utils/request";
const router = useRouter();
const search = ref("");
const list = ref([]);
const items = ref([]);
const loading = ref(false);
const finished = ref(false);
const onLoad = () => {
// 异步更新数据
// setTimeout 仅做示例,真实场景中一般为 ajax 请求
setTimeout(() => {
for (let i = 0; i < 10; i++) {
list.value.push(list.value.length + 1);
}
const offset = ref("");
// 加载状态结束
loading.value = false;
// 数据全部加载完成
if (list.value.length >= 40) {
finished.value = true;
}
}, 1000);
};
const onLoad = () => { };
const play = (item) => {
// vue router goto play view
console.log("play", item);
console.log("play -", item);
router.push({ name: "play", params: { id: item } });
};
const loadData = () => {
loading.value = true;
console.log("loadData");
// request /v1/medias
const data = {
offset: offset.value,
action: 0,
};
request
.post("/medias", data)
.then((res) => {
console.log(res);
if (offset.value == "") {
items.value = res.data;
} else {
items.value = items.value.concat(res.data);
if (res.data.length == 0) {
finished.value = true;
}
}
offset.value = res.data[res.data.length - 1].hash;
})
.catch((err) => {
console.error(err);
})
.finally(() => {
loading.value = true;
// finished.value = true;
});
};
onMounted(() => {
// loadData();
});
</script>

View File

@@ -5,18 +5,39 @@ import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { defineConfig } from "vite";
import vueDevTools from 'vite-plugin-vue-devtools';
// import vueDevTools from 'vite-plugin-vue-devtools';
// https://vite.dev/config/
export default defineConfig({
server: {
proxy: {
'^/static': {
target: 'http://localhost:9600',
changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, '')
},
'^/v1': {
target: 'http://localhost:9600',
changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, '')
},
},
},
plugins: [
vue(),
vueDevTools(),
// vueDevTools(),
AutoImport({
imports: [
'vue',
'vue-router',
'pinia',
],
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
resolvers: [
VantResolver(),
],
}),
],
resolve: {

View File

@@ -8,10 +8,10 @@
}
],
"settings": {
"vue3snippets.enable-compile-vue-file-on-did-save-code": true,
"vue3snippets.enable-compile-vue-file-on-did-save-code": false,
"cSpell.words": [
"qvyun"
],
"git.ignoreLimitWarning": true
}
}
}