Skip to content

Commit 797a5ef

Browse files
committed
Fix
- hopefully that time it is gonna work
1 parent d9b5e38 commit 797a5ef

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from homeassistant.components.http import HomeAssistantView
22
from homeassistant.config_entries import ConfigEntry
3-
from aiohttp import web
3+
from aiohttp import web, ClientSession
44
import requests
55

66
from homeassistant.const import (
77
CONF_API_KEY,
88
CONF_NAME,
99
CONF_HOST,
1010
CONF_PORT,
11+
CONF_SSL
1112
)
1213

1314
from .const import DOMAIN
@@ -18,12 +19,18 @@ class ImagesRedirect(HomeAssistantView):
1819
def __init__(self, config_entry: ConfigEntry):
1920
super().__init__()
2021
self._token = config_entry.data[CONF_API_KEY]
21-
self._base_url = f'https://{config_entry.data[CONF_HOST]}:{config_entry.data[CONF_PORT]}'
22+
self._base_url = f'http{'s' if config_entry.data[CONF_SSL] else ''}://{config_entry.data[CONF_HOST]}:{config_entry.data[CONF_PORT]}'
2223
self.name = f'{self._token}_Plex_Recently_Added'
2324
self.url = f'/{config_entry.data[CONF_NAME].lower() + "_" if len(config_entry.data[CONF_NAME]) > 0 else ""}plex_recently_added'
2425

2526
async def get(self, request):
2627
path = request.query.get("path", "")
2728
url = f'{self._base_url}{path}?X-Plex-Token={self._token}'
28-
return web.HTTPFound(url)
2929

30+
async with ClientSession() as session:
31+
async with session.get(url) as res:
32+
if res.ok:
33+
content = await res.read()
34+
return web.Response(body=content, content_type=res.content_type)
35+
36+
return web.HTTPNotFound()

0 commit comments

Comments
 (0)