diff --git a/src/app/services/channel.ts b/src/app/services/channel.ts index 02032cd4..49a30386 100644 --- a/src/app/services/channel.ts +++ b/src/app/services/channel.ts @@ -2,6 +2,7 @@ import { createApi } from "@reduxjs/toolkit/query/react"; import { Channel, ChannelDTO, CreateChannelDTO } from "@/types/channel"; import { ContentTypeKey } from "@/types/message"; +import { transformInviteLink } from "@/utils"; import BASE_URL, { ContentTypes } from "../config"; import { removeChannel, updateChannel } from "../slices/channels"; import { removeMessage } from "../slices/message"; @@ -93,12 +94,7 @@ export const channelApi = createApi({ responseHandler: "text" }), transformResponse: (link: string) => { - // 确保http开头 - const _link = link.startsWith("http") ? link : `http://${link}`; - // return _link; - // 替换掉域名 - const invite = new URL(_link); - return `${location.origin}${invite.pathname}${invite.hash}${invite.search}`; + return transformInviteLink(link); } }), clearChannelMessage: builder.query({ @@ -132,12 +128,7 @@ export const channelApi = createApi({ responseHandler: "text" }), transformResponse: (link: string) => { - // 确保http开头 - const _link = link.startsWith("http") ? link : `http://${link}`; - // return _link; - // 替换掉域名 - const invite = new URL(_link); - return `${location.origin}${invite.pathname}${invite.hash}${invite.search}`; + return transformInviteLink(link); } }), removeChannel: builder.query({ diff --git a/src/app/services/server.ts b/src/app/services/server.ts index 047c9bb8..beb8a743 100644 --- a/src/app/services/server.ts +++ b/src/app/services/server.ts @@ -21,6 +21,7 @@ import { TestEmailDTO } from "@/types/server"; import { User } from "@/types/user"; +import { transformInviteLink } from "@/utils"; import BASE_URL, { ContentTypes, IS_OFFICIAL_DEMO, PAYMENT_URL_PREFIX } from "../config"; import { updateInfo } from "../slices/server"; import { updateCallInfo, upsertVoiceList } from "../slices/voice"; @@ -272,11 +273,7 @@ export const serverApi = createApi({ responseHandler: "text" }), transformResponse: (link: string) => { - // 确保http开头 - const _link = link.startsWith("http") ? link : `http://${link}`; - // 替换掉域名 - const invite = new URL(_link); - return `${location.origin}${invite.pathname}${invite.search}${invite.hash}`; + return transformInviteLink(link); } }), updateServer: builder.mutation({ diff --git a/src/utils.tsx b/src/utils.tsx index f513cb8a..3b228997 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -405,3 +405,15 @@ export const playAgoraVideo = (uid: number, videoTrack?: ICameraVideoTrack | nul } } }; + +// 转换一下邀请连接 +export const transformInviteLink = (link: string) => { + // 确保http开头 + const _link = link.startsWith("http") ? link : `http://${link}`; + // return _link; + // 替换掉域名 + const invite = new URL(_link); + const tmpLink = `${location.origin}${invite.pathname}${invite.hash}${invite.search}`; + + return `https://voce.chat/url?i=${encodeURIComponent(tmpLink)}`; +};