From 0d9eade6a747380fd9b719ab030fc813660defc6 Mon Sep 17 00:00:00 2001 From: 1005281342 <1005281342@qq.com> Date: Sun, 29 May 2022 16:13:43 +0800 Subject: [PATCH 01/22] =?UTF-8?q?docs:=20=E5=91=BD=E4=BB=A4`go=20build=20.?= =?UTF-8?q?`=E6=9E=84=E5=BB=BA=E4=BA=A7=E7=89=A9=E5=90=8D=E5=AD=97?= =?UTF-8?q?=E4=B8=BA=E9=A1=B9=E7=9B=AE=E5=90=8D=E5=8D=B3paopao-ce=EF=BC=8C?= =?UTF-8?q?=E6=95=85=E8=B0=83=E6=95=B4=E7=BC=96=E8=AF=91=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E4=B8=BA`go=20build=20-o=20paopao-api=20.`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 08905e30..a9bead35 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ PaoPao主要由以下优秀的开源项目/工具构建 3. 编译后端 ```sh go mod download - go build . + go build -o paopao-api . ``` 4. 启动后端 ```sh From 76a8fdffd9aa45379ca1744d772fb9ae7a6df471 Mon Sep 17 00:00:00 2001 From: orzi! <1063614727@qq.com> Date: Mon, 30 May 2022 17:19:59 +0800 Subject: [PATCH 02/22] fix: content-main width --- web/src/assets/css/main.less | 7 ++++++- web/src/components/rightbar.vue | 2 +- web/src/components/sidebar.vue | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/web/src/assets/css/main.less b/web/src/assets/css/main.less index ebc806a5..b33e6dac 100644 --- a/web/src/assets/css/main.less +++ b/web/src/assets/css/main.less @@ -1,3 +1,8 @@ +:root { + // 如果要变更中间栏的大小,修改此处即可 + --content-main: 500px; +} + .app-container { margin: 0; @@ -16,7 +21,7 @@ .content-wrap { width: 100%; - max-width: 500px; + max-width: var(--content-main); position: relative; } diff --git a/web/src/components/rightbar.vue b/web/src/components/rightbar.vue index c4d363b9..ee6c6035 100644 --- a/web/src/components/rightbar.vue +++ b/web/src/components/rightbar.vue @@ -119,7 +119,7 @@ onMounted(() => { .rightbar-wrap { width: 240px; position: fixed; - left: calc(50% + 260px); + left: calc(50% + var(--content-main) / 2 + 10px); .search-wrap { margin: 12px 0; } diff --git a/web/src/components/sidebar.vue b/web/src/components/sidebar.vue index 0749f6e6..bde6a712 100644 --- a/web/src/components/sidebar.vue +++ b/web/src/components/sidebar.vue @@ -279,7 +279,7 @@ window.$message = useMessage(); width: 200px; height: 100vh; position: fixed; - right: calc(50% + 260px); + right: calc(50% + var(--content-main) / 2 + 10px); padding: 12px 0; box-sizing: border-box; .n-menu .n-menu-item-content::before { From 8b33f6ac3c01036b86e0d1aab92e1c160c58f4e1 Mon Sep 17 00:00:00 2001 From: alimy Date: Mon, 30 May 2022 23:27:41 +0800 Subject: [PATCH 03/22] use internal implement instead github.com/yinheli/qqwry to get ip location info --- go.mod | 3 +- go.sum | 2 - pkg/util/ip.go | 10 +- pkg/util/iploc/iploc.go | 128 ++++++++++++++++++++++++++ pkg/util/iploc/iploc_test.go | 25 +++++ qqwry.dat => pkg/util/iploc/qqwry.dat | Bin 6 files changed, 157 insertions(+), 11 deletions(-) create mode 100644 pkg/util/iploc/iploc.go create mode 100644 pkg/util/iploc/iploc_test.go rename qqwry.dat => pkg/util/iploc/qqwry.dat (100%) diff --git a/go.mod b/go.mod index 3c326ad5..cb0ddd07 100644 --- a/go.mod +++ b/go.mod @@ -23,8 +23,7 @@ require ( github.com/smartwalle/alipay/v3 v3.1.7 github.com/spf13/viper v1.10.1 github.com/ugorji/go v1.2.7 // indirect - github.com/yinheli/mahonia v0.0.0-20131226213531-0eef680515cc // indirect - github.com/yinheli/qqwry v0.0.0-20160229183603-f50680010f4a + github.com/yinheli/mahonia v0.0.0-20131226213531-0eef680515cc golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 // indirect golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect diff --git a/go.sum b/go.sum index 29160250..19759b67 100644 --- a/go.sum +++ b/go.sum @@ -675,8 +675,6 @@ github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6Ut github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yinheli/mahonia v0.0.0-20131226213531-0eef680515cc h1:7VHQaaNwHymWbj8lAcXMYX1qopebSBHwYC3ceXLWONU= github.com/yinheli/mahonia v0.0.0-20131226213531-0eef680515cc/go.mod h1:Pcc297eVCbkDBBVq8FbnI+qDUeIMrHy4Bo7nveAuCAs= -github.com/yinheli/qqwry v0.0.0-20160229183603-f50680010f4a h1:VUPXGL4N1B5xqomxI4vZn0momgleh0hcH0PE/oIOsAI= -github.com/yinheli/qqwry v0.0.0-20160229183603-f50680010f4a/go.mod h1:Zva9ErVtC2arl+9xtHwiXujgejX1S3VpOYExADJ9kio= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/pkg/util/ip.go b/pkg/util/ip.go index 5e657944..3aaa13c1 100644 --- a/pkg/util/ip.go +++ b/pkg/util/ip.go @@ -1,12 +1,8 @@ package util -import ( - "github.com/yinheli/qqwry" -) +import "github.com/rocboss/paopao-ce/pkg/util/iploc" func GetIPLoc(ip string) string { - q := qqwry.NewQQwry("qqwry.dat") - q.Find(ip) - - return q.Country + country, _ := iploc.Find(ip) + return country } diff --git a/pkg/util/iploc/iploc.go b/pkg/util/iploc/iploc.go new file mode 100644 index 00000000..0a103738 --- /dev/null +++ b/pkg/util/iploc/iploc.go @@ -0,0 +1,128 @@ +package iploc + +import ( + _ "embed" + "encoding/binary" + "net" + + "github.com/yinheli/mahonia" +) + +// Note: This file is a modified version of https://github.com/yinheli/qqwry. + +//go:embed qqwry.dat +var qqwry []byte + +const ( + cIndexLen = 7 + cRedirectMode1 = 0x01 + cRedirectMode2 = 0x02 +) + +// Find get country and city base ip +func Find(ip string) (string, string) { + offset := searchIndex(binary.BigEndian.Uint32(net.ParseIP(ip).To4())) + if offset <= 0 { + return "", "" + } + var country, area []byte + mode := readMode(offset + 4) + if mode == cRedirectMode1 { + countryOffset := readUInt24(offset + 5) + mode = readMode(countryOffset) + if mode == cRedirectMode2 { + c := readUInt24(countryOffset + 1) + country = readString(c) + countryOffset += 4 + } else { + country = readString(countryOffset) + countryOffset += uint32(len(country) + 1) + } + area = readArea(countryOffset) + } else if mode == cRedirectMode2 { + countryOffset := readUInt24(offset + 5) + country = readString(countryOffset) + area = readArea(offset + 8) + } else { + country = readString(offset + 4) + area = readArea(offset + uint32(5+len(country))) + } + enc := mahonia.NewDecoder("gbk") + Country := enc.ConvertString(string(country)) + City := enc.ConvertString(string(area)) + return Country, City +} + +func readMode(offset uint32) byte { + return qqwry[offset] +} + +func readArea(offset uint32) []byte { + mode := readMode(offset) + if mode == cRedirectMode1 || mode == cRedirectMode2 { + areaOffset := readUInt24(offset + 1) + if areaOffset == 0 { + return []byte("") + } else { + return readString(areaOffset) + } + } else { + return readString(offset) + } +} + +func readString(offset uint32) []byte { + data := make([]byte, 0, 30) + for { + if qqwry[offset] == 0 { + break + } + data = append(data, qqwry[offset]) + offset++ + } + return data +} + +func searchIndex(ip uint32) uint32 { + header := qqwry[:8] + start := binary.LittleEndian.Uint32(header[:4]) + end := binary.LittleEndian.Uint32(header[4:]) + for { + mid := getMiddleOffset(start, end) + buf := qqwry[mid : mid+cIndexLen] + ipaddr := binary.LittleEndian.Uint32(buf[:4]) + if end-start == cIndexLen { + offset := byte3ToUInt32(buf[4:]) + // TODO: 这里可能有bug,需要优化 + if ip < binary.LittleEndian.Uint32(qqwry[end:end+4]) { + return offset + } else { + return 0 + } + } + // 找到的比较大,向前移 + if ipaddr > ip { + end = mid + } else if ipaddr < ip { // 找到的比较小,向后移 + start = mid + } else { + return byte3ToUInt32(buf[4:]) + } + } +} + +func readUInt24(offset uint32) uint32 { + return byte3ToUInt32(qqwry[offset : offset+3]) +} + +func getMiddleOffset(start uint32, end uint32) uint32 { + records := ((end - start) / cIndexLen) >> 1 + return start + records*cIndexLen +} + +func byte3ToUInt32(data []byte) uint32 { + i := uint32(data[0]) & 0xff + i |= (uint32(data[1]) << 8) & 0xff00 + i |= (uint32(data[2]) << 16) & 0xff0000 + return i +} diff --git a/pkg/util/iploc/iploc_test.go b/pkg/util/iploc/iploc_test.go new file mode 100644 index 00000000..4754e86d --- /dev/null +++ b/pkg/util/iploc/iploc_test.go @@ -0,0 +1,25 @@ +package iploc + +import ( + "testing" +) + +func TestFind(t *testing.T) { + for _, data := range []struct { + ip string + country string + city string + }{ + {ip: "127.0.0.1", country: "本机地址", city: " CZ88.NET"}, + {ip: "180.89.94.9", country: "北京市", city: "鹏博士宽带"}, + } { + country, city := Find(data.ip) + t.Logf("ip:%v, country:%v, city:%v", data.ip, country, city) + if country != data.country { + t.Errorf("find ip:%s expect country: %s got: %s", data.ip, data.country, country) + } + if city != data.city { + t.Errorf("find ip:%s expect city: %s got: %s", data.ip, data.city, city) + } + } +} diff --git a/qqwry.dat b/pkg/util/iploc/qqwry.dat similarity index 100% rename from qqwry.dat rename to pkg/util/iploc/qqwry.dat From 2de528ba3f2fa5e7b641e90357488592aa8a4360 Mon Sep 17 00:00:00 2001 From: ROC Date: Tue, 31 May 2022 10:34:59 +0800 Subject: [PATCH 04/22] fix: posts query param --- web/src/types/NetParams.d.ts | 2 +- web/src/views/Home.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/types/NetParams.d.ts b/web/src/types/NetParams.d.ts index 435e0ed1..50bb4987 100644 --- a/web/src/types/NetParams.d.ts +++ b/web/src/types/NetParams.d.ts @@ -75,7 +75,7 @@ declare module NetParams { interface PostGetPosts { query: string | null, - type: number, + type: string, page: number, page_size: number } diff --git a/web/src/views/Home.vue b/web/src/views/Home.vue index 179f3294..5122d653 100644 --- a/web/src/views/Home.vue +++ b/web/src/views/Home.vue @@ -67,7 +67,7 @@ const loadPosts = () => { loading.value = true; getPosts({ query: route.query.q ? decodeURIComponent(route.query.q as string) : null, - type: +(route.query.t as string), + type: route.query.t as string, page: page.value, page_size: pageSize.value, }) From a2e2777678bb95a1791162f8a13dbddce7c4c478 Mon Sep 17 00:00:00 2001 From: ROC Date: Tue, 31 May 2022 10:53:08 +0800 Subject: [PATCH 05/22] fix: dockerfile --- Dockerfile | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index f6034422..38ea62e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ # build app FROM golang AS build-env -ADD . /paopao-api +ADD . /paopao-ce -WORKDIR /paopao-api +WORKDIR /paopao-ce RUN CGO_ENABLED=0 go build . @@ -14,14 +14,13 @@ ENV TZ=Asia/Shanghai RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates -COPY --from=build-env /paopao-api/paopao-api /usr/bin/paopao-api -COPY --from=build-env /paopao-api/comic.ttf /comic.ttf -COPY --from=build-env /paopao-api/qqwry.dat /qqwry.dat -COPY --from=build-env /paopao-api/configs /configs +COPY --from=build-env /paopao-ce/paopao-ce /usr/bin/paopao-ce +COPY --from=build-env /paopao-ce/comic.ttf /comic.ttf +COPY --from=build-env /paopao-ce/configs /configs EXPOSE 8000 -CMD ["paopao-api"] +CMD ["paopao-ce"] # HEALTHCHECK -HEALTHCHECK --interval=5s --timeout=3s --retries=3 CMD ps -ef | grep paopao-api || exit 1 +HEALTHCHECK --interval=5s --timeout=3s --retries=3 CMD ps -ef | grep paopao-ce || exit 1 From d5e205ca85297c94ac165fb91df941f6c3699dc2 Mon Sep 17 00:00:00 2001 From: orzi! <1063614727@qq.com> Date: Tue, 31 May 2022 18:42:48 +0800 Subject: [PATCH 06/22] feat: fix typescript --- web/src/api/auth.ts | 43 +---- web/src/api/post.ts | 167 +++++------------ web/src/api/user.ts | 130 +++++-------- web/src/components/comment-item.vue | 4 +- web/src/components/compose-comment.vue | 2 +- web/src/components/compose.vue | 8 +- web/src/components/post-attachment.vue | 4 +- web/src/components/post-detail.vue | 2 +- web/src/components/post-image.vue | 2 +- web/src/components/post-item.vue | 2 +- web/src/components/post-link.vue | 2 +- web/src/components/post-video.vue | 2 +- web/src/types/NetParams.d.ts | 81 +++++++- web/src/types/NetReq.d.ts | 72 ++++++- web/src/types/item.d.ts | 249 ++++++++++++++++++++++--- web/src/utils/request.ts | 6 +- web/src/views/Post.vue | 2 +- web/src/views/Setting.vue | 6 +- 18 files changed, 480 insertions(+), 304 deletions(-) diff --git a/web/src/api/auth.ts b/web/src/api/auth.ts index e6513e92..904e9bba 100644 --- a/web/src/api/auth.ts +++ b/web/src/api/auth.ts @@ -1,29 +1,16 @@ -import request from '@/utils/request'; +import { request } from '@/utils/request'; - -/** - * 用户登录 - * @param {Object} params - * - @param {string} username - * - @param {string} password - * @returns Promise - */ -export const userLogin = (params: NetParams.AuthUserLogin = {}) => { +/** 用户登录 */ +export const userLogin = (params: NetParams.AuthUserLogin): Promise => { return request({ method: 'post', url: '/auth/login', data: params, - }) as unknown as Promise; + }); }; -/** - * 注册用户 - * @param {Object} params - * - @param {string} username - * - @param {string} password - * @returns Promise - */ -export const userRegister = (params = {}) => { +/** 注册用户 */ +export const userRegister = (params: NetParams.AuthUserRegister): Promise => { return request({ method: 'post', url: '/auth/register', @@ -31,12 +18,8 @@ export const userRegister = (params = {}) => { }); }; -/** - * 用户信息 - * @param {Object} params - * @returns Promise - */ -export const userInfo = (token = '') => { +/** 用户信息 */ +export const userInfo = (token: NetParams.AuthUserInfo = ""): Promise => { return request({ method: 'get', url: '/user/info', @@ -46,14 +29,8 @@ export const userInfo = (token = '') => { }); }; -/** - * 修改用户密码 - * @param {Object} params - * - @param {string} password 新密码 - * - @param {string} old_password 旧密码 - * @returns Promise - */ -export const updateUserPassword = (data: any) => { +/** 修改用户密码,该接口暂时未使用 */ +export const updateUserPassword = (data: NetParams.AuthUpdateUserPassword): Promise => { return request({ method: 'post', url: '/api/user/password', diff --git a/web/src/api/post.ts b/web/src/api/post.ts index 3488eed5..49386cc6 100644 --- a/web/src/api/post.ts +++ b/web/src/api/post.ts @@ -1,132 +1,88 @@ -import request from '@/utils/request'; +import { request } from '@/utils/request'; -/** - * 获取动态列表 - * @param {Object} params - * @returns Promise - */ -export const getPosts = (params: NetParams.PostGetPosts) => { +/** 获取动态列表 */ +export const getPosts = (params: NetParams.PostGetPosts): Promise => { return request({ method: 'get', url: '/posts', params - }) as unknown as Promise; + }); }; -/** - * 获取标签列表 - * @param {Object} params - * @returns Promise - */ -export const getTags = (params: NetParams.PostGetTags) => { +/** 获取标签列表 */ +export const getTags = (params: NetParams.PostGetTags): Promise => { return request({ method: 'get', url: '/tags', params - }) as unknown as Promise; + }); }; -/** - * 获取动态详情 - * @param {Object} params - * @returns Promise - */ -export const getPost = (params: NetParams.PostGetPost) => { +/** 获取动态详情 */ +export const getPost = (params: NetParams.PostGetPost): Promise => { return request({ method: 'get', url: '/post', params - }) as unknown as Promise; + }); }; -/** - * 获取动态点赞状态 - * @param {Object} params - * @returns Promise - */ -export const getPostStar = (params: NetParams.PostPostStar) => { +/** 获取动态点赞状态 */ +export const getPostStar = (params: NetParams.PostPostStar): Promise => { return request({ method: 'get', url: '/post/star', params - }) as unknown as Promise; + }); }; -/** - * 动态点赞 - * @param {Object} data - * @returns Promise - */ -export const postStar = (data: NetParams.PostPostStar) => { +/** 动态点赞 */ +export const postStar = (data: NetParams.PostPostStar): Promise => { return request({ method: 'post', url: '/post/star', data - }) as unknown as Promise; + }); }; -/** - * 获取动态收藏状态 - * @param {Object} params - * @returns Promise - */ -export const getPostCollection = (params: NetParams.PostGetPostCollection) => { +/** 获取动态收藏状态 */ +export const getPostCollection = (params: NetParams.PostGetPostCollection): Promise => { return request({ method: 'get', url: '/post/collection', params - }) as unknown as Promise; + }); }; -/** - * 动态收藏 - * @param {Object} data - * @returns Promise - */ -export const postCollection = (data: NetParams.PostPostCollection) => { +/** 动态收藏 */ +export const postCollection = (data: NetParams.PostPostCollection): Promise => { return request({ method: 'post', url: '/post/collection', data - }) as unknown as Promise; + }); }; -/** - * 获取动态评论列表 - * @param {Object} params - * @returns Promise - */ -export const getPostComments = (params: NetParams.PostGetPostComments) => { +/** 获取动态评论列表 */ +export const getPostComments = (params: NetParams.PostGetPostComments): Promise => { return request({ method: 'get', url: '/post/comments', params - }) as unknown as Promise; + }); }; -/** - * 发布动态 - * @param {Object} data - * - @param {array} contents 内容 - * - @param {array} users at用户 - * - @param {array} tags 话题 - * @returns Promise - */ -export const createPost = (data: NetParams.PostCreatePost) => { +/** 发布动态 */ +export const createPost = (data: NetParams.PostCreatePost): Promise => { return request({ method: 'post', url: '/post', data - }) as unknown as Promise; + }); }; -/** - * 删除动态 - * @param {Object} data - * - @param {number} id - * @returns Promise - */ -export const deletePost = (data: any) => { +/** 删除动态 */ +export const deletePost = (data: NetParams.PostDeletePost): Promise => { return request({ method: 'delete', url: '/post', @@ -134,42 +90,26 @@ export const deletePost = (data: any) => { }); }; -/** - * 锁定/解锁动态 - * @param {Object} data - * - @param {number} id - * @returns Promise - */ -export const lockPost = (data: NetParams.PostLockPost) => { +/** 锁定/解锁动态 */ +export const lockPost = (data: NetParams.PostLockPost): Promise => { return request({ method: 'post', url: '/post/lock', data - }) as unknown as Promise; + }); }; -/** - * 置顶/取消置顶动态 - * @param {Object} data - * - @param {number} id - * @returns Promise - */ -export const stickPost = (data: NetParams.PostStickPost) => { +/** 置顶/取消置顶动态 */ +export const stickPost = (data: NetParams.PostStickPost): Promise => { return request({ method: 'post', url: '/post/stick', data - }) as unknown as Promise; + }); }; -/** - * 发布动态评论 - * @param {Object} data - * - @param {array} contents 内容 - * - @param {array} users at用户 - * @returns Promise - */ -export const createComment = (data: any) => { +/** 发布动态评论 */ +export const createComment = (data: NetParams.PostCreateComment): Promise => { return request({ method: 'post', url: '/post/comment', @@ -177,13 +117,8 @@ export const createComment = (data: any) => { }); }; -/** - * 删除评论 - * @param {Object} data - * - @param {number} id - * @returns Promise - */ -export const deleteComment = (data: any) => { +/** 删除评论 */ +export const deleteComment = (data: NetParams.PostDeleteComment): Promise => { return request({ method: 'delete', url: '/post/comment', @@ -191,15 +126,8 @@ export const deleteComment = (data: any) => { }); }; -/** - * 发布评论回复 - * @param {Object} data - * - @param {string} content 内容 - * - @param {number} comment_id 评论ID - * - @param {number} at_user_id at用户ID - * @returns Promise - */ -export const createCommentReply = (data: any) => { +/** 发布评论回复 */ +export const createCommentReply = (data: NetParams.PostCreateCommentReply): Promise => { return request({ method: 'post', url: '/post/comment/reply', @@ -207,16 +135,11 @@ export const createCommentReply = (data: any) => { }); }; -/** - * 删除评论回复 - * @param {Object} data - * - @param {number} id 评论ID - * @returns Promise - */ -export const deleteCommentReply = (data: any) => { +/** 删除评论回复 */ +export const deleteCommentReply = (data: NetParams.PostDeleteCommentReply): Promise => { return request({ method: 'delete', url: '/post/comment/reply', data }); -}; \ No newline at end of file +}; diff --git a/web/src/api/user.ts b/web/src/api/user.ts index 46cfe889..2828290c 100644 --- a/web/src/api/user.ts +++ b/web/src/api/user.ts @@ -1,16 +1,12 @@ -import request from '@/utils/request'; +import { request } from '@/utils/request'; -/** - * 获取验证码 - * @param {Object} params - * @returns Promise - */ -export const getCaptcha = (params: NetParams.UserGetCaptcha = {}) => { +/** 获取验证码 */ +export const getCaptcha = (params: NetParams.UserGetCaptcha = {}): Promise => { return request({ method: 'get', url: '/captcha', params - }) as unknown as Promise; + }); }; /** @@ -31,12 +27,12 @@ export const sendCaptcha = (data: any) => { * @param {Object} data * @returns Promise */ -export const sendUserWhisper = (data: NetParams.UserWhisper) => { +export const sendUserWhisper = (data: NetParams.UserWhisper): Promise => { return request({ method: 'post', url: '/user/whisper', data - }) as unknown as Promise; + }); }; /** @@ -44,20 +40,16 @@ export const sendUserWhisper = (data: NetParams.UserWhisper) => { * @param {Object} data * @returns Promise */ -export const bindUserPhone = (data: NetParams.UserBindUserPhone) => { +export const bindUserPhone = (data: NetParams.UserBindUserPhone): Promise => { return request({ method: 'post', url: '/user/phone', data - }) as unknown as Promise; + }); }; -/** - * 更改密码 - * @param {Object} data - * @returns Promise - */ -export const changePassword = (data: any) => { +/** 更改密码 */ +export const changePassword = (data: NetParams.UserChangePassword): Promise => { return request({ method: 'post', url: '/user/password', @@ -65,12 +57,8 @@ export const changePassword = (data: any) => { }); }; -/** - * 更改昵称 - * @param {Object} data - * @returns Promise - */ -export const changeNickname = (data: any) => { +/** 更改昵称 */ +export const changeNickname = (data: NetParams.UserChangeNickname): Promise => { return request({ method: 'post', url: '/user/nickname', @@ -91,30 +79,22 @@ export const changeAvatar = (data: any) => { }); }; -/** - * 获取未读消息数 - * @param {Object} params - * @returns Promise - */ -export const getUnreadMsgCount = (params: NetParams.UserGetUnreadMsgCount = {}) => { +/** 获取未读消息数 */ +export const getUnreadMsgCount = (params: NetParams.UserGetUnreadMsgCount = {}): Promise => { return request({ method: 'get', url: '/user/msgcount/unread', params - }) as unknown as Promise; + }); }; -/** - * 获取消息列表 - * @param {Object} params - * @returns Promise - */ -export const getMessages = (params: NetParams.UserGetMessages) => { +/** 获取消息列表 */ +export const getMessages = (params: NetParams.UserGetMessages): Promise => { return request({ method: 'get', url: '/user/messages', params - }) as unknown as Promise; + }); }; /** @@ -130,69 +110,49 @@ export const readMessage = (data: any) => { }); }; -/** - * 获取收藏列表 - * @param {Object} params - * @returns Promise - */ -export const getCollections = (params: NetParams.UserGetCollections) => { +/** 获取收藏列表 */ +export const getCollections = (params: NetParams.UserGetCollections): Promise => { return request({ method: 'get', url: '/user/collections', params - }) as unknown as Promise; + }); }; -/** - * 获取点赞列表 - * @param {Object} params - * @returns Promise - */ -export const getStars = (params: NetParams.UserGetStars) => { +/** 获取点赞列表 */ +export const getStars = (params: NetParams.UserGetStars): Promise => { return request({ method: 'get', url: '/user/stars', params - }) as unknown as Promise; + }); }; -/** - * 获取用户基础信息 - * @param {Object} params - * @returns Promise - */ -export const getUserProfile = (params: NetParams.UserGetUserProfile) => { +/** 获取用户基础信息 */ +export const getUserProfile = (params: NetParams.UserGetUserProfile): Promise => { return request({ method: 'get', url: '/user/profile', params - }) as unknown as Promise; + }); }; -/** - * 获取点赞列表 - * @param {Object} params - * @returns Promise - */ -export const getUserPosts = (params: NetParams.UserGetUserPosts) => { +/** 获取用户帖子列表 */ +export const getUserPosts = (params: NetParams.UserGetUserPosts): Promise => { return request({ method: 'get', url: '/user/posts', params - }) as unknown as Promise; + }); }; -/** - * 获取账单列表 - * @param {Object} params - * @returns Promise - */ -export const getBills = (params: NetParams.UserGetBills) => { +/** 获取账单列表 */ +export const getBills = (params: NetParams.UserGetBills): Promise => { return request({ method: 'get', url: '/user/wallet/bills', params - }) as unknown as Promise; + }); }; /** @@ -200,12 +160,12 @@ export const getBills = (params: NetParams.UserGetBills) => { * @param {Object} data * @returns Promise */ -export const reqRecharge = (data: NetParams.UserReqRecharge) => { +export const reqRecharge = (data: NetParams.UserReqRecharge): Promise => { return request({ method: 'post', url: '/user/recharge', data - }) as unknown as Promise; + }); }; /** @@ -213,12 +173,12 @@ export const reqRecharge = (data: NetParams.UserReqRecharge) => { * @param {Object} params * @returns Promise */ -export const getRecharge = (params: NetParams.UserGetRecharge) => { +export const getRecharge = (params: NetParams.UserGetRecharge): Promise => { return request({ method: 'get', url: '/user/recharge', params - }) as unknown as Promise; + }); }; /** @@ -226,12 +186,12 @@ export const getRecharge = (params: NetParams.UserGetRecharge) => { * @param {Object} params * @returns Promise */ -export const getSuggestUsers = (params: { k: string }) => { +export const getSuggestUsers = (params: { k: string }): Promise => { return request({ method: 'get', url: '/suggest/users', params - }) as unknown as Promise; + }); }; /** @@ -239,12 +199,12 @@ export const getSuggestUsers = (params: { k: string }) => { * @param {Object} params * @returns Promise */ -export const getSuggestTags = (params: { k: string }) => { +export const getSuggestTags = (params: { k: string }): Promise => { return request({ method: 'get', url: '/suggest/tags', params - }) as unknown as Promise; + }); }; /** @@ -252,12 +212,12 @@ export const getSuggestTags = (params: { k: string }) => { * @param {Object} params * @returns Promise */ -export const precheckAttachment = (params: NetParams.UserPrecheckAttachment) => { +export const precheckAttachment = (params: NetParams.UserPrecheckAttachment): Promise => { return request({ method: 'get', url: '/attachment/precheck', params - }) as unknown as Promise; + }); }; /** @@ -265,10 +225,10 @@ export const precheckAttachment = (params: NetParams.UserPrecheckAttachment) => * @param {Object} params * @returns Promise */ -export const getAttachment = (params: NetParams.UserGetAttachment) => { +export const getAttachment = (params: NetParams.UserGetAttachment): Promise => { return request({ method: 'get', url: '/attachment', params - }) as unknown as Promise; + }); }; diff --git a/web/src/components/comment-item.vue b/web/src/components/comment-item.vue index ad93562a..b1799e05 100644 --- a/web/src/components/comment-item.vue +++ b/web/src/components/comment-item.vue @@ -120,13 +120,13 @@ const props = withDefaults(defineProps<{ }>(), {}) const comment = computed(() => { - let comment = Object.assign( + let comment: Item.CommentComponentProps = Object.assign( { texts: [], imgs: [], }, props.comment - ) as {texts: Item.CommentProps[], imgs: Item.CommentProps[]} & Item.CommentProps; + ); comment.contents.map((content :any) => { if (+content.type === 1 || +content.type === 2) { comment.texts.push(content); diff --git a/web/src/components/compose-comment.vue b/web/src/components/compose-comment.vue index 3bcb36fd..ea23f264 100644 --- a/web/src/components/compose-comment.vue +++ b/web/src/components/compose-comment.vue @@ -265,7 +265,7 @@ const finishUpload = ({ file, event }: any): any => { imageContents.value.push({ id: file.id, content: data.data.content, - }); + } as Item.CommentItemProps); } } } catch (error) { diff --git a/web/src/components/compose.vue b/web/src/components/compose.vue index 7fa46214..db8fca0c 100644 --- a/web/src/components/compose.vue +++ b/web/src/components/compose.vue @@ -265,7 +265,7 @@ const uploadType = ref('public/image'); const fileQueue = ref([]); const imageContents = ref([]); const videoContents = ref([]); -const attachmentContents = ref([]); +const attachmentContents = ref([]); const uploadGateway = import.meta.env.VITE_HOST + '/attachment'; const uploadToken = ref(); @@ -402,19 +402,19 @@ const finishUpload = ({ file, event }: any): any => { imageContents.value.push({ id: file.id, content: data.data.content, - }); + } as Item.CommentItemProps); } if (uploadType.value === 'public/video') { videoContents.value.push({ id: file.id, content: data.data.content, - }); + } as Item.CommentItemProps); } if (uploadType.value === 'attachment') { attachmentContents.value.push({ id: file.id, content: data.data.content, - }); + } as Item.AttachmentProps); } } } catch (error) { diff --git a/web/src/components/post-attachment.vue b/web/src/components/post-attachment.vue index c806ac9f..a3d01bf8 100644 --- a/web/src/components/post-attachment.vue +++ b/web/src/components/post-attachment.vue @@ -42,7 +42,7 @@ import { precheckAttachment, getAttachment } from '@/api/user'; const props = withDefaults( defineProps<{ - attachments: Item.AttachmentProps[]; + attachments: Item.PostItemProps[]; price?: number; }>(), { @@ -54,7 +54,7 @@ const showDownloadModal = ref(false); const downloadTip = ref(''); const attachmentID = ref(0); -const download = (attachment: Item.AttachmentProps) => { +const download = (attachment: Item.PostItemProps) => { showDownloadModal.value = true; attachmentID.value = attachment.id; diff --git a/web/src/components/post-detail.vue b/web/src/components/post-detail.vue index 5bfc9a43..af283e9c 100644 --- a/web/src/components/post-detail.vue +++ b/web/src/components/post-detail.vue @@ -197,7 +197,7 @@ const emit = defineEmits<{ const post = computed({ get: () => { - let post: Required = Object.assign( + let post: Item.PostComponentProps = Object.assign( { texts: [], imgs: [], diff --git a/web/src/components/post-image.vue b/web/src/components/post-image.vue index 3a136b6e..179ed462 100644 --- a/web/src/components/post-image.vue +++ b/web/src/components/post-image.vue @@ -230,7 +230,7 @@ const defaultImg = const thumbnail = '?x-oss-process=image/resize,m_fill,w_300,h_300,limit_0/auto-orient,1/format,png'; const props = withDefaults(defineProps<{ - imgs: Item.PostProps[], + imgs: Item.PostItemProps[], }>(), { imgs: () => [] }); diff --git a/web/src/components/post-item.vue b/web/src/components/post-item.vue index 9ae3ad55..06dfd018 100644 --- a/web/src/components/post-item.vue +++ b/web/src/components/post-item.vue @@ -101,7 +101,7 @@ const props = withDefaults(defineProps<{ }>(), {}); const post = computed(() => { - let post: Required = Object.assign( + let post: Item.PostComponentProps = Object.assign( { texts: [], imgs: [], diff --git a/web/src/components/post-link.vue b/web/src/components/post-link.vue index b5713695..16864089 100644 --- a/web/src/components/post-link.vue +++ b/web/src/components/post-link.vue @@ -17,7 +17,7 @@