Skip to content

Commit

Permalink
fix(sandbox): fix database injection warning
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 30, 2024
1 parent a3d9ac0 commit 1db209f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions plugins/sandbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,30 @@ export function apply(ctx: Context, config: Config) {
}, { authority: 4 })

ctx.console.addListener('sandbox/get-user', async function (platform, pid) {
if (!ctx.database) return
const [binding] = await ctx.database.get('binding', { platform, pid }, ['aid'])
if (binding) return ctx.database.getUser(platform, pid)
return ctx.database.createUser(platform, pid, {
const database = ctx.get('database')
if (!database) return
const [binding] = await database.get('binding', { platform, pid }, ['aid'])
if (binding) return database.getUser(platform, pid)
return database.createUser(platform, pid, {
authority: 1,
})
}, { authority: 4 })

ctx.console.addListener('sandbox/set-user', async function (platform, pid, data) {
if (!ctx.database) return
const [binding] = await ctx.database.get('binding', { platform, pid }, ['aid'])
const database = ctx.get('database')
if (!database) return
const [binding] = await database.get('binding', { platform, pid }, ['aid'])
if (!binding) {
if (!data) return
await ctx.database.createUser(platform, pid, {
await database.createUser(platform, pid, {
authority: 1,
...data,
})
} else if (!data) {
await ctx.database.remove('user', binding.aid)
await ctx.database.remove('binding', { platform, pid })
await database.remove('user', binding.aid)
await database.remove('binding', { platform, pid })
} else {
await ctx.database.upsert('user', [{
await database.upsert('user', [{
id: binding.aid,
...data,
}])
Expand Down

0 comments on commit 1db209f

Please sign in to comment.