mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added reactions for news
This commit is contained in:
parent
ad030cd560
commit
f4519dc84b
1 changed files with 41 additions and 0 deletions
|
@ -103,6 +103,7 @@ function GetApp(): ModuleType {
|
||||||
const uloadFiles = publicDir + 'f'
|
const uloadFiles = publicDir + 'f'
|
||||||
const motdFile = publicDir + 'motd'
|
const motdFile = publicDir + 'motd'
|
||||||
const userSpecificMotdFile = publicDir + 'userSpecificMotd.json'
|
const userSpecificMotdFile = publicDir + 'userSpecificMotd.json'
|
||||||
|
const newsFile = publicDir + 'news.json'
|
||||||
|
|
||||||
let domain = url.split('.') // [ "https://api", "frylabs", "net" ]
|
let domain = url.split('.') // [ "https://api", "frylabs", "net" ]
|
||||||
domain.shift() // [ "frylabs", "net" ]
|
domain.shift() // [ "frylabs", "net" ]
|
||||||
|
@ -1306,6 +1307,46 @@ function GetApp(): ModuleType {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (req.body.react && req.body.newsKey) {
|
||||||
|
const { react, newsKey, isDelete } = req.body
|
||||||
|
const news: any = utils.ReadJSON(newsFile)
|
||||||
|
|
||||||
|
if (news[newsKey]) {
|
||||||
|
if (isDelete) {
|
||||||
|
if (news[newsKey].reacts) {
|
||||||
|
news[newsKey].reacts[react] = news[newsKey].reacts[react].filter(
|
||||||
|
(uid) => {
|
||||||
|
return uid !== user.id
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (news[newsKey].reacts[react].length === 0) {
|
||||||
|
delete news[newsKey].reacts[react]
|
||||||
|
}
|
||||||
|
logger.Log(
|
||||||
|
`User #${user.id} removed reaction '${react}' from '${newsKey}' `,
|
||||||
|
logger.GetColor('blue')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!news[newsKey].reacts) {
|
||||||
|
news[newsKey].reacts = { [react]: [user.id] }
|
||||||
|
} else {
|
||||||
|
if (Array.isArray(news[newsKey].reacts[react])) {
|
||||||
|
news[newsKey].reacts[react].push(user.id)
|
||||||
|
} else {
|
||||||
|
news[newsKey].reacts[react] = [user.id]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.Log(
|
||||||
|
`User #${user.id} reacted on '${newsKey}' with '${react}'`,
|
||||||
|
logger.GetColor('blue')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.WriteFile(JSON.stringify(news, null, 2), newsFile)
|
||||||
|
}
|
||||||
|
|
||||||
res.json({ msg: 'done' })
|
res.json({ msg: 'done' })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue