forked from unimatrix/web
Fresh production baseline [skip ci]
This commit is contained in:
commit
0a11a18274
1 changed files with 229644 additions and 0 deletions
16
website/node/native-agents.mjs
Normal file
16
website/node/native-agents.mjs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import {nativeAgentIdentity} from './organisation-native-projection.mjs';
|
||||
import {syncGamePermissions} from './game-permission-sync.mjs';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {existsSync} from 'node:fs';
|
||||
import {accessFor} from './permissions.mjs';
|
||||
import {syncNativeSeals} from './native-seals.mjs';
|
||||
const native='/home/dunerealms/apps/integrations/osticket/sync-agents.php';
|
||||
export async function syncNativeAgents(db){
|
||||
if(!existsSync(native))return;
|
||||
const {results}=await db.prepare('SELECT id,username,role FROM site_accounts').all();
|
||||
const accounts=[];for(const user of results){const access=await accessFor(db,user);accounts.push(nativeAgentIdentity(user,access));}
|
||||
await new Promise((resolve,reject)=>{const child=spawn('/usr/bin/php',[native],{stdio:['pipe','ignore','pipe']});let error='';child.stderr.on('data',chunk=>{error+=chunk.toString().slice(0,1000)});const timer=setTimeout(()=>{child.kill();reject(Error('Native staff sync timed out'));},20000);child.once('error',reject);child.once('exit',code=>{clearTimeout(timer);code===0?resolve():reject(Error('Native staff sync failed'));});child.stdin.on('error',()=>{});child.stdin.end(JSON.stringify(accounts));});
|
||||
await syncNativeSeals(db);
|
||||
await syncGamePermissions(db);
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue

Staff