mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 21:29:59 -05:00
Upgrading base packages. Fixing failing test from merge.
This commit is contained in:
parent
b84c6d5149
commit
c79e28ff02
5 changed files with 26 additions and 38 deletions
|
|
@ -3,11 +3,12 @@ from typing import List
|
||||||
from urllib.request import Request
|
from urllib.request import Request
|
||||||
|
|
||||||
from sanic import response
|
from sanic import response
|
||||||
|
from sanic_ext import validate
|
||||||
|
from sanic_ext.extensions.openapi import openapi
|
||||||
|
|
||||||
from wrolpi.common import get_media_directory
|
from wrolpi.common import get_media_directory
|
||||||
from wrolpi.errors import InvalidFile
|
from wrolpi.errors import InvalidFile
|
||||||
from wrolpi.root_api import get_blueprint, json_response
|
from wrolpi.root_api import get_blueprint, json_response
|
||||||
from wrolpi.schema import validate_doc
|
|
||||||
from . import lib, schema
|
from . import lib, schema
|
||||||
|
|
||||||
bp = get_blueprint('Files', '/api/files')
|
bp = get_blueprint('Files', '/api/files')
|
||||||
|
|
@ -42,12 +43,10 @@ def paths_to_files(paths: List[pathlib.Path]):
|
||||||
|
|
||||||
|
|
||||||
@bp.post('/')
|
@bp.post('/')
|
||||||
@validate_doc(
|
@openapi.description('List files in a directory')
|
||||||
'List files in a directory',
|
@validate(schema.FilesRequest)
|
||||||
consumes=schema.FilesRequest,
|
async def get_files(_: Request, body: schema.FilesRequest):
|
||||||
)
|
directories = body.directories or []
|
||||||
async def get_files(_: Request, data: dict):
|
|
||||||
directories = data.get('directories') or []
|
|
||||||
|
|
||||||
files = lib.list_files(directories)
|
files = lib.list_files(directories)
|
||||||
files = paths_to_files(files)
|
files = paths_to_files(files)
|
||||||
|
|
@ -55,13 +54,10 @@ async def get_files(_: Request, data: dict):
|
||||||
|
|
||||||
|
|
||||||
@bp.post('/delete')
|
@bp.post('/delete')
|
||||||
@validate_doc(
|
@openapi.description('Delete a single file. Returns an error if WROL Mode is enabled.')
|
||||||
'Delete a single file. Returns an error if WROL Mode is enabled.',
|
@validate(schema.DeleteRequest)
|
||||||
consumes=schema.DeleteRequest,
|
async def delete_file(_: Request, body: schema.DeleteRequest):
|
||||||
)
|
if not body.file:
|
||||||
async def delete_file(_: Request, data: dict):
|
|
||||||
file = data.get('file')
|
|
||||||
if not file:
|
|
||||||
raise InvalidFile('file cannot be empty')
|
raise InvalidFile('file cannot be empty')
|
||||||
lib.delete_file(file)
|
lib.delete_file(body.file)
|
||||||
return response.empty()
|
return response.empty()
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
from sanic_openapi import doc
|
from dataclasses import dataclass, field
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class FilesRequest:
|
class FilesRequest:
|
||||||
directories = doc.List(doc.String())
|
directories: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class DeleteRequest:
|
class DeleteRequest:
|
||||||
file = doc.String()
|
file: str
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ from sanic_ext.extensions.openapi import openapi
|
||||||
|
|
||||||
from wrolpi.common import logger, wrol_mode_check, make_media_directory, \
|
from wrolpi.common import logger, wrol_mode_check, make_media_directory, \
|
||||||
get_media_directory
|
get_media_directory
|
||||||
|
from wrolpi.errors import UnknownDirectory
|
||||||
from wrolpi.root_api import json_response
|
from wrolpi.root_api import json_response
|
||||||
from wrolpi.schema import JSONErrorResponse
|
from wrolpi.schema import JSONErrorResponse
|
||||||
from .lib import get_minimal_channels, delete_channel, update_channel, get_channel, create_channel
|
from .lib import get_minimal_channels, delete_channel, update_channel, get_channel, create_channel
|
||||||
|
|
@ -43,19 +44,9 @@ def channel_get(_: Request, link: str):
|
||||||
@validate(ChannelPostRequest)
|
@validate(ChannelPostRequest)
|
||||||
@wrol_mode_check
|
@wrol_mode_check
|
||||||
def channel_post(_: Request, body: ChannelPostRequest):
|
def channel_post(_: Request, body: ChannelPostRequest):
|
||||||
try:
|
body.directory = get_media_directory() / body.directory
|
||||||
# Channel directory is relative to the media directory. Channel directory may not be in "videos" directory!
|
if not body.directory.is_dir() and body.mkdir:
|
||||||
body.directory = get_media_directory() / body.directory
|
make_media_directory(body.directory)
|
||||||
except UnknownDirectory:
|
|
||||||
if body.mkdir:
|
|
||||||
make_media_directory(body.directory)
|
|
||||||
body.directory = get_relative_to_media_directory(body.directory)
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
# Channel directory is relative to the media directory. Channel directory may not be in "videos" directory!
|
|
||||||
data['directory'] = get_media_directory() / data['directory']
|
|
||||||
if data.get('mkdir') is True:
|
|
||||||
make_media_directory(data['directory'])
|
|
||||||
|
|
||||||
channel = create_channel(body.__dict__) # TODO don't use the dataclass as a dict.
|
channel = create_channel(body.__dict__) # TODO don't use the dataclass as a dict.
|
||||||
|
|
||||||
|
|
@ -75,7 +66,7 @@ def channel_post(_: Request, body: ChannelPostRequest):
|
||||||
@validate(ChannelPutRequest)
|
@validate(ChannelPutRequest)
|
||||||
@wrol_mode_check
|
@wrol_mode_check
|
||||||
def channel_update(_: Request, link: str, body: ChannelPutRequest):
|
def channel_update(_: Request, link: str, body: ChannelPutRequest):
|
||||||
channel = update_channel(body.__dict__, link)
|
channel = update_channel(body.__dict__, link) # TODO don't use the dataclass as a dict.
|
||||||
return response.raw('', HTTPStatus.NO_CONTENT,
|
return response.raw('', HTTPStatus.NO_CONTENT,
|
||||||
headers={'Location': f'/api/videos/channels/{channel.link}'})
|
headers={'Location': f'/api/videos/channels/{channel.link}'})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -611,9 +611,7 @@ def test_download_channel_no_refresh(test_session, download_channel, video_downl
|
||||||
|
|
||||||
|
|
||||||
def test_channel_post_directory(test_session, test_client, test_directory):
|
def test_channel_post_directory(test_session, test_client, test_directory):
|
||||||
"""
|
"""A Channel can be created with or without an existing directory."""
|
||||||
A Channel can be created with or without an existing directory.
|
|
||||||
"""
|
|
||||||
# Channel can be created with a missing directory.
|
# Channel can be created with a missing directory.
|
||||||
data = dict(name='foo', directory='foo')
|
data = dict(name='foo', directory='foo')
|
||||||
request, response = test_client.post('/api/videos/channels', content=json.dumps(data))
|
request, response = test_client.post('/api/videos/channels', content=json.dumps(data))
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ mock==4.0.3
|
||||||
Pillow==9.0.0
|
Pillow==9.0.0
|
||||||
Pint==0.18
|
Pint==0.18
|
||||||
psycopg2-binary==2.9.3
|
psycopg2-binary==2.9.3
|
||||||
pytest-asyncio==0.17.0
|
pytest-asyncio==0.17.2
|
||||||
pytest==6.2.5
|
pytest==6.2.5
|
||||||
pytz==2021.3
|
pytz==2021.3
|
||||||
PyYAML==5.3.1
|
PyYAML==6.0
|
||||||
requests==2.27.1
|
requests==2.27.1
|
||||||
sanic-ext==22.1.2
|
sanic-ext==22.1.2
|
||||||
sanic-testing==0.8.2
|
sanic-testing==0.8.2
|
||||||
|
|
@ -18,4 +18,4 @@ SQLAlchemy==1.3.22
|
||||||
srt==3.5.0
|
srt==3.5.0
|
||||||
websockets==10.1
|
websockets==10.1
|
||||||
webvtt-py==0.4.6
|
webvtt-py==0.4.6
|
||||||
yt-dlp==2021.12.27
|
yt-dlp==2022.1.21
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue