implement comments from review; slow fade-in of events

This commit is contained in:
gluap 2023-05-04 18:04:33 +02:00 committed by Paul Bienkowski
parent a946ea53c9
commit 7e44f6d31d
4 changed files with 43 additions and 37 deletions

View file

@ -1,7 +1,5 @@
import logging import logging
import queue
import re import re
import tarfile
from json import load as jsonload from json import load as jsonload
from os.path import join, exists, isfile from os.path import join, exists, isfile
@ -12,6 +10,7 @@ from sqlalchemy.orm import joinedload
from obs.api.app import api, require_auth, read_api_key, json from obs.api.app import api, require_auth, read_api_key, json
from obs.api.db import Track, Comment, DuplicateTrackFileError from obs.api.db import Track, Comment, DuplicateTrackFileError
from obs.api.utils import tar_of_tracks
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -59,39 +58,6 @@ async def _return_tracks(req, extend_query, limit, offset, order_by=None):
}, },
) )
class StreamerHelper:
def __init__(self, response):
self.response = response
self.towrite = queue.Queue()
def write(self, data):
self.towrite.put(data)
async def send_all(self):
while True:
try:
tosend = self.towrite.get(block=False)
await self.response.send(tosend)
except queue.Empty:
break
async def tar_of_tracks(req, files):
response = await req.respond(content_type="application/x-gtar", headers={'Content-Disposition': 'attachment; filename="tracks.tar.bz2"'})
helper = StreamerHelper(response)
tar = tarfile.open(name=None, fileobj=helper, mode="w|bz2", bufsize=256 * 512)
for fname in files:
logging.info(f"sending {fname}")
with open(fname, "rb") as fobj:
tar.addfile(tar.gettarinfo(fname),fobj)
await helper.send_all()
tar.close()
await helper.send_all()
await response.eof()
@api.get("/tracks") @api.get("/tracks")
async def get_tracks(req): async def get_tracks(req):

View file

@ -1,7 +1,11 @@
import queue
import tarfile
from datetime import datetime from datetime import datetime
import dateutil.parser import dateutil.parser
from sanic.exceptions import InvalidUsage from sanic.exceptions import InvalidUsage
from obs.api.routes.tracks import log
RAISE = object() RAISE = object()
@ -76,3 +80,38 @@ class chunk:
if len(current): if len(current):
yield current yield current
break break
async def tar_of_tracks(req, files):
response = await req.respond(content_type="application/x-gtar", headers={'Content-Disposition': 'attachment; filename="tracks.tar.bz2"'})
helper = StreamerHelper(response)
tar = tarfile.open(name=None, fileobj=helper, mode="w|bz2", bufsize=256 * 512)
for fname in files:
log.info("Write file to tar: %s", fname)
with open(fname, "rb") as fobj:
tar.addfile(tar.gettarinfo(fname),fobj)
await helper.send_all()
tar.close()
await helper.send_all()
await response.eof()
class StreamerHelper:
def __init__(self, response):
self.response = response
self.towrite = queue.Queue()
def write(self, data):
self.towrite.put(data)
async def send_all(self):
while True:
try:
tosend = self.towrite.get(block=False)
await self.response.send(tosend)
except queue.Empty:
break

View file

@ -80,6 +80,7 @@ const getEventsLayer = () => ({
"source-layer": "obs_events", "source-layer": "obs_events",
paint: { paint: {
"circle-radius": ["interpolate", ["linear"], ["zoom"], 14, 3, 17, 8], "circle-radius": ["interpolate", ["linear"], ["zoom"], 14, 3, 17, 8],
"circle-opacity": ["interpolate",["linear"],["zoom"],8,0.1,9,0.3,10,0.5,11,1],
"circle-color": colorByDistance("distance_overtaker"), "circle-color": colorByDistance("distance_overtaker"),
}, },
minzoom: 8, minzoom: 8,

View file

@ -235,7 +235,7 @@ function TracksTable({ title }) {
}; };
const bulkAction = async (action: string) => { const bulkAction = async (action: string) => {
const data = await api.post("/tracks/bulk", { const response = await api.post("/tracks/bulk", {
body: { body: {
action, action,
tracks: Object.keys(selectedTracks), tracks: Object.keys(selectedTracks),
@ -243,7 +243,7 @@ function TracksTable({ title }) {
returnResponse: true returnResponse: true
}); });
if (action === "download") { if (action === "download") {
download(await data.blob(), "tracks.tar.bz2", "application/x-gtar"); download(await response.blob(), "tracks.tar.bz2", "application/x-gtar");
} }
setShowBulkDelete(false); setShowBulkDelete(false);