feat: add typed data and views with scoped device power
This commit is contained in:
@@ -50,6 +50,8 @@ import recording_archive
|
||||
import app_downloads
|
||||
import map_service
|
||||
import location_history
|
||||
import device_power
|
||||
import device_types
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
os.umask(0o077)
|
||||
@@ -108,6 +110,8 @@ HISTORY = location_history.History(sys.modules[__name__])
|
||||
VOICE = family_voice.Voice(sys.modules[__name__])
|
||||
MEMBERS = family_members.Members(sys.modules[__name__])
|
||||
ARCHIVE = recording_archive.Archive(sys.modules[__name__])
|
||||
POWER = device_power.Power(sys.modules[__name__])
|
||||
TYPES = device_types.DeviceTypes(sys.modules[__name__])
|
||||
|
||||
|
||||
def setting(key, default=None):
|
||||
@@ -698,6 +702,11 @@ class Handler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
try:
|
||||
path = url.urlsplit(self.path).path
|
||||
if path == '/api/device-power/agent':
|
||||
self.answer(POWER.agent(self.body(16384))); return
|
||||
if path == '/api/phone/home':
|
||||
authorization=self.headers.get('Authorization','')
|
||||
self.answer(POWER.phone(authorization[7:] if authorization.startswith('Bearer ') else '',self.body(16384))); return
|
||||
if path == '/api/voice':
|
||||
authorization=self.headers.get('Authorization','')
|
||||
self.answer(VOICE.native(authorization[7:] if authorization.startswith('Bearer ') else '',self.body(220000)))
|
||||
@@ -736,7 +745,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.login(data, path == '/api/setup')
|
||||
return
|
||||
self.require_auth()
|
||||
if path not in ('/api/locations', '/api/location-history', '/api/logout', '/api/account/password', '/api/preferences', '/api/households/layout', '/api/family/restore',
|
||||
if path not in ('/api/device-power', '/api/locations', '/api/location-history', '/api/logout', '/api/account/password', '/api/preferences', '/api/households/layout', '/api/family/restore',
|
||||
'/api/family/person', '/api/family/link', '/api/family/event', '/api/heritage', '/api/ptz', '/api/ptz/presets',
|
||||
'/api/journal', '/api/journal/action', '/api/journal/upload', '/api/journal/finish', '/api/journal/pause', '/api/journal/draft', '/api/journal/abandon-draft', '/api/journal/remove-upload', '/api/journal/restore-upload'):
|
||||
self.require_manager()
|
||||
@@ -747,6 +756,16 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.answer({'ok': True}, cookie='vision=; Path=/; Max-Age=0; HttpOnly; SameSite=Strict')
|
||||
elif path == '/api/locations':
|
||||
self.answer(LOCATIONS.manage(self.user,data))
|
||||
elif path == '/api/device-power':
|
||||
self.answer(POWER.web(self.user,data))
|
||||
elif path == '/api/device-types':
|
||||
self.answer(TYPES.bind(self.user,data) if data.get('action')=='bind' else TYPES.manage(self.user,data))
|
||||
elif path == '/api/data-types':
|
||||
self.answer(TYPES.save_data_type(self.user,data))
|
||||
elif path == '/api/view-types':
|
||||
self.answer(TYPES.save_view_type(self.user,data))
|
||||
elif path == '/api/device-views':
|
||||
self.answer(TYPES.save_view(self.user,data))
|
||||
elif path == '/api/maps':
|
||||
self.require_admin()
|
||||
if data.get('action')!='retry':raise Problem('地图操作不正确')
|
||||
@@ -1065,6 +1084,19 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.answer(ACCOUNTS.state(self.user, status()))
|
||||
elif path == '/api/locations':
|
||||
self.answer(LOCATIONS.snapshot(self.user))
|
||||
elif path == '/api/device-power':
|
||||
self.answer(POWER.read(self.user,query.get('id')))
|
||||
elif path == '/api/device-types':
|
||||
self.answer(TYPES.listing(self.user))
|
||||
elif path == '/api/data-types':
|
||||
self.answer(TYPES.data_listing(self.user))
|
||||
elif path == '/api/view-types':
|
||||
self.answer(TYPES.view_listing(self.user))
|
||||
elif path == '/api/device-views':
|
||||
self.answer(TYPES.views(self.user,query.get('dataInstanceId') or query.get('deviceId')))
|
||||
elif path == '/api/device-data':
|
||||
item=POWER.web_device(self.user,query.get('id'))
|
||||
self.answer({'instance':INVENTORY.display(item)['dataInstance']})
|
||||
elif path == '/api/maps':
|
||||
self.require_admin();self.answer(MAPS.archive.status())
|
||||
elif path == '/api/location-history':
|
||||
@@ -1301,6 +1333,7 @@ def initialize():
|
||||
FAMILY.initialize()
|
||||
ACCOUNTS.initialize()
|
||||
HOUSEHOLDS.initialize()
|
||||
TYPES.initialize()
|
||||
MEMBERS.initialize()
|
||||
DISPLAYS.initialize()
|
||||
LOCATIONS.initialize()
|
||||
@@ -1309,6 +1342,7 @@ def initialize():
|
||||
ARCHIVE.initialize()
|
||||
HERITAGE.initialize()
|
||||
JOURNAL.initialize()
|
||||
POWER.initialize()
|
||||
if not setting('storage'):
|
||||
set_setting('storage', DEFAULT_STORAGE)
|
||||
if not setting('mediaSecret'):
|
||||
@@ -1333,6 +1367,7 @@ if __name__ == '__main__':
|
||||
threading.Thread(target=JOURNAL.watch, daemon=True).start()
|
||||
threading.Thread(target=MAPS.archive.watch, daemon=True).start()
|
||||
threading.Thread(target=HISTORY.watch, daemon=True).start()
|
||||
threading.Thread(target=POWER.watch, daemon=True).start()
|
||||
bindings = [h.strip() for h in os.environ.get('VISION_BIND', '127.0.0.1').split(',') if h.strip()]
|
||||
port = int(os.environ.get('VISION_PORT', '8790'))
|
||||
servers = []
|
||||
|
||||
Reference in New Issue
Block a user