Release 0.1.49: self-hosted maps and consented cloud location history

This commit is contained in:
Codex
2026-10-19 00:00:12 +08:00
parent d0b3db7f82
commit a5d2399d2e
58 changed files with 2586 additions and 223 deletions
+28 -2
View File
@@ -48,6 +48,8 @@ import family_voice
import family_members
import recording_archive
import app_downloads
import map_service
import location_history
ROOT = Path(__file__).resolve().parent
os.umask(0o077)
@@ -101,6 +103,8 @@ 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__])
MAPS = map_service.Maps(sys.modules[__name__])
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__])
@@ -732,7 +736,7 @@ class Handler(BaseHTTPRequestHandler):
self.login(data, path == '/api/setup')
return
self.require_auth()
if path not in ('/api/locations', '/api/logout', '/api/account/password', '/api/preferences', '/api/households/layout', '/api/family/restore',
if path not in ('/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()
@@ -743,6 +747,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/maps':
self.require_admin()
if data.get('action')!='retry':raise Problem('地图操作不正确')
if data.get('id') not in MAPS.archive.specs():raise Problem('地图区域不存在',404)
MAPS.archive.update(data['id'],nextTry=0,state='queued',attempts=0)
MAPS.archive.wake.set()
self.answer(MAPS.archive.status())
elif path == '/api/location-history':
if data.get('action')!='delete' or data.get('confirm') is not True:raise Problem('请确认删除历史轨迹')
self.answer(HISTORY.delete(HOUSEHOLDS.scope(self.user),data.get('memberId'),user=self.user))
elif path == '/api/display-voice':
self.answer(VOICE.manage_display(self.user,data))
elif path == '/api/members':
@@ -1000,6 +1014,9 @@ class Handler(BaseHTTPRequestHandler):
parsed = url.urlsplit(self.path)
path = parsed.path
query = {k: v[0] for k, v in url.parse_qs(parsed.query).items()}
if path.startswith('/maps/') and path != '/maps/phone':
MAPS.serve(self,path)
return
if path in ('/api/app-release','/downloads/ZhaoDisplay.apk','/downloads/ZhaoTerminal.apk'):
self.require_auth()
if path == '/api/app-release': self.answer(app_downloads.release(sys.modules[__name__],query.get('variant','phone'))[1])
@@ -1048,6 +1065,10 @@ class Handler(BaseHTTPRequestHandler):
self.answer(ACCOUNTS.state(self.user, status()))
elif path == '/api/locations':
self.answer(LOCATIONS.snapshot(self.user))
elif path == '/api/maps':
self.require_admin();self.answer(MAPS.archive.status())
elif path == '/api/location-history':
self.answer(HISTORY.query(HOUSEHOLDS.scope(self.user),query.get('memberId'),query.get('date'),user=self.user,period=query.get('period','day'),until=query.get('until'),cursor=query.get('cursor',0)))
elif path == '/api/members':
self.answer(MEMBERS.snapshot(self.user))
elif path == '/api/family-directory':
@@ -1245,9 +1266,11 @@ class Handler(BaseHTTPRequestHandler):
files[path] = path[1:]
if path in ('/tv', '/tv/'):
files[path] = 'ui/tv.html'
if path == '/maps/phone':
files[path] = 'ui/map.html'
if path in ('/downloads','/downloads/'):
files[path] = 'downloads.html'
for resource in ('downloads.js','downloads.css','vendor/bootstrap.min.css'):
for resource in ('downloads.js','downloads.css','vendor/bootstrap.min.css','vendor/maps-LICENSES.txt'):
files['/'+resource] = resource
if path not in files or not (ROOT / 'web' / files[path]).is_file():
raise Problem('页面不存在', 404)
@@ -1281,6 +1304,7 @@ def initialize():
MEMBERS.initialize()
DISPLAYS.initialize()
LOCATIONS.initialize()
HISTORY.initialize()
VOICE.initialize()
ARCHIVE.initialize()
HERITAGE.initialize()
@@ -1307,6 +1331,8 @@ if __name__ == '__main__':
threading.Thread(target=VOICE.watch, daemon=True).start()
threading.Thread(target=ARCHIVE.watch, daemon=True).start()
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()
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 = []