Separate system accounts and household people, add generation directory and consented member location sharing

This commit is contained in:
Codex
2026-10-18 20:00:43 +08:00
parent 67bc5a1ba9
commit 3b2c046060
52 changed files with 1497 additions and 311 deletions
+36 -2
View File
@@ -43,8 +43,10 @@ import baidu
import journal
import ptz
import displays
import family_locations
import member_locations as family_locations
import family_members
import recording_archive
import app_downloads
ROOT = Path(__file__).resolve().parent
os.umask(0o077)
@@ -98,6 +100,7 @@ JOURNAL = journal.Journal(sys.modules[__name__])
CLOUD_IMAGES = cloud_images.CloudImages(sys.modules[__name__])
DISPLAYS = displays.Displays(sys.modules[__name__])
LOCATIONS = family_locations.Locations(sys.modules[__name__])
MEMBERS = family_members.Members(sys.modules[__name__])
ARCHIVE = recording_archive.Archive(sys.modules[__name__])
@@ -734,6 +737,12 @@ 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/members':
self.answer(MEMBERS.save(self.user,data))
elif path == '/api/genealogy/share':
self.answer(MEMBERS.share_genealogy(self.user,data))
elif path == '/api/users/grant':
self.answer(ACCOUNTS.grant_household(self.user,data))
elif path == '/api/preferences':
self.answer(APPEARANCE.save_preferences(data, self.user))
elif path == '/api/households/layout':
@@ -970,11 +979,24 @@ class Handler(BaseHTTPRequestHandler):
finally:
self.connection.settimeout(old_timeout)
def do_HEAD(self):
if url.urlsplit(self.path).path != '/downloads/ZhaoDisplay.apk':
self.send_response(405); self.send_header('Content-Length','0'); self.end_headers(); return
try:
self.require_auth(); app_downloads.serve(self,sys.modules[__name__])
except Problem as exc:
self.send_response(exc.status); self.send_header('Content-Length','0'); self.end_headers()
def do_GET(self):
try:
parsed = url.urlsplit(self.path)
path = parsed.path
query = {k: v[0] for k, v in url.parse_qs(parsed.query).items()}
if path in ('/api/app-release','/downloads/ZhaoDisplay.apk'):
self.require_auth()
if path == '/api/app-release': self.answer(app_downloads.release(sys.modules[__name__])[1])
else: app_downloads.serve(self,sys.modules[__name__])
return
if path == baidu.CALLBACK:
try:
BAIDU.callback(query, self.headers.get('Cookie', '')); result = 'ok'
@@ -1018,6 +1040,13 @@ class Handler(BaseHTTPRequestHandler):
self.answer(ACCOUNTS.state(self.user, status()))
elif path == '/api/locations':
self.answer(LOCATIONS.snapshot(self.user))
elif path == '/api/members':
self.answer(MEMBERS.snapshot(self.user))
elif path == '/api/family-directory':
self.answer(MEMBERS.directory(self.user))
elif path == '/api/platform/users':
self.require_admin()
self.answer({'users':[ACCOUNTS.public(u) for u in objects('users')]})
elif path == '/api/devices/network':
self.require_manager(); self.answer(NETWORK.read(self.user, query))
elif path == '/api/displays':
@@ -1171,7 +1200,7 @@ class Handler(BaseHTTPRequestHandler):
with BAIDU.open_file('shared',dict(remotePath=cloud['remote'],fsId=cloud['fs_id']),self.headers.get('Range','')) as response:
self.send_response(response.status)
self.send_header('Content-Type','video/mp4')
self.send_header('Content-Disposition','attachment; filename="recording.mp4"')
self.send_header('Content-Disposition',"attachment; filename=\"recording.mp4\"; filename*=UTF-8''"+url.quote(cloud['remote'].rsplit('/',1)[-1],safe=''))
self.send_header('Cache-Control','no-store')
for header in ('Content-Length','Content-Range','Accept-Ranges'):
if response.headers.get(header): self.send_header(header,response.headers[header])
@@ -1208,6 +1237,10 @@ class Handler(BaseHTTPRequestHandler):
files[path] = path[1:]
if path in ('/tv', '/tv/'):
files[path] = 'ui/tv.html'
if path in ('/downloads','/downloads/'):
files[path] = 'downloads.html'
for resource in ('downloads.js','downloads.css','vendor/bootstrap.min.css'):
files['/'+resource] = resource
if path not in files or not (ROOT / 'web' / files[path]).is_file():
raise Problem('页面不存在', 404)
file = ROOT / 'web' / files[path]
@@ -1237,6 +1270,7 @@ def initialize():
FAMILY.initialize()
ACCOUNTS.initialize()
HOUSEHOLDS.initialize()
MEMBERS.initialize()
DISPLAYS.initialize()
LOCATIONS.initialize()
ARCHIVE.initialize()