File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
custom_components/plex_recently_added Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 11from homeassistant .components .http import HomeAssistantView
22from homeassistant .config_entries import ConfigEntry
3- from aiohttp import web
3+ from aiohttp import web , ClientSession
44import requests
55
66from homeassistant .const import (
77 CONF_API_KEY ,
88 CONF_NAME ,
99 CONF_HOST ,
1010 CONF_PORT ,
11+ CONF_SSL
1112 )
1213
1314from .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 ()
You can’t perform that action at this time.
0 commit comments