implement comments from review; slow fade-in of events
This commit is contained in:
parent
a946ea53c9
commit
7e44f6d31d
|
@ -1,7 +1,5 @@
|
|||
import logging
|
||||
import queue
|
||||
import re
|
||||
import tarfile
|
||||
from json import load as jsonload
|
||||
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.db import Track, Comment, DuplicateTrackFileError
|
||||
from obs.api.utils import tar_of_tracks
|
||||
|
||||
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")
|
||||
async def get_tracks(req):
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import queue
|
||||
import tarfile
|
||||
from datetime import datetime
|
||||
import dateutil.parser
|
||||
from sanic.exceptions import InvalidUsage
|
||||
|
||||
from obs.api.routes.tracks import log
|
||||
|
||||
RAISE = object()
|
||||
|
||||
|
||||
|
@ -76,3 +80,38 @@ class chunk:
|
|||
if len(current):
|
||||
yield current
|
||||
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
|
||||
|
|
|
@ -80,6 +80,7 @@ const getEventsLayer = () => ({
|
|||
"source-layer": "obs_events",
|
||||
paint: {
|
||||
"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"),
|
||||
},
|
||||
minzoom: 8,
|
||||
|
|
|
@ -235,7 +235,7 @@ function TracksTable({ title }) {
|
|||
};
|
||||
|
||||
const bulkAction = async (action: string) => {
|
||||
const data = await api.post("/tracks/bulk", {
|
||||
const response = await api.post("/tracks/bulk", {
|
||||
body: {
|
||||
action,
|
||||
tracks: Object.keys(selectedTracks),
|
||||
|
@ -243,7 +243,7 @@ function TracksTable({ title }) {
|
|||
returnResponse: true
|
||||
});
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue