Fix being able to edit/delete messages only on the websocket end, doesn't affect db
This commit is contained in:
@@ -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,6 +142,7 @@ app.ws('/ws', {
|
|||||||
)
|
)
|
||||||
.execute()
|
.execute()
|
||||||
|
|
||||||
|
if (result[0].affectedRows == 1) {
|
||||||
for (const client of clients) {
|
for (const client of clients) {
|
||||||
client.send(
|
client.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -153,6 +154,7 @@ app.ws('/ws', {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
connection0.end()
|
connection0.end()
|
||||||
connection1.end()
|
connection1.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,6 +197,7 @@ app.ws('/ws', {
|
|||||||
)
|
)
|
||||||
.execute()
|
.execute()
|
||||||
|
|
||||||
|
if (result[0].affectedRows == 1) {
|
||||||
const chatRows = await db1
|
const chatRows = await db1
|
||||||
.select({
|
.select({
|
||||||
id: berryDashChats.id,
|
id: berryDashChats.id,
|
||||||
@@ -220,7 +223,6 @@ app.ws('/ws', {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
const chat = chatRows[0]
|
const chat = chatRows[0]
|
||||||
console.log(chat)
|
|
||||||
|
|
||||||
const userData = await db1
|
const userData = await db1
|
||||||
.select({
|
.select({
|
||||||
@@ -278,6 +280,7 @@ app.ws('/ws', {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
connection0.end()
|
connection0.end()
|
||||||
connection1.end()
|
connection1.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