Skip to content

Commit c3d7c43

Browse files
committed
More OpenGraph
1 parent d28458f commit c3d7c43

File tree

4 files changed

+73
-24
lines changed

4 files changed

+73
-24
lines changed

app/api/api_v2/endpoints/video/list_videos.py

-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ async def get_all_files(
2323
name: Optional[str] = None,
2424
hidden: Optional[bool] = None,
2525
tag: list[str] = Query(default=[]),
26-
path: Optional[str] = Query(default=None, description='Exact match. Reflects a `files/{path}` API.'),
2726
offset: int = 0,
2827
limit: int = Query(default=100, lte=100),
2928
) -> dict[str, int | list]:
@@ -40,15 +39,6 @@ async def get_all_files(
4039
.options(selectinload(Video.likes))
4140
.order_by(desc(Video.uploaded_at))
4241
)
43-
if path:
44-
# Short route, specific path requested. This cannot be a `files/{path}` API due to `/` in video paths.
45-
video_statement = video_statement.where(Video.path == path)
46-
video_response = await session.exec(video_statement) # type: ignore
47-
video = []
48-
if found := video_response.one_or_none():
49-
video.append(found)
50-
return {'total_count': len(video), 'response': video}
51-
5242
if username:
5343
video_statement = video_statement.where(Video.user.has(name=username)) # type: ignore
5444
if name:

app/render/video_player.py

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
1-
from fastapi import APIRouter, Request
1+
import typing
2+
3+
from fastapi import APIRouter, Depends, Request
24
from fastapi.responses import HTMLResponse
35
from fastapi.templating import Jinja2Templates
6+
from sqlalchemy import desc
7+
from sqlalchemy.orm import selectinload
8+
from sqlmodel import select
9+
from sqlmodel.ext.asyncio.session import AsyncSession
10+
11+
from app.api.dependencies import yield_db_session
12+
from app.models.klepp import Video
13+
14+
if typing.TYPE_CHECKING:
15+
from starlette.templating import _TemplateResponse
416

517
templates = Jinja2Templates(directory='templates')
618

719
router = APIRouter()
820

921

1022
@router.get('/', response_class=HTMLResponse, include_in_schema=False)
11-
async def render_video_page(request: Request, path: str):
12-
return templates.TemplateResponse('video.html', {'request': request, 'path': path})
23+
async def render_video_page(
24+
request: Request, path: str, session: AsyncSession = Depends(yield_db_session)
25+
) -> '_TemplateResponse':
26+
"""
27+
Static site for share.klepp.me?path=<path>
28+
"""
29+
video_statement = (
30+
select(Video)
31+
.options(selectinload(Video.user))
32+
.options(selectinload(Video.tags))
33+
.options(selectinload(Video.likes))
34+
.order_by(desc(Video.uploaded_at))
35+
)
36+
if path:
37+
# Short route, specific path requested. This cannot be a `files/{path}` API due to `/` in video paths.
38+
video_statement = video_statement.where(Video.path == path)
39+
video_response = await session.exec(video_statement) # type: ignore
40+
if found := video_response.one_or_none():
41+
return templates.TemplateResponse('video.html', {'request': request, 'video_dict': found.dict()})
42+
return templates.TemplateResponse('404.html', {'request': request})

templates/404.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta property="og:title" content="Klepp.me"/>
6+
<meta property="og:type" content="website"/>
7+
<meta property="og:image" content="https://klepp.me/favicon.ico"/>
8+
<title>Klepp 404</title>
9+
<style>
10+
body {background: linear-gradient(90deg,#0f2027,#36474f 50%,#2c5364); color: white}
11+
</style>
12+
</head>
13+
<body>
14+
<div class="404">
15+
404 video not found
16+
</div>
17+
</body>
18+
</html>

templates/video.html

+22-11
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,36 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<meta property="og:title" content="Klepp"/>
5+
<title>Klepp.me - {{video_dict.display_name}}</title>
6+
<meta property="og:title" content="Klepp {{video_dict.name}}"/>
67
<meta property="og:type" content="website"/>
7-
<meta property="og:url" content="https://gg.klepp.me/{{path}}"/>
8-
<meta property="og:video" content="https://gg.klepp.me/{{path}}"/>
9-
<meta property="og:video:type" content="application/x-shockwave-flash">
10-
<meta property="og:video:width" content="398">
11-
<meta property="og:video:height" content="264">
12-
<meta property="og:image" content="https://klepp.me/favicon.ico"/>
8+
<meta property="og:url" content="{{video_dict.uri}}"/>
9+
<meta property="og:video" content="{{video_dict.uri}}"/>
10+
11+
<meta property="og:image" content="{{video_dict.thumbnail_uri}}"/>
1312
<meta name="theme-color" content="#FF0000">
14-
<title>Klepp video</title>
13+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
14+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
15+
<meta property="og:site_name" content="Klepp.me"/>
16+
<meta property="og:title" content="{{video_dict.display_name}}" />
17+
<meta name="description" content="Watch &#34;{{video_dict.display_name}}&#34; on Klepp.me">
18+
<link rel="shortcut icon" href="https://klepp.me/favicon.ico">
19+
<meta property="og:type" content="video.other">
20+
<meta property="og:image" content="{{video_dict.thumbnail_uri}}" />
21+
<meta property="og:image:secure_url" content="{{video_dict.thumbnail_uri}}" />
22+
<meta property="og:image:type" content="image/jpeg" />
23+
<meta property="og:updated_time" content="{{video_dict.uploaded_at}}" />
24+
<meta property="og:url" content="{{video_dict.uri}}">
1525
<style>
16-
body {background: linear-gradient(90deg,#0f2027,#36474f 50%,#2c5364)}
26+
body {background: linear-gradient(90deg,#0f2027,#36474f 50%,#2c5364);}
1727
.videoplayer {width: 100%; height: 100%}
28+
#videocontrols {width: 100%; height: 100%;}
1829
</style>
1930
</head>
2031
<body>
2132
<div class="videoplayer">
22-
<video controls>
23-
<source src="https://gg.klepp.me/{{path}}" type="video/mp4">
33+
<video controls id="videocontrols">
34+
<source src="{{ video_dict.uri }}" type="video/mp4">
2435
Your browser does not support the video tag.
2536
</video>
2637
</div>

0 commit comments

Comments
 (0)