style: format ts file with prettier

This commit is contained in:
Tristan Yang
2023-05-19 17:28:15 +08:00
parent 5bd0183651
commit 54f995803a
70 changed files with 1021 additions and 777 deletions
+5 -4
View File
@@ -1,8 +1,6 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import { nanoid } from "@reduxjs/toolkit";
import baseQuery from "./base.query";
import { setAuthData, updateToken, resetAuthData, updateInitialized } from "../slices/auth.data";
import BASE_URL, { KEY_DEVICE_ID, KEY_DEVICE_TOKEN, KEY_LOCAL_MAGIC_TOKEN } from "../config";
import { createApi } from "@reduxjs/toolkit/query/react";
import {
AuthData,
CredentialResponse,
@@ -11,6 +9,9 @@ import {
RenewTokenResponse
} from "@/types/auth";
import { UserRegDTO, UserRegResponse } from "@/types/user";
import BASE_URL, { KEY_DEVICE_ID, KEY_DEVICE_TOKEN, KEY_LOCAL_MAGIC_TOKEN } from "../config";
import { resetAuthData, setAuthData, updateInitialized, updateToken } from "../slices/auth.data";
import baseQuery from "./base.query";
const getDeviceId = () => {
let d = localStorage.getItem(KEY_DEVICE_ID);
+11 -9
View File
@@ -1,10 +1,11 @@
import { fetchBaseQuery } from "@reduxjs/toolkit/query";
import toast from "react-hot-toast";
import { fetchBaseQuery } from "@reduxjs/toolkit/query";
import dayjs from "dayjs";
import { updateToken, resetAuthData } from "../slices/auth.data";
import BASE_URL, { tokenHeader } from "../config";
import { RootState } from "../store";
import { getLocalAuthData } from "@/utils";
import BASE_URL, { tokenHeader } from "../config";
import { resetAuthData, updateToken } from "../slices/auth.data";
import { RootState } from "../store";
const whiteList = [
"guestLogin",
@@ -102,12 +103,13 @@ const baseQueryWithTokenCheck = async (args: any, api: any, extraOptions: any) =
}
}
break;
case 403: {
const whiteList403 = ["sendMsg"];
if (!whiteList403.includes(api.endpoint)) {
toast.error("Request Not Allowed");
case 403:
{
const whiteList403 = ["sendMsg"];
if (!whiteList403.includes(api.endpoint)) {
toast.error("Request Not Allowed");
}
}
}
break;
case 404:
+22 -18
View File
@@ -1,16 +1,17 @@
import { createApi } from "@reduxjs/toolkit/query/react";
// import toast from "react-hot-toast";
import baseQuery from "./base.query";
import { Channel, ChannelDTO, CreateChannelDTO } from "@/types/channel";
import { ContentTypeKey } from "@/types/message";
import BASE_URL, { ContentTypes } from "../config";
import { updateChannel, removeChannel } from "../slices/channels";
import { updateRememberedNavs } from "../slices/ui";
import { removeChannel, updateChannel } from "../slices/channels";
import { removeMessage } from "../slices/message";
import { removeChannelSession } from "../slices/message.channel";
import { removeReactionMessage } from "../slices/message.reaction";
import { onMessageSendStarted } from "./handlers";
import { Channel, ChannelDTO, CreateChannelDTO } from "@/types/channel";
import { updateRememberedNavs } from "../slices/ui";
import { RootState } from "../store";
import { ContentTypeKey } from "@/types/message";
// import toast from "react-hot-toast";
import baseQuery from "./base.query";
import { onMessageSendStarted } from "./handlers";
export const channelApi = createApi({
reducerPath: "channelApi",
@@ -34,14 +35,19 @@ export const channelApi = createApi({
}
}
}),
createChannel: builder.mutation<{ gid: number, created_at: number } | number, CreateChannelDTO>({
query: (data) => ({
url: "group",
method: "POST",
body: data
})
}),
changeChannelType: builder.mutation<number, { is_public: boolean, id: number, members?: number[] }>({
createChannel: builder.mutation<{ gid: number; created_at: number } | number, CreateChannelDTO>(
{
query: (data) => ({
url: "group",
method: "POST",
body: data
})
}
),
changeChannelType: builder.mutation<
number,
{ is_public: boolean; id: number; members?: number[] }
>({
query: ({ id, is_public, members }) => ({
url: `/group/${id}/change_type`,
method: "POST",
@@ -101,9 +107,7 @@ export const channelApi = createApi({
method: "DELETE"
}),
async onQueryStarted(id, { dispatch, getState, queryFulfilled }) {
const {
channelMessage,
} = getState() as RootState;
const { channelMessage } = getState() as RootState;
try {
await queryFulfilled;
// 删掉该channel下的所有消息&reaction
+5 -3
View File
@@ -2,9 +2,9 @@ import toast from "react-hot-toast";
import { batch } from "react-redux";
import { ContentTypes } from "../config";
import { addMessage, removeMessage, updateMessage } from "../slices/message";
import { addChannelMsg, removeChannelMsg } from "../slices/message.channel";
import { addUserMsg, removeUserMsg } from "../slices/message.user";
import { addMessage, removeMessage, updateMessage } from "../slices/message";
export const onMessageSendStarted = async (
{
@@ -23,7 +23,9 @@ export const onMessageSendStarted = async (
if (type == "archive") return;
// id: who send to ,from_uid: who sent
// console.log("handlers data", content, type, properties, ignoreLocal, id);
const isMedia = properties.content_type ? ["image", "video", "audio"].includes(properties.content_type.split('/')[0]) : false;
const isMedia = properties.content_type
? ["image", "video", "audio"].includes(properties.content_type.split("/")[0])
: false;
// const isImage = properties.content_type?.startsWith("image");
const ts = properties.local_id || +new Date();
const tmpMsg = {
@@ -63,7 +65,7 @@ export const onMessageSendStarted = async (
// toast.error(`Failed to send, blocked maybe.`,);
dispatch(updateMessage({ mid: ts, failed: true }));
} else {
toast.error(`Send Message Failed ${JSON.stringify(error)}`,);
toast.error(`Send Message Failed ${JSON.stringify(error)}`);
dispatch(removeContextMessage({ id, mid: ts }));
dispatch(removeMessage(ts));
}
+38 -25
View File
@@ -1,16 +1,17 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import { ContentTypes } from "../config";
import { updateReadChannels, updateReadUsers, upsertOG } from "../slices/footprint";
import { fillFavorites, populateFavorite, addFavorite, deleteFavorite } from "../slices/favorites";
import { onMessageSendStarted } from "./handlers";
import { normalizeArchiveData } from "@/utils";
import baseQuery from "./base.query";
import { Archive, FavoriteArchive, OG } from "@/types/resource";
import { ChatMessage, ContentTypeKey, UploadFileResponse } from "@/types/message";
import { ChatContext } from "@/types/common";
import { ChatMessage, ContentTypeKey, UploadFileResponse } from "@/types/message";
import { Archive, FavoriteArchive, OG } from "@/types/resource";
import handleChatMessage from "@/hooks/useStreaming/chat.handler";
import { RootState } from "../store";
import { normalizeArchiveData } from "@/utils";
import { ContentTypes } from "../config";
import { addFavorite, deleteFavorite, fillFavorites, populateFavorite } from "../slices/favorites";
import { updateReadChannels, updateReadUsers, upsertOG } from "../slices/footprint";
import { upsertArchiveMessage } from "../slices/message.archive";
import { RootState } from "../store";
import baseQuery from "./base.query";
import { onMessageSendStarted } from "./handlers";
export const messageApi = createApi({
reducerPath: "messageApi",
@@ -73,15 +74,18 @@ export const messageApi = createApi({
dispatch(upsertOG({ key: url, value: data }));
} catch (err) {
console.log("get og error", err);
dispatch(upsertOG({
key: url, value: {
images: [],
audios: [],
videos: [],
title: "",
url,
}
}));
dispatch(
upsertOG({
key: url,
value: {
images: [],
audios: [],
videos: [],
title: "",
url
}
})
);
}
}
}),
@@ -176,12 +180,15 @@ export const messageApi = createApi({
}
}
}),
loadMoreMessages: builder.query<ChatMessage[], { context?: ChatContext, id: number; mid?: number; limit?: number }>({
loadMoreMessages: builder.query<
ChatMessage[],
{ context?: ChatContext; id: number; mid?: number; limit?: number }
>({
query: ({ context = "channel", id, mid = "", limit = 100 }) => {
const url = context == "channel" ?
`/group/${id}/history?limit=${limit}${mid ? `&before=${mid}` : ""}`
:
`/user/${id}/history?limit=${limit}${mid ? `&before=${mid}` : ""}`;
const url =
context == "channel"
? `/group/${id}/history?limit=${limit}${mid ? `&before=${mid}` : ""}`
: `/user/${id}/history?limit=${limit}${mid ? `&before=${mid}` : ""}`;
return {
url
};
@@ -198,7 +205,13 @@ export const messageApi = createApi({
}),
replyMessage: builder.mutation<
number,
{ from_uid: number, reply_mid: number; content: string; type: ContentTypeKey, properties?: {} }
{
from_uid: number;
reply_mid: number;
content: string;
type: ContentTypeKey;
properties?: {};
}
>({
query: ({ reply_mid, content, type = "text", properties }) => ({
headers: {
@@ -245,7 +258,7 @@ export const messageApi = createApi({
method: "HEAD",
responseHandler: "text"
})
}),
})
})
});
+61 -46
View File
@@ -1,30 +1,31 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import BASE_URL, { ContentTypes, IS_OFFICIAL_DEMO, PAYMENT_URL_PREFIX } from "../config";
import { updateInfo } from "../slices/server";
import baseQuery from "./base.query";
import { RootState } from "../store";
import { User } from "@/types/user";
import {
FirebaseConfig,
GoogleAuthConfig,
LoginConfig,
Server,
TestEmailDTO,
CreateAdminDTO,
SMTPConfig,
AgoraConfig,
GithubAuthConfig,
LicenseResponse,
RenewLicense,
RenewLicenseResponse,
AgoraTokenResponse,
AgoraVoicingListResponse,
SystemCommon,
AgoraChannelUsersResponse
} from "@/types/server";
import { Channel } from "@/types/channel";
import { ContentTypeKey } from "@/types/message";
import {
AgoraChannelUsersResponse,
AgoraConfig,
AgoraTokenResponse,
AgoraVoicingListResponse,
CreateAdminDTO,
FirebaseConfig,
GithubAuthConfig,
GoogleAuthConfig,
LicenseResponse,
LoginConfig,
RenewLicense,
RenewLicenseResponse,
Server,
SMTPConfig,
SystemCommon,
TestEmailDTO
} from "@/types/server";
import { User } from "@/types/user";
import BASE_URL, { ContentTypes, IS_OFFICIAL_DEMO, PAYMENT_URL_PREFIX } from "../config";
import { updateInfo } from "../slices/server";
import { updateCallInfo, upsertVoiceList } from "../slices/voice";
import { RootState } from "../store";
import baseQuery from "./base.query";
const defaultExpireDuration = 2 * 24 * 60 * 60;
@@ -69,9 +70,7 @@ export const serverApi = createApi({
async onQueryStarted(data, { dispatch, queryFulfilled }) {
try {
const resp = await queryFulfilled;
dispatch(
updateInfo({ version: resp.data })
);
dispatch(updateInfo({ version: resp.data }));
} catch {
console.error("get server version error");
}
@@ -117,18 +116,26 @@ export const serverApi = createApi({
getAgoraConfig: builder.query<AgoraConfig, void>({
query: () => ({ url: `/admin/agora/config` })
}),
getAgoraChannels: builder.query<AgoraVoicingListResponse, { page_no: number, page_size: number }>({
query: (param = { page_no: 0, page_size: 100 }) => ({ url: `/admin/agora/channel/${param.page_no}/${param.page_size}` }),
getAgoraChannels: builder.query<
AgoraVoicingListResponse,
{ page_no: number; page_size: number }
>({
query: (param = { page_no: 0, page_size: 100 }) => ({
url: `/admin/agora/channel/${param.page_no}/${param.page_size}`
}),
async onQueryStarted(data, { dispatch, queryFulfilled, getState }) {
try {
const { voice: { callingFrom }, authData } = getState() as RootState;
const {
voice: { callingFrom },
authData
} = getState() as RootState;
const { data: resp } = await queryFulfilled;
const { success } = resp;
if (success) {
const arr = resp.data.channels.map(data => {
const arr = resp.data.channels.map((data) => {
const [type, id] = data.channel_name.split(":").slice(-2);
const count = data.user_count;
const context = type === "group" ? "channel" as const : "dm" as const;
const context = type === "group" ? ("channel" as const) : ("dm" as const);
return {
id: +id,
context,
@@ -137,7 +144,9 @@ export const serverApi = createApi({
};
});
dispatch(upsertVoiceList(arr));
const hasMyself = arr.some(data => data.context === "dm" && data.id == authData?.user?.uid);
const hasMyself = arr.some(
(data) => data.context === "dm" && data.id == authData?.user?.uid
);
const sendByMe = callingFrom && callingFrom === authData?.user?.uid;
// reset dm call setting
if (callingFrom && !sendByMe && !hasMyself) {
@@ -187,9 +196,7 @@ export const serverApi = createApi({
async onQueryStarted(data, { dispatch, queryFulfilled }) {
try {
const resp = await queryFulfilled;
dispatch(
updateInfo(resp.data)
);
dispatch(updateInfo(resp.data));
} catch {
console.error("get server common error");
}
@@ -204,9 +211,7 @@ export const serverApi = createApi({
async onQueryStarted(data, { dispatch, queryFulfilled }) {
try {
await queryFulfilled;
dispatch(
updateInfo(data)
);
dispatch(updateInfo(data));
} catch {
console.error("update server common error");
}
@@ -309,7 +314,7 @@ export const serverApi = createApi({
url: `/admin/system/update_frontend_url`,
method: "POST",
headers: {
"content-type": 'text/plain',
"content-type": "text/plain"
},
body: url
})
@@ -324,16 +329,16 @@ export const serverApi = createApi({
const rootStore = getState() as RootState;
const { upgraded: prevValue } = rootStore.server;
try {
const { data: { user_limit } } = await queryFulfilled;
const {
data: { user_limit }
} = await queryFulfilled;
const currValue = user_limit > 20;
if (prevValue !== currValue) {
dispatch(updateInfo({ upgraded: currValue }));
}
} catch {
console.error("update license upgraded status failed ");
}
}
}),
@@ -363,15 +368,25 @@ export const serverApi = createApi({
body: { license }
})
}),
getBotRelatedChannels: builder.query<Channel[], { api_key: string, public_only?: boolean }>({
getBotRelatedChannels: builder.query<Channel[], { api_key: string; public_only?: boolean }>({
query: ({ api_key, public_only = false }) => ({
url: public_only ? `/bot?public_only=${public_only}` : `/bot`,
headers: {
"x-api-key": api_key
},
}
})
}),
sendMessageByBot: builder.mutation<number, { uid?: number, cid?: number, api_key: string, content: string, type?: ContentTypeKey, properties?: object }>({
sendMessageByBot: builder.mutation<
number,
{
uid?: number;
cid?: number;
api_key: string;
content: string;
type?: ContentTypeKey;
properties?: object;
}
>({
query: ({ uid, cid, api_key, type = "text", properties, content }) => ({
headers: {
"x-api-key": api_key,
@@ -384,7 +399,7 @@ export const serverApi = createApi({
method: "POST",
body: content
})
}),
})
})
});
+44 -28
View File
@@ -1,13 +1,25 @@
import { createApi } from "@reduxjs/toolkit/query/react";
// import toast from "react-hot-toast";
import baseQuery from "./base.query";
import { ContentTypeKey, MuteDTO } from "@/types/message";
import {
AutoDeleteMsgDTO,
BotAPIKey,
ContactAction,
ContactResponse,
ContactStatus,
User,
UserCreateDTO,
UserDTO,
UserForAdmin,
UserForAdminDTO
} from "@/types/user";
import BASE_URL, { ContentTypes } from "../config";
import { updateAutoDeleteSetting, updateMute } from "../slices/footprint";
import { fillUsers, updateContactStatus as updateStatus } from "../slices/users";
import BASE_URL, { ContentTypes } from "../config";
import { onMessageSendStarted } from "./handlers";
import { AutoDeleteMsgDTO, BotAPIKey, ContactAction, ContactResponse, ContactStatus, User, UserCreateDTO, UserDTO, UserForAdmin, UserForAdminDTO } from "@/types/user";
import { ContentTypeKey, MuteDTO } from "@/types/message";
import { RootState } from "../store";
// import toast from "react-hot-toast";
import baseQuery from "./base.query";
import { onMessageSendStarted } from "./handlers";
export const userApi = createApi({
reducerPath: "userApi",
@@ -29,14 +41,20 @@ export const userApi = createApi({
async onQueryStarted(data, { dispatch, queryFulfilled, getState }) {
try {
const { data: users } = await queryFulfilled;
const { authData: { user: loginUser } } = getState() as RootState;
dispatch(fillUsers(users.map((u) => {
const status = loginUser?.uid == u.uid ? "added" : "";
return {
...u,
status
};
})));
const {
authData: { user: loginUser }
} = getState() as RootState;
dispatch(
fillUsers(
users.map((u) => {
const status = loginUser?.uid == u.uid ? "added" : "";
return {
...u,
status
};
})
)
);
} catch {
console.log("get user list error");
}
@@ -71,7 +89,7 @@ export const userApi = createApi({
method: "POST"
})
}),
searchUser: builder.mutation<User, { search_type: "id" | "email", keyword: string }>({
searchUser: builder.mutation<User, { search_type: "id" | "email"; keyword: string }>({
query: (input) => ({
url: `/user/search`,
body: input,
@@ -123,7 +141,7 @@ export const userApi = createApi({
}
}),
updateContactStatus: builder.mutation<void, { action: ContactAction, target_uid: number }>({
updateContactStatus: builder.mutation<void, { action: ContactAction; target_uid: number }>({
query: (payload) => ({
url: `/user/update_contact_status`,
method: "POST",
@@ -131,10 +149,10 @@ export const userApi = createApi({
}),
async onQueryStarted(data, { dispatch, queryFulfilled }) {
const map = {
"add": "added",
"block": "blocked",
"remove": "",
"unblock": "",
add: "added",
block: "blocked",
remove: "",
unblock: ""
};
try {
await queryFulfilled;
@@ -170,7 +188,7 @@ export const userApi = createApi({
body: data
})
}),
updateAvatarByAdmin: builder.mutation<void, { uid: number, file: File }>({
updateAvatarByAdmin: builder.mutation<void, { uid: number; file: File }>({
query: ({ uid, file }) => ({
headers: {
"content-type": "image/png"
@@ -184,18 +202,17 @@ export const userApi = createApi({
query: (uid) => ({ url: `/admin/user/${uid}` })
}),
// bot operations
createBotAPIKey: builder.mutation<void, { uid: number, name: string }>({
createBotAPIKey: builder.mutation<void, { uid: number; name: string }>({
query: ({ uid, name }) => ({
url: `/admin/user/bot-api-key/${uid}`,
method: "POST",
body: { name },
}),
body: { name }
})
}),
getBotAPIKeys: builder.query<BotAPIKey[], number>({
query: (uid) => ({ url: `/admin/user/bot-api-key/${uid}` })
}),
deleteBotAPIKey: builder.query<void, { uid: number, kid: number }>({
deleteBotAPIKey: builder.query<void, { uid: number; kid: number }>({
query: ({ uid, kid }) => ({ url: `/admin/user/bot-api-key/${uid}/${kid}`, method: "DELETE" })
}),
// bot operations end
@@ -225,8 +242,7 @@ export const userApi = createApi({
// @ts-ignore
await onMessageSendStarted.call(this, param1, param2, "user");
}
}),
})
})
});