* Upgrade service to integrate with new FPrint OS.

This commit is contained in:
2022-01-30 17:46:52 +01:00
parent 8bbfb59c6b
commit 3c5fbbf46b
2 changed files with 33 additions and 13 deletions
+18 -2
View File
@@ -1,3 +1,4 @@
import datetime
import json import json
import socketio import socketio
import uuid import uuid
@@ -19,11 +20,18 @@ config = {
}, },
'mode': 'capture' 'mode': 'capture'
} }
config_default = config;
os.chdir(os.path.dirname(__file__));
configFileExists = os.path.exists('.config.json'); configFileExists = os.path.exists('.config.json');
if configFileExists: if configFileExists:
with open('.config.json') as reader: with open('.config.json') as reader:
try:
config = json.loads(reader.read()); config = json.loads(reader.read());
except:
config = config_default
sio = socketio.Server(async_mode="threading") sio = socketio.Server(async_mode="threading")
app = Flask(__name__) app = Flask(__name__)
@@ -260,18 +268,26 @@ def connect(sid, data):
config['started'] = is_identify_active config['started'] = is_identify_active
domain_code = config['domain']['code']; domain_code = config['domain']['code'];
response = requests.get("https://apis.a2loft.net/identity/{}/units".format(domain_code)) response = requests.get("https://apis.a2loft.net/identity/{}/units".format(domain_code))
config['departments'] = [];
if response.ok:
responseJson = json.loads(response.text) responseJson = json.loads(response.text)
if responseJson['ok']: if responseJson['ok']:
config['departments'] = responseJson['data']; config['departments'] = responseJson['data'];
domain_fprint_file = '{}/fprint-sync/.{}-fprint-data.json'.format(os.getenv("HOME"), domain_code); domain_fprint_file = '{}/fprint-sync/.{}-fprint-data.json'.format(os.getenv("HOME"), domain_code);
config['records'] = {
'length': 0,
'timestamp': 0
};
if os.path.exists(domain_fprint_file): if os.path.exists(domain_fprint_file):
with open(domain_fprint_file) as f: with open(domain_fprint_file) as f:
records = json.loads(f.read()); records = json.loads(f.read());
raw_prints = records['profiles']; raw_prints = records['profiles'];
prints_dict = {}; prints_dict = {};
for profile in raw_prints: for profile in raw_prints:
for fp in profile['fingerprints']: for index, fp in enumerate(profile['fingerprints']):
prints_dict[fp] = profile reference = profile['reference'];
finger = fp['finger']
prints_dict['{}-{}-{}'.format(reference, finger, index+1)] = profile
config['records'] = { config['records'] = {
'length': len(records['profiles']), 'length': len(records['profiles']),
'timestamp': records['timestamp'] 'timestamp': records['timestamp']
+6 -2
View File
@@ -2,7 +2,7 @@
var app = new Vue({ var app = new Vue({
el: '#app', el: '#app',
data: { data: {
domain: { }, domain: { name: '', code: '' },
errorMessage: '', errorMessage: '',
staff: { reference: '' }, staff: { reference: '' },
department: '-', department: '-',
@@ -23,12 +23,16 @@ var app = new Vue({
this.socket.on("config", (data) => { this.socket.on("config", (data) => {
let deptStr = localStorage.getItem("idid-departments"); let deptStr = localStorage.getItem("idid-departments");
if (deptStr) this.savedDepartments = JSON.parse(deptStr); if (deptStr) this.savedDepartments = JSON.parse(deptStr);
if (data.departments)
data.departments.forEach(d => { data.departments.forEach(d => {
d.name = d.name.replace('*', ''); d.name = d.name.replace('*', '');
d.checked = this.savedDepartments.includes(d.id); d.checked = this.savedDepartments.includes(d.id);
return d; return d;
}); });
this.domain = data; else
data.departments = [];
this.domain = data.domain;
this.started = data.started; this.started = data.started;
this.today = new Date().toDateString(); this.today = new Date().toDateString();
this.records = data.records; this.records = data.records;