Compare commits
8 Commits
v0.7.0
...
fdbf9b2610
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fdbf9b2610 | ||
|
|
8437c1f60e | ||
|
|
02c5e484b5 | ||
|
|
71eb252b8d | ||
|
|
27422ae1e2 | ||
|
|
c3d6aecffd | ||
|
|
e2a9a6903c | ||
|
|
58b9dd3dd4 |
16
cista/app.py
16
cista/app.py
@@ -2,6 +2,7 @@ import asyncio
|
||||
import datetime
|
||||
import mimetypes
|
||||
import threading
|
||||
import tracemalloc
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from pathlib import Path, PurePath, PurePosixPath
|
||||
from stat import S_IFDIR, S_IFREG
|
||||
@@ -9,6 +10,7 @@ from urllib.parse import unquote
|
||||
from wsgiref.handlers import format_date_time
|
||||
|
||||
import brotli
|
||||
import objgraph
|
||||
import sanic.helpers
|
||||
from blake3 import blake3
|
||||
from sanic import Blueprint, Sanic, empty, raw, redirect
|
||||
@@ -32,13 +34,25 @@ app.exception(Exception)(handle_sanic_exception)
|
||||
|
||||
@app.before_server_start
|
||||
async def main_start(app, loop):
|
||||
tracemalloc.start()
|
||||
config.load_config()
|
||||
app.ctx.threadexec = ThreadPoolExecutor(
|
||||
max_workers=8, thread_name_prefix="cista-ioworker"
|
||||
max_workers=3, thread_name_prefix="cista-ioworker"
|
||||
)
|
||||
await watching.start(app, loop)
|
||||
|
||||
|
||||
@app.add_task
|
||||
async def mem_task():
|
||||
while True:
|
||||
await asyncio.sleep(10)
|
||||
snapshot = tracemalloc.take_snapshot()
|
||||
top_stats = snapshot.statistics("lineno")
|
||||
for stat in top_stats[:10]:
|
||||
print(stat)
|
||||
objgraph.show_growth(limit=10)
|
||||
|
||||
|
||||
@app.after_server_stop
|
||||
async def main_stop(app, loop):
|
||||
quit.set()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import gc
|
||||
import io
|
||||
import mimetypes
|
||||
import urllib.parse
|
||||
@@ -9,6 +10,7 @@ from wsgiref.handlers import format_date_time
|
||||
import av
|
||||
import av.datasets
|
||||
import fitz # PyMuPDF
|
||||
from av.streams import SideData
|
||||
from PIL import Image
|
||||
from sanic import Blueprint, empty, raw
|
||||
from sanic.exceptions import NotFound
|
||||
@@ -96,19 +98,20 @@ def process_pdf(path, *, maxsize, maxzoom, quality, page_number=0):
|
||||
def process_video(path, *, maxsize, quality):
|
||||
with av.open(str(path)) as container:
|
||||
stream = container.streams.video[0]
|
||||
rotation = (
|
||||
stream.side_data
|
||||
and stream.side_data.get(av.stream.SideData.DISPLAYMATRIX)
|
||||
or 0
|
||||
)
|
||||
stream.codec_context.skip_frame = "NONKEY"
|
||||
stream.codec_context.threads = 1
|
||||
rot = stream.side_data and stream.side_data.get(SideData.DISPLAYMATRIX) or 0
|
||||
container.seek(container.duration // 8)
|
||||
frame = next(container.decode(stream))
|
||||
img = frame.to_image()
|
||||
img = next(container.decode(stream)).to_image()
|
||||
del stream
|
||||
|
||||
img.thumbnail((maxsize, maxsize))
|
||||
imgdata = io.BytesIO()
|
||||
if rotation:
|
||||
img = img.rotate(rotation, expand=True)
|
||||
if rot:
|
||||
img = img.rotate(rot, expand=True)
|
||||
img.save(imgdata, format="webp", quality=quality, method=4)
|
||||
return imgdata.getvalue()
|
||||
del img
|
||||
ret = imgdata.getvalue()
|
||||
del imgdata
|
||||
gc.collect()
|
||||
return ret
|
||||
|
||||
@@ -27,7 +27,6 @@ import Router from '@/router/index'
|
||||
import { needleFormat, localeIncludes, collator } from '@/utils'
|
||||
import { sorted } from '@/utils/docsort'
|
||||
import FileExplorer from '@/components/FileExplorer.vue'
|
||||
import cog from '@/assets/svg/cog.svg'
|
||||
|
||||
const store = useMainStore()
|
||||
const fileExplorer = ref()
|
||||
|
||||
Reference in New Issue
Block a user