Compare commits
4 commits
445abccd73
...
abedef1583
| Author | SHA1 | Date | |
|---|---|---|---|
| abedef1583 | |||
| 5867b1f3c4 | |||
| 143e19490c | |||
| 00d17ee71f |
18 changed files with 109 additions and 15 deletions
|
|
@ -11,7 +11,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from .dav_common import webdav_check
|
||||
from .routers.v1 import router as v1_router
|
||||
from .routers import v1_router
|
||||
from .settings import SETTINGS
|
||||
|
||||
app = FastAPI(
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ Definition of WebDAV and CalDAV clients.
|
|||
|
||||
from functools import lru_cache
|
||||
from logging import getLogger
|
||||
from os import path
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
from typing import Any, Iterator
|
||||
|
||||
|
|
@ -12,6 +14,7 @@ from caldav import Principal as CalDAVPrincipal
|
|||
from webdav3.client import Client as WebDAVclient
|
||||
from webdav3.client import Resource as WebDAVResource
|
||||
|
||||
from . import __file__ as OVD_INIT
|
||||
from .async_helpers import run_in_executor
|
||||
from .settings import SETTINGS
|
||||
|
||||
|
|
@ -67,7 +70,7 @@ def webdav_check() -> None:
|
|||
_logger.debug("WebDAV prefix directory found.")
|
||||
|
||||
|
||||
def webdav_ensure_path(remote_path: str) -> None:
|
||||
def webdav_ensure_path(remote_path: str) -> bool:
|
||||
remote_path = f"{SETTINGS.webdav_prefix}/{remote_path}"
|
||||
|
||||
if _WEBDAV_CLIENT.check(remote_path):
|
||||
|
|
@ -75,7 +78,7 @@ def webdav_ensure_path(remote_path: str) -> None:
|
|||
"WebDAV path %s found.",
|
||||
repr(remote_path),
|
||||
)
|
||||
return
|
||||
return True
|
||||
|
||||
_logger.info(
|
||||
"WebDAV path %s not found, creating ...",
|
||||
|
|
@ -83,6 +86,45 @@ def webdav_ensure_path(remote_path: str) -> None:
|
|||
)
|
||||
_WEBDAV_CLIENT.mkdir(remote_path)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_skel_path(skel_file: str) -> Path:
|
||||
skel_path = path.dirname(Path(OVD_INIT).absolute())
|
||||
return Path(skel_path).joinpath("skel", skel_file)
|
||||
|
||||
|
||||
def webdav_upload_skel(remote_path: str, *skel_files: str) -> None:
|
||||
remote_path = f"{SETTINGS.webdav_prefix}/{remote_path}"
|
||||
|
||||
for skel_file in skel_files:
|
||||
_logger.debug(
|
||||
"Creating WebDAV file %s ...",
|
||||
repr(skel_file),
|
||||
)
|
||||
|
||||
_WEBDAV_CLIENT.upload_file(
|
||||
f"{remote_path}/{skel_file}",
|
||||
get_skel_path(skel_file),
|
||||
)
|
||||
|
||||
|
||||
def webdav_ensure_files(remote_path: str, *file_names: str) -> None:
|
||||
missing_files = (
|
||||
file_name
|
||||
for file_name in file_names
|
||||
if not _WEBDAV_CLIENT.check(path.join(
|
||||
SETTINGS.webdav_prefix,
|
||||
remote_path,
|
||||
file_name,
|
||||
))
|
||||
)
|
||||
|
||||
webdav_upload_skel(
|
||||
remote_path,
|
||||
*missing_files,
|
||||
)
|
||||
|
||||
|
||||
@lru_cache(maxsize=SETTINGS.cache_size)
|
||||
def webdav_resource(remote_path: Any) -> WebDAVResource:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
from .v1 import router as v1_router
|
||||
|
||||
__all__ = [
|
||||
"v1_router",
|
||||
]
|
||||
|
|
@ -19,7 +19,3 @@ router.include_router(file.router)
|
|||
|
||||
router.include_router(calendar.router)
|
||||
router.include_router(aggregate.router)
|
||||
|
||||
__all__ = [
|
||||
"router",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from fastapi import APIRouter, Depends
|
|||
from fastapi.responses import StreamingResponse
|
||||
from magic import Magic
|
||||
|
||||
from ...dav_common import webdav_ensure_path
|
||||
from ...dav_common import webdav_ensure_files, webdav_ensure_path
|
||||
from ...dav_file import DavFile
|
||||
from ._common import FileNameLister, PrefixFinder, PrefixUnique
|
||||
|
||||
|
|
@ -40,7 +40,11 @@ file_unique = PrefixUnique(file_finder)
|
|||
async def start_router() -> None:
|
||||
_logger.debug(f"{router.prefix} router starting.")
|
||||
|
||||
webdav_ensure_path(await file_lister.remote_path)
|
||||
if not webdav_ensure_path(await file_lister.remote_path):
|
||||
webdav_ensure_files(
|
||||
await file_lister.remote_path,
|
||||
"logo.svg",
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from fastapi.responses import StreamingResponse
|
|||
from PIL import Image
|
||||
|
||||
from ...config import Config, ImageUIConfig
|
||||
from ...dav_common import webdav_ensure_path
|
||||
from ...dav_common import webdav_ensure_files, webdav_ensure_path
|
||||
from ...dav_file import DavFile
|
||||
from ._common import FileNameLister, PrefixFinder, PrefixUnique
|
||||
|
||||
|
|
@ -40,7 +40,13 @@ image_unique = PrefixUnique(image_finder)
|
|||
async def start_router() -> None:
|
||||
_logger.debug(f"{router.prefix} router starting.")
|
||||
|
||||
webdav_ensure_path(await image_lister.remote_path)
|
||||
if not webdav_ensure_path(await image_lister.remote_path):
|
||||
webdav_ensure_files(
|
||||
await image_lister.remote_path,
|
||||
"img1.jpg",
|
||||
"img2.jpg",
|
||||
"img3.jpg",
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from typing import Iterator
|
|||
from fastapi import APIRouter, Depends
|
||||
from markdown import markdown
|
||||
|
||||
from ...dav_common import webdav_ensure_path
|
||||
from ...dav_common import webdav_ensure_files, webdav_ensure_path
|
||||
from ...dav_file import DavFile
|
||||
from ._common import FileNameLister, PrefixFinder, PrefixUnique
|
||||
|
||||
|
|
@ -40,6 +40,13 @@ async def start_router() -> None:
|
|||
|
||||
webdav_ensure_path(await text_lister.remote_path)
|
||||
|
||||
webdav_ensure_files(
|
||||
await text_lister.remote_path,
|
||||
"message.txt",
|
||||
"title.txt",
|
||||
"ticker.txt",
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/list",
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from fastapi import APIRouter, Depends
|
|||
from markdown import markdown
|
||||
|
||||
from ...config import Config, TickerUIConfig
|
||||
from ...dav_common import webdav_ensure_path
|
||||
from ...dav_common import webdav_ensure_files, webdav_ensure_path
|
||||
from ...dav_file import DavFile
|
||||
from .text import text_lister, text_unique
|
||||
|
||||
|
|
@ -28,6 +28,11 @@ async def start_router() -> None:
|
|||
|
||||
webdav_ensure_path(await text_lister.remote_path)
|
||||
|
||||
webdav_ensure_files(
|
||||
await text_lister.remote_path,
|
||||
"ticker.txt",
|
||||
)
|
||||
|
||||
|
||||
async def get_ticker_lines() -> Iterator[str]:
|
||||
cfg = await Config.get()
|
||||
|
|
|
|||
BIN
api/ovdashboard_api/skel/img1.jpg
Normal file
BIN
api/ovdashboard_api/skel/img1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
BIN
api/ovdashboard_api/skel/img2.jpg
Normal file
BIN
api/ovdashboard_api/skel/img2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
BIN
api/ovdashboard_api/skel/img3.jpg
Normal file
BIN
api/ovdashboard_api/skel/img3.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
10
api/ovdashboard_api/skel/message.txt
Normal file
10
api/ovdashboard_api/skel/message.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# The API is working!
|
||||
|
||||
## Everything seems to be set up correctly
|
||||
|
||||
If you're reading this text in the dashboard, your OVDashboard is set up correctly.
|
||||
|
||||
A few files, including message.txt have been uploaded to your WebDAV server, and this
|
||||
message is already being served from there.
|
||||
|
||||
> Congratulations!
|
||||
18
api/ovdashboard_api/skel/ticker.txt
Normal file
18
api/ovdashboard_api/skel/ticker.txt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
######################################################################
|
||||
# OVDashboard Ticker #
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
|
||||
# This is the news ticker on the dashboard's bottom. #
|
||||
# #
|
||||
# Format: #
|
||||
# - Every line corresponds to one item in the ticker #
|
||||
# - Empty lines are ignored #
|
||||
# - Lines beginning with the "Comment Marker" (default: "#") are #
|
||||
# ignored #
|
||||
######################################################################
|
||||
|
||||
This is the first ticker item
|
||||
|
||||
This is the second ticker item, the empty line does not count
|
||||
Another ticker item
|
||||
# This also used to be a ticker item, but now it is inactive
|
||||
And another ticker item
|
||||
1
api/ovdashboard_api/skel/title.txt
Normal file
1
api/ovdashboard_api/skel/title.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
# OVDashboard Title
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
[tool.poetry]
|
||||
authors = ["Jörn-Michael Miehe <jmm@yavook.de>"]
|
||||
description = ""
|
||||
include = ["skel/*"]
|
||||
include = ["ovdashboard_api/skel/*"]
|
||||
name = "ovdashboard-api"
|
||||
version = "0.1.0"
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ export default class App extends Vue {
|
|||
private image_height = 300;
|
||||
private image_contain = false;
|
||||
private image_speed = 10000;
|
||||
private message_html = require("@/assets/lipsum.json");
|
||||
private message_html = require("@/assets/message_testdata.json");
|
||||
|
||||
private calendar_data: CalendarData[] = require("@/assets/calendar_testdata.json");
|
||||
private calendar_speed = 10000;
|
||||
|
|
|
|||
Loading…
Reference in a new issue