view libervia/web/pages/files/view/page_meta.py @ 1557:855729ef75f2

browser (calls): improve call buttons: - following template change, there are now a call button for video and one for audio, and no more "switch" button, this is more intuitive - search items have been customised with a 3 dots menu to show a dropdown, which let select the "video" or "audio" call mode. By defaut, a click on a search item will do a video call.
author Goffi <goffi@goffi.org>
date Tue, 15 Aug 2023 17:16:45 +0200
parents eb00d593801d
children ebd538cb26cb
line wrap: on
line source

#!/usr/bin/env python3


from libervia.web.server.constants import Const as C
from libervia.backend.core.i18n import _
from twisted.web import static
from libervia.web.server.utils import ProgressHandler
import tempfile
import os
import os.path
from libervia.backend.core.log import getLogger

log = getLogger(__name__)
"""files handling pages"""

name = "files_view"
access = C.PAGES_ACCESS_PROFILE


def parse_url(self, request):
    self.get_path_args(request, ["service", "*path"], min_args=2, service="jid", path="")


def cleanup(__, tmp_dir, dest_path):
    try:
        os.unlink(dest_path)
    except OSError:
        log.warning(_("Can't remove temporary file {path}").format(path=dest_path))
    try:
        os.rmdir(tmp_dir)
    except OSError:
        log.warning(_("Can't remove temporary directory {path}").format(path=tmp_dir))


async def render(self, request):
    data = self.get_r_data(request)
    profile = self.get_profile(request)
    service, path_elts = data["service"], data["path"]
    basename = path_elts[-1]
    dir_elts = path_elts[:-1]
    dir_path = "/".join(dir_elts)
    tmp_dir = tempfile.mkdtemp()
    dest_path = os.path.join(tmp_dir, basename)
    request.notifyFinish().addCallback(cleanup, tmp_dir, dest_path)
    progress_id = await self.host.bridge_call(
        "file_jingle_request",
        service.full(),
        dest_path,
        basename,
        "",
        "",
        {"path": dir_path},
        profile,
    )
    log.debug("file requested")
    await ProgressHandler(self.host, progress_id, profile).register()
    log.debug("file downloaded")
    self.delegate_to_resource(request, static.File(dest_path))