Fix being able to edit/delete messages only on the websocket end, doesn't affect db
This commit is contained in:
189
src/index.ts
189
src/index.ts
@@ -129,7 +129,7 @@ app.ws('/ws', {
|
|||||||
if (!authResult.valid) return
|
if (!authResult.valid) return
|
||||||
const userId = authResult.id
|
const userId = authResult.id
|
||||||
|
|
||||||
await db1
|
const result = await db1
|
||||||
.update(berryDashChats)
|
.update(berryDashChats)
|
||||||
.set({
|
.set({
|
||||||
content: btoa(message.data.newContent)
|
content: btoa(message.data.newContent)
|
||||||
@@ -142,16 +142,18 @@ app.ws('/ws', {
|
|||||||
)
|
)
|
||||||
.execute()
|
.execute()
|
||||||
|
|
||||||
for (const client of clients) {
|
if (result[0].affectedRows == 1) {
|
||||||
client.send(
|
for (const client of clients) {
|
||||||
JSON.stringify({
|
client.send(
|
||||||
for: message.type + ':' + message.kind,
|
JSON.stringify({
|
||||||
data: {
|
for: message.type + ':' + message.kind,
|
||||||
id: message.data.id as number,
|
data: {
|
||||||
newContent: message.data.newContent as string
|
id: message.data.id as number,
|
||||||
}
|
newContent: message.data.newContent as string
|
||||||
})
|
}
|
||||||
)
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection0.end()
|
connection0.end()
|
||||||
@@ -182,7 +184,7 @@ app.ws('/ws', {
|
|||||||
const userId = authResult.id
|
const userId = authResult.id
|
||||||
const time = Math.floor(Date.now() / 1000)
|
const time = Math.floor(Date.now() / 1000)
|
||||||
|
|
||||||
await db1
|
const result = await db1
|
||||||
.update(berryDashChats)
|
.update(berryDashChats)
|
||||||
.set({
|
.set({
|
||||||
deletedAt: time
|
deletedAt: time
|
||||||
@@ -195,88 +197,89 @@ app.ws('/ws', {
|
|||||||
)
|
)
|
||||||
.execute()
|
.execute()
|
||||||
|
|
||||||
const chatRows = await db1
|
if (result[0].affectedRows == 1) {
|
||||||
.select({
|
const chatRows = await db1
|
||||||
id: berryDashChats.id,
|
.select({
|
||||||
content: berryDashChats.content,
|
id: berryDashChats.id,
|
||||||
userId: berryDashChats.userId
|
content: berryDashChats.content,
|
||||||
})
|
userId: berryDashChats.userId
|
||||||
.from(berryDashChats)
|
|
||||||
.limit(50)
|
|
||||||
.where(eq(berryDashChats.deletedAt, 0))
|
|
||||||
.orderBy(desc(berryDashChats.id))
|
|
||||||
.execute()
|
|
||||||
|
|
||||||
if (!chatRows.reverse()[0])
|
|
||||||
for (const client of clients) {
|
|
||||||
client.send(
|
|
||||||
JSON.stringify({
|
|
||||||
for: message.type + ':' + message.kind,
|
|
||||||
data: {
|
|
||||||
id: message.data.id as number,
|
|
||||||
fillerMessage: null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
const chat = chatRows[0]
|
|
||||||
console.log(chat)
|
|
||||||
|
|
||||||
const userData = await db1
|
|
||||||
.select({
|
|
||||||
legacyHighScore: berryDashUserData.legacyHighScore,
|
|
||||||
saveData: berryDashUserData.saveData
|
|
||||||
})
|
|
||||||
.from(berryDashUserData)
|
|
||||||
.where(eq(berryDashUserData.id, chat.userId))
|
|
||||||
.limit(1)
|
|
||||||
.execute()
|
|
||||||
if (!userData[0])
|
|
||||||
for (const client of clients) {
|
|
||||||
client.send(
|
|
||||||
JSON.stringify({
|
|
||||||
for: message.type + ':' + message.kind,
|
|
||||||
data: {
|
|
||||||
id: message.data.id as number,
|
|
||||||
fillerMessage: null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const userInfo = await db0
|
|
||||||
.select({ username: users.username })
|
|
||||||
.from(users)
|
|
||||||
.where(eq(users.id, chat.userId))
|
|
||||||
.limit(1)
|
|
||||||
.execute()
|
|
||||||
|
|
||||||
let savedata = JSON.parse(userData[0].saveData)
|
|
||||||
|
|
||||||
for (const client of clients) {
|
|
||||||
client.send(
|
|
||||||
JSON.stringify({
|
|
||||||
for: message.type + ':' + message.kind,
|
|
||||||
data: {
|
|
||||||
id: message.data.id as number,
|
|
||||||
fillerMessage: {
|
|
||||||
username: userInfo[0].username,
|
|
||||||
userId: chat.userId,
|
|
||||||
content: chat.content,
|
|
||||||
id: chat.id,
|
|
||||||
icon: savedata?.bird?.icon ?? 1,
|
|
||||||
overlay: savedata?.bird?.overlay ?? 0,
|
|
||||||
birdColor: savedata?.settings?.colors?.icon ?? [
|
|
||||||
255, 255, 255
|
|
||||||
],
|
|
||||||
overlayColor: savedata?.settings?.colors?.overlay ?? [
|
|
||||||
255, 255, 255
|
|
||||||
],
|
|
||||||
customIcon: savedata?.bird?.customIcon?.selected ?? null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
)
|
.from(berryDashChats)
|
||||||
|
.limit(50)
|
||||||
|
.where(eq(berryDashChats.deletedAt, 0))
|
||||||
|
.orderBy(desc(berryDashChats.id))
|
||||||
|
.execute()
|
||||||
|
|
||||||
|
if (!chatRows.reverse()[0])
|
||||||
|
for (const client of clients) {
|
||||||
|
client.send(
|
||||||
|
JSON.stringify({
|
||||||
|
for: message.type + ':' + message.kind,
|
||||||
|
data: {
|
||||||
|
id: message.data.id as number,
|
||||||
|
fillerMessage: null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const chat = chatRows[0]
|
||||||
|
|
||||||
|
const userData = await db1
|
||||||
|
.select({
|
||||||
|
legacyHighScore: berryDashUserData.legacyHighScore,
|
||||||
|
saveData: berryDashUserData.saveData
|
||||||
|
})
|
||||||
|
.from(berryDashUserData)
|
||||||
|
.where(eq(berryDashUserData.id, chat.userId))
|
||||||
|
.limit(1)
|
||||||
|
.execute()
|
||||||
|
if (!userData[0])
|
||||||
|
for (const client of clients) {
|
||||||
|
client.send(
|
||||||
|
JSON.stringify({
|
||||||
|
for: message.type + ':' + message.kind,
|
||||||
|
data: {
|
||||||
|
id: message.data.id as number,
|
||||||
|
fillerMessage: null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const userInfo = await db0
|
||||||
|
.select({ username: users.username })
|
||||||
|
.from(users)
|
||||||
|
.where(eq(users.id, chat.userId))
|
||||||
|
.limit(1)
|
||||||
|
.execute()
|
||||||
|
|
||||||
|
let savedata = JSON.parse(userData[0].saveData)
|
||||||
|
|
||||||
|
for (const client of clients) {
|
||||||
|
client.send(
|
||||||
|
JSON.stringify({
|
||||||
|
for: message.type + ':' + message.kind,
|
||||||
|
data: {
|
||||||
|
id: message.data.id as number,
|
||||||
|
fillerMessage: {
|
||||||
|
username: userInfo[0].username,
|
||||||
|
userId: chat.userId,
|
||||||
|
content: chat.content,
|
||||||
|
id: chat.id,
|
||||||
|
icon: savedata?.bird?.icon ?? 1,
|
||||||
|
overlay: savedata?.bird?.overlay ?? 0,
|
||||||
|
birdColor: savedata?.settings?.colors?.icon ?? [
|
||||||
|
255, 255, 255
|
||||||
|
],
|
||||||
|
overlayColor: savedata?.settings?.colors?.overlay ?? [
|
||||||
|
255, 255, 255
|
||||||
|
],
|
||||||
|
customIcon: savedata?.bird?.customIcon?.selected ?? null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection0.end()
|
connection0.end()
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export async function checkAuthorization (
|
|||||||
|
|
||||||
if (!userData[0]) return { valid: false, id: 0 }
|
if (!userData[0]) return { valid: false, id: 0 }
|
||||||
else {
|
else {
|
||||||
if (updateIp != undefined && updateIp != null && db0 != undefined)
|
if (updateIp != null)
|
||||||
db0
|
db0
|
||||||
.update(users)
|
.update(users)
|
||||||
.set({ latestIp: updateIp })
|
.set({ latestIp: updateIp })
|
||||||
|
|||||||
Reference in New Issue
Block a user