refactor: invite link
This commit is contained in:
@@ -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<void, number>({
|
||||
@@ -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<void, number>({
|
||||
|
||||
@@ -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<void, Server>({
|
||||
|
||||
@@ -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)}`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user