Skip to content

Commit d2b04a6

Browse files
author
Kerwin
committed
fix: build error
1 parent 7b48303 commit d2b04a6

File tree

5 files changed

+23
-35
lines changed

5 files changed

+23
-35
lines changed

service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"scripts": {
1717
"start": "esno ./src/index.ts",
1818
"dev": "esno watch ./src/index.ts",
19-
"prod": "node ./build/index.mjs",
19+
"prod": "esno ./build/index.js",
2020
"build": "pnpm clean && tsup",
2121
"clean": "rimraf build",
2222
"lint": "eslint .",

service/src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ app.all('*', (_, res, next) => {
3030

3131
router.get('/chatrooms', auth, async (req, res) => {
3232
try {
33-
const userId = new ObjectId(req.headers.userId as string)
33+
const userId = req.headers.userId as string
3434
const rooms = await getChatRooms(userId)
3535
const result = []
3636
rooms.forEach((r) => {
@@ -50,7 +50,7 @@ router.get('/chatrooms', auth, async (req, res) => {
5050

5151
router.post('/room-create', auth, async (req, res) => {
5252
try {
53-
const userId = new ObjectId(req.headers.userId as string)
53+
const userId = req.headers.userId as string
5454
const { title, roomId } = req.body as { title: string; roomId: number }
5555
const room = await createChatRoom(userId, title, roomId)
5656
res.send({ status: 'Success', message: null, data: room })
@@ -63,7 +63,7 @@ router.post('/room-create', auth, async (req, res) => {
6363

6464
router.post('/room-rename', auth, async (req, res) => {
6565
try {
66-
const userId = new ObjectId(req.headers.userId as string)
66+
const userId = req.headers.userId as string
6767
const { title, roomId } = req.body as { title: string; roomId: number }
6868
const room = await renameChatRoom(userId, title, roomId)
6969
res.send({ status: 'Success', message: null, data: room })
@@ -76,7 +76,7 @@ router.post('/room-rename', auth, async (req, res) => {
7676

7777
router.post('/room-delete', auth, async (req, res) => {
7878
try {
79-
const userId = new ObjectId(req.headers.userId as string)
79+
const userId = req.headers.userId as string
8080
const { roomId } = req.body as { roomId: number }
8181
if (!roomId || !await existsChatRoom(userId, roomId)) {
8282
res.send({ status: 'Fail', message: 'Unknow room', data: null })
@@ -93,7 +93,7 @@ router.post('/room-delete', auth, async (req, res) => {
9393

9494
router.get('/chat-hisroty', auth, async (req, res) => {
9595
try {
96-
const userId = new ObjectId(req.headers.userId as string)
96+
const userId = req.headers.userId as string
9797
const roomId = +req.query.roomid
9898
const lastTime = req.query.lasttime as string
9999
if (!roomId || !await existsChatRoom(userId, roomId)) {
@@ -146,7 +146,7 @@ router.get('/chat-hisroty', auth, async (req, res) => {
146146

147147
router.post('/chat-delete', auth, async (req, res) => {
148148
try {
149-
const userId = new ObjectId(req.headers.userId as string)
149+
const userId = req.headers.userId as string
150150
const { roomId, uuid, inversion } = req.body as { roomId: number; uuid: number; inversion: boolean }
151151
if (!roomId || !await existsChatRoom(userId, roomId)) {
152152
res.send({ status: 'Fail', message: 'Unknow room', data: null })
@@ -163,7 +163,7 @@ router.post('/chat-delete', auth, async (req, res) => {
163163

164164
router.post('/chat-clear-all', auth, async (req, res) => {
165165
try {
166-
const userId = new ObjectId(req.headers.userId as string)
166+
const userId = req.headers.userId as string
167167
await deleteAllChatRooms(userId)
168168
res.send({ status: 'Success', message: null, data: null })
169169
}
@@ -175,7 +175,7 @@ router.post('/chat-clear-all', auth, async (req, res) => {
175175

176176
router.post('/chat-clear', auth, async (req, res) => {
177177
try {
178-
const userId = new ObjectId(req.headers.userId as string)
178+
const userId = req.headers.userId as string
179179
const { roomId } = req.body as { roomId: number }
180180
if (!roomId || !await existsChatRoom(userId, roomId)) {
181181
res.send({ status: 'Fail', message: 'Unknow room', data: null })
@@ -426,7 +426,7 @@ router.post('/setting-mail', rootAuth, async (req, res) => {
426426
router.post('/mail-test', rootAuth, async (req, res) => {
427427
try {
428428
const config = req.body as MailConfig
429-
const userId = new ObjectId(req.headers.userId as string)
429+
const userId = req.headers.userId as string
430430
const user = await getUserById(userId)
431431
await sendTestMail(user.email, config)
432432
res.send({ status: 'Success', message: '发送成功 | Successfully', data: null })

service/src/storage/model.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,13 @@ export class UserInfo {
2828
}
2929
}
3030

31-
export class UserOauth {
32-
userId: number
33-
oauthType: OauthType
34-
oauthId: string
35-
36-
constructor(userId: number, oauthType: OauthType, oauthId: string) {
37-
this.userId = userId
38-
this.oauthType = oauthType
39-
this.oauthId = oauthId
40-
}
41-
}
42-
4331
export class ChatRoom {
4432
_id: ObjectId
4533
roomId: number
46-
userId: number
34+
userId: string
4735
title: string
4836
status: Status = Status.Normal
49-
constructor(userId: number, title: string, roomId: number) {
37+
constructor(userId: string, title: string, roomId: number) {
5038
this.userId = userId
5139
this.title = title
5240
this.roomId = roomId

service/src/storage/mongo.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ export async function updateChat(chatId: string, response: string, messageId: st
3434
await chatCol.updateOne(query, update)
3535
}
3636

37-
export async function createChatRoom(userId: ObjectId, title: string, roomId: number) {
37+
export async function createChatRoom(userId: string, title: string, roomId: number) {
3838
const room = new ChatRoom(userId, title, roomId)
3939
await roomCol.insertOne(room)
4040
return room
4141
}
42-
export async function renameChatRoom(userId: ObjectId, title: string, roomId: number) {
42+
export async function renameChatRoom(userId: string, title: string, roomId: number) {
4343
const query = { userId, roomId }
4444
const update = {
4545
$set: {
@@ -50,25 +50,25 @@ export async function renameChatRoom(userId: ObjectId, title: string, roomId: nu
5050
return result
5151
}
5252

53-
export async function deleteChatRoom(userId: ObjectId, roomId: number) {
53+
export async function deleteChatRoom(userId: string, roomId: number) {
5454
const result = await roomCol.updateOne({ roomId, userId }, { $set: { status: Status.Deleted } })
5555
await clearChat(roomId)
5656
return result
5757
}
5858

59-
export async function getChatRooms(userId: ObjectId) {
59+
export async function getChatRooms(userId: string) {
6060
const cursor = await roomCol.find({ userId, status: { $ne: Status.Deleted } })
6161
const rooms = []
6262
await cursor.forEach(doc => rooms.push(doc))
6363
return rooms
6464
}
6565

66-
export async function existsChatRoom(userId: ObjectId, roomId: number) {
66+
export async function existsChatRoom(userId: string, roomId: number) {
6767
const room = await roomCol.findOne({ roomId, userId })
6868
return !!room
6969
}
7070

71-
export async function deleteAllChatRooms(userId: ObjectId) {
71+
export async function deleteAllChatRooms(userId: string) {
7272
await roomCol.updateMany({ userId, status: Status.Normal }, { $set: { status: Status.Deleted } })
7373
await chatCol.updateMany({ userId, status: Status.Normal }, { $set: { status: Status.Deleted } })
7474
}
@@ -133,8 +133,8 @@ export async function createUser(email: string, password: string): Promise<UserI
133133
return userInfo
134134
}
135135

136-
export async function updateUserInfo(userId: ObjectId, user: UserInfo) {
137-
const result = userCol.updateOne({ _id: userId }
136+
export async function updateUserInfo(userId: string, user: UserInfo) {
137+
const result = userCol.updateOne({ _id: new ObjectId(userId) }
138138
, { $set: { name: user.name, description: user.description, avatar: user.avatar } })
139139
return result
140140
}
@@ -144,8 +144,8 @@ export async function getUser(email: string): Promise<UserInfo> {
144144
return await userCol.findOne({ email }) as UserInfo
145145
}
146146

147-
export async function getUserById(userId: ObjectId): Promise<UserInfo> {
148-
return await userCol.findOne({ _id: userId }) as UserInfo
147+
export async function getUserById(userId: string): Promise<UserInfo> {
148+
return await userCol.findOne({ _id: new ObjectId(userId) }) as UserInfo
149149
}
150150

151151
export async function verifyUser(email: string) {

service/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default defineConfig({
44
entry: ['src/index.ts'],
55
outDir: 'build',
66
target: 'es2020',
7-
format: ['esm'],
7+
format: ['cjs'],
88
splitting: false,
99
sourcemap: true,
1010
minify: false,

0 commit comments

Comments
 (0)