Commit e9812be7 authored by echel0n's avatar echel0n
Browse files

Implemented abstract class in web base handler

Added schedule API v2 endpoint
parent 5322d507
......@@ -19,8 +19,6 @@
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
import json
import os
from abc import ABC
import sentry_sdk
from tornado.web import authenticated
......@@ -31,7 +29,7 @@ from sickrage.core.helpers import get_internal_ip, get_external_ip
from sickrage.core.webserver.handlers.base import BaseHandler
class AccountLinkHandler(BaseHandler, ABC):
class AccountLinkHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
code = self.get_argument('code', None)
......@@ -101,7 +99,7 @@ class AccountLinkHandler(BaseHandler, ABC):
return self.redirect('/account/link')
class AccountUnlinkHandler(BaseHandler, ABC):
class AccountUnlinkHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
if not sickrage.app.config.general.server_id or sickrage.app.api.account.unregister_server(sickrage.app.config.general.server_id):
......@@ -118,7 +116,7 @@ class AccountUnlinkHandler(BaseHandler, ABC):
sickrage.app.alerts.message(_('Unlinked SiCKRAGE account from SiCKRAGE API'))
class AccountIsLinkedHandler(BaseHandler, ABC):
class AccountIsLinkedHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
return self.write(json.dumps({'linked': ('true', 'false')[not sickrage.app.api.userinfo]}))
......@@ -19,14 +19,13 @@
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
import json
from abc import ABC
import sickrage
from sickrage.core.webserver.handlers.base import BaseHandler
from sickrage.libs.trakt.interfaces.base import authenticated
class AnnouncementsHandler(BaseHandler, ABC):
class AnnouncementsHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
return self.render('announcements.mako',
......@@ -38,7 +37,7 @@ class AnnouncementsHandler(BaseHandler, ABC):
action='announcements')
class MarkAnnouncementSeenHandler(BaseHandler, ABC):
class MarkAnnouncementSeenHandler(BaseHandler):
@authenticated
def post(self, *args, **kwargs):
ahash = self.get_argument('ahash')
......@@ -50,7 +49,7 @@ class MarkAnnouncementSeenHandler(BaseHandler, ABC):
return self.write(json.dumps({'success': True}))
class AnnouncementCountHandler(BaseHandler, ABC):
class AnnouncementCountHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
return self.write(json.dumps({'count': sickrage.app.announcements.count()}))
......@@ -20,7 +20,6 @@
# ##############################################################################
import json
import traceback
from abc import ABC
import sentry_sdk
from apispec import APISpec
......@@ -36,7 +35,7 @@ from sickrage.core.helpers import get_external_ip, get_internal_ip
from sickrage.core.webserver.handlers.base import BaseHandler
class APIBaseHandler(BaseHandler, ABC):
class APIBaseHandler(BaseHandler):
def prepare(self):
super(APIBaseHandler, self).prepare()
......@@ -183,12 +182,12 @@ class APIBaseHandler(BaseHandler, ABC):
return spec.to_dict()
class PingHandler(APIBaseHandler, ABC):
class PingHandler(APIBaseHandler):
def get(self):
return self.write_json({'message': 'pong'})
class SwaggerDotJsonHandler(APIBaseHandler, ABC):
class SwaggerDotJsonHandler(APIBaseHandler):
def initialize(self, api_handlers, api_version):
super(SwaggerDotJsonHandler, self).initialize()
self.api_handlers = sickrage.app.wserver.handlers[api_handlers]
......
......@@ -19,13 +19,12 @@
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
import os
from abc import ABC
import sickrage
from sickrage.core.webserver.handlers.api import APIBaseHandler
class RetrieveSeriesMetadataHandler(APIBaseHandler, ABC):
class RetrieveSeriesMetadataHandler(APIBaseHandler):
def get(self):
series_directory = self.get_argument('seriesDirectory', None)
if not series_directory:
......
......@@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
from abc import ABC
import sickrage
from sickrage.core.common import Overview
......@@ -27,7 +27,7 @@ from sickrage.core.enums import SearchFormat
from sickrage.core.webserver.handlers.api import APIBaseHandler
class ConfigHandler(APIBaseHandler, ABC):
class ConfigHandler(APIBaseHandler):
def get(self, *args, **kwargs):
config_data = sickrage.app.config.to_json()
......
......@@ -19,7 +19,6 @@
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
import os
from abc import ABC
from tornado.escape import json_decode
......@@ -32,7 +31,7 @@ from sickrage.core.webserver.handlers.api.v2.episode.schemas import EpisodesManu
from sickrage.core.websocket import WebSocketMessage
class EpisodesManualSearchHandler(APIBaseHandler, ABC):
class EpisodesManualSearchHandler(APIBaseHandler):
def get(self, episode_slug):
"""Episode Manual Search"
---
......@@ -103,7 +102,7 @@ class EpisodesManualSearchHandler(APIBaseHandler, ABC):
)
class EpisodesRenameHandler(APIBaseHandler, ABC):
class EpisodesRenameHandler(APIBaseHandler):
def get(self):
"""Get list of episodes to rename"
---
......
......@@ -19,12 +19,11 @@
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
import os
from abc import ABC
from sickrage.core.webserver.handlers.api import APIBaseHandler
class FileBrowserHandler(APIBaseHandler, ABC):
class FileBrowserHandler(APIBaseHandler):
def get(self):
path = self.get_argument('path', None)
include_files = self.get_argument('includeFiles', None)
......
......@@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
from abc import ABC
import sickrage
from sickrage.core.enums import ProcessMethod
......@@ -26,7 +26,7 @@ from sickrage.core.webserver.handlers.api import APIBaseHandler
from sickrage.core.webserver.handlers.api.v2.postprocess.schemas import PostProcessSchema
class PostProcessHandler(APIBaseHandler, ABC):
class PostProcessHandler(APIBaseHandler):
def get(self):
"""Postprocess TV show video files"
---
......
# ##############################################################################
# Author: echel0n <[email protected]>
# URL: https://sickrage.ca/
# Git: https://git.sickrage.ca/SiCKRAGE/sickrage.git
# -
# This file is part of SiCKRAGE.
# -
# SiCKRAGE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# -
# SiCKRAGE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# -
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
from sickrage.core.webserver.handlers.api import APIBaseHandler
class ScheduleHandler(APIBaseHandler):
def get(self):
"""Get TV show schedule information"
---
tags: [Schedule]
summary: Get TV show schedule information
description: Get TV show schedule information
parameters:
- in: path
schema:
SeriesPath
responses:
200:
description: Success payload
content:
application/json:
schema:
ScheduleSuccessSchema
400:
description: Bad request; Check `errors` for any validation errors
content:
application/json:
schema:
BadRequestSchema
401:
description: Returned if your JWT token is missing or expired
content:
application/json:
schema:
NotAuthorizedSchema
404:
description: Returned if the given series slug does not exist or no series results.
content:
application/json:
schema:
NotFoundSchema
"""
\ No newline at end of file
......@@ -20,11 +20,11 @@
# ##############################################################################
import os
import re
from abc import ABC
from tornado.escape import json_decode
import sickrage
from sickrage.core.common import Quality, Qualities, EpisodeStatus
from sickrage.core.databases.main import MainDB
from sickrage.core.databases.main.schemas import IMDbInfoSchema, BlacklistSchema, WhitelistSchema
from sickrage.core.enums import SearchFormat, SeriesProviderID
......@@ -32,12 +32,11 @@ from sickrage.core.exceptions import CantUpdateShowException, NoNFOException, Ca
from sickrage.core.helpers import checkbox_to_value, sanitize_file_name, make_dir, chmod_as_parent
from sickrage.core.helpers.anidb import short_group_names
from sickrage.core.media.util import series_image, SeriesImageType
from sickrage.core.common import Quality, Qualities, EpisodeStatus
from sickrage.core.tv.show.helpers import get_show_list, find_show, find_show_by_slug
from sickrage.core.webserver.handlers.api import APIBaseHandler
class SeriesHandler(APIBaseHandler, ABC):
class SeriesHandler(APIBaseHandler):
def get(self, series_slug=None):
"""Get list of series or specific series information"
---
......@@ -318,7 +317,7 @@ class SeriesHandler(APIBaseHandler, ABC):
return self.write_json({'message': 'successful'})
class SeriesEpisodesHandler(APIBaseHandler, ABC):
class SeriesEpisodesHandler(APIBaseHandler):
def get(self, series_slug, *args, **kwargs):
series = find_show_by_slug(series_slug)
if series is None:
......@@ -331,7 +330,7 @@ class SeriesEpisodesHandler(APIBaseHandler, ABC):
return self.write_json(episodes)
class SeriesImagesHandler(APIBaseHandler, ABC):
class SeriesImagesHandler(APIBaseHandler):
def get(self, series_slug, *args, **kwargs):
series = find_show_by_slug(series_slug)
if series is None:
......@@ -341,7 +340,7 @@ class SeriesImagesHandler(APIBaseHandler, ABC):
return self.write_json({'poster': image.url})
class SeriesImdbInfoHandler(APIBaseHandler, ABC):
class SeriesImdbInfoHandler(APIBaseHandler):
def get(self, series_slug, *args, **kwargs):
series = find_show_by_slug(series_slug)
if series is None:
......@@ -354,7 +353,7 @@ class SeriesImdbInfoHandler(APIBaseHandler, ABC):
return self.write_json(json_data)
class SeriesBlacklistHandler(APIBaseHandler, ABC):
class SeriesBlacklistHandler(APIBaseHandler):
def get(self, series_slug, *args, **kwargs):
series = find_show_by_slug(series_slug)
if series is None:
......@@ -367,7 +366,7 @@ class SeriesBlacklistHandler(APIBaseHandler, ABC):
return self.write_json(json_data)
class SeriesWhitelistHandler(APIBaseHandler, ABC):
class SeriesWhitelistHandler(APIBaseHandler):
def get(self, series_slug, *args, **kwargs):
series = find_show_by_slug(series_slug)
if series is None:
......@@ -380,7 +379,7 @@ class SeriesWhitelistHandler(APIBaseHandler, ABC):
return self.write_json(json_data)
class SeriesRefreshHandler(APIBaseHandler, ABC):
class SeriesRefreshHandler(APIBaseHandler):
def get(self, series_slug):
force = self.get_argument('force', None)
......@@ -394,7 +393,7 @@ class SeriesRefreshHandler(APIBaseHandler, ABC):
return self.send_error(400, error=_(f"Unable to refresh this show, error: {e}"))
class SeriesUpdateHandler(APIBaseHandler, ABC):
class SeriesUpdateHandler(APIBaseHandler):
def get(self, series_slug):
force = self.get_argument('force', None)
......
......@@ -18,19 +18,19 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
from abc import ABC
import sickrage
from sickrage.core.enums import SeriesProviderID
from sickrage.core.webserver.handlers.api import APIBaseHandler
class SeriesProvidersHandler(APIBaseHandler, ABC):
class SeriesProvidersHandler(APIBaseHandler):
def get(self):
self.write_json([{'displayName': x.display_name, 'slug': x.slug} for x in SeriesProviderID])
class SeriesProvidersSearchHandler(APIBaseHandler, ABC):
class SeriesProvidersSearchHandler(APIBaseHandler):
def get(self, series_provider_slug):
search_term = self.get_argument('searchTerm', None)
lang = self.get_argument('seriesProviderLanguage', None)
......@@ -49,7 +49,7 @@ class SeriesProvidersSearchHandler(APIBaseHandler, ABC):
return self.write_json(results)
class SeriesProvidersLanguagesHandler(APIBaseHandler, ABC):
class SeriesProvidersLanguagesHandler(APIBaseHandler):
def get(self, series_provider_slug):
series_provider_id = SeriesProviderID.by_slug(series_provider_slug)
if not series_provider_id:
......
......@@ -22,8 +22,8 @@ import functools
import time
import traceback
import types
from abc import ABC
from concurrent.futures.thread import ThreadPoolExecutor
from typing import Optional, Awaitable
from urllib.parse import urlparse, urljoin
from jose import ExpiredSignatureError
......@@ -36,7 +36,7 @@ import sickrage
from sickrage.core.helpers import is_ip_whitelisted, torrent_webui_url
class BaseHandler(RequestHandler, ABC):
class BaseHandler(RequestHandler):
def __init__(self, application, request, **kwargs):
super(BaseHandler, self).__init__(application, request, **kwargs)
......@@ -44,6 +44,9 @@ class BaseHandler(RequestHandler, ABC):
self.startTime = time.time()
def data_received(self, chunk: bytes) -> Optional[Awaitable[None]]:
pass
def get_user_locale(self):
return locale.get(sickrage.app.config.gui.gui_lang)
......
......@@ -20,10 +20,8 @@
# ##############################################################################
import datetime
from abc import ABC
import dateutil
from tornado.concurrent import run_on_executor
from tornado.web import authenticated
import sickrage
......@@ -32,7 +30,7 @@ from sickrage.core.tv.show.helpers import get_show_list
from sickrage.core.webserver.handlers.base import BaseHandler
class CalendarHandler(BaseHandler, ABC):
class CalendarHandler(BaseHandler):
def get(self, *args, **kwargs):
if sickrage.app.config.general.calendar_unprotected:
self.write(self.calendar())
......
......@@ -18,17 +18,16 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
from abc import ABC
import markdown2
from tornado.concurrent import run_on_executor
from tornado.web import authenticated
import sickrage
from sickrage.core.webserver.handlers.base import BaseHandler
class ChangelogHandler(BaseHandler, ABC):
class ChangelogHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
try:
......
......@@ -20,7 +20,6 @@
# ##############################################################################
import os
from abc import ABC
from tornado.web import authenticated
......@@ -28,7 +27,7 @@ import sickrage
from sickrage.core.webserver.handlers.base import BaseHandler
class ConfigWebHandler(BaseHandler, ABC):
class ConfigWebHandler(BaseHandler):
menu = [
{'title': _('Help and Info'), 'path': '/config/', 'icon': 'fas fa-info'},
{'title': _('General'), 'path': '/config/general/', 'icon': 'fas fa-cogs'},
......@@ -53,7 +52,7 @@ class ConfigWebHandler(BaseHandler, ABC):
action='index')
class ConfigResetHandler(BaseHandler, ABC):
class ConfigResetHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
sickrage.app.config.load(defaults=True)
......
......@@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
from abc import ABC
from tornado.web import authenticated
......@@ -28,7 +28,7 @@ from sickrage.core.webserver import ConfigWebHandler
from sickrage.core.webserver.handlers.base import BaseHandler
class ConfigAnimeHandler(BaseHandler, ABC):
class ConfigAnimeHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
return self.render('config/anime.mako',
......@@ -40,7 +40,7 @@ class ConfigAnimeHandler(BaseHandler, ABC):
action='anime')
class ConfigSaveAnimeHandler(BaseHandler, ABC):
class ConfigSaveAnimeHandler(BaseHandler):
@authenticated
def post(self, *args, **kwargs):
use_anidb = self.get_argument('use_anidb', '')
......
......@@ -20,7 +20,6 @@
# ##############################################################################
import os
from abc import ABC
from tornado.web import authenticated
......@@ -30,7 +29,7 @@ from sickrage.core.webserver import ConfigWebHandler
from sickrage.core.webserver.handlers.base import BaseHandler
class ConfigBackupRestoreHandler(BaseHandler, ABC):
class ConfigBackupRestoreHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
return self.render('config/backup_restore.mako',
......@@ -42,7 +41,7 @@ class ConfigBackupRestoreHandler(BaseHandler, ABC):
action='backup_restore')
class ConfigBackupHandler(BaseHandler, ABC):
class ConfigBackupHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
backup_dir = self.get_argument('backupDir')
......@@ -62,7 +61,7 @@ class ConfigBackupHandler(BaseHandler, ABC):
return self.write(final_result)
class ConfigRestoreHandler(BaseHandler, ABC):
class ConfigRestoreHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
backup_file = self.get_argument('backupFile')
......@@ -93,7 +92,7 @@ class ConfigRestoreHandler(BaseHandler, ABC):
return self.write(final_result)
class SaveBackupRestoreHandler(BaseHandler, ABC):
class SaveBackupRestoreHandler(BaseHandler):
@authenticated
def post(self, *args, **kwargs):
return self.redirect("/config/backuprestore/")
......@@ -20,21 +20,20 @@
# ##############################################################################
import os
from abc import ABC
from tornado.web import authenticated
import sickrage
from sickrage.core.common import Quality, Qualities, EpisodeStatus
from sickrage.core.enums import UITheme, DefaultHomePage, TimezoneDisplay, SearchFormat, SeriesProviderID, CpuPreset
from sickrage.core.helpers import generate_api_key, checkbox_to_value, try_int
from sickrage.core.config.helpers import change_gui_lang, change_https_key, change_https_cert, change_updater_freq, change_show_update_hour, \
change_version_notify
from sickrage.core.enums import UITheme, DefaultHomePage, TimezoneDisplay, SearchFormat, SeriesProviderID, CpuPreset
from sickrage.core.helpers import generate_api_key, checkbox_to_value, try_int
from sickrage.core.webserver import ConfigWebHandler
from sickrage.core.webserver.handlers.base import BaseHandler
class ConfigGeneralHandler(BaseHandler, ABC):
class ConfigGeneralHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
return self.render('config/general.mako',
......@@ -46,20 +45,20 @@ class ConfigGeneralHandler(BaseHandler, ABC):
action='general', )
class GenerateApiKeyHandler(BaseHandler, ABC):
class GenerateApiKeyHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
return self.write(generate_api_key())
class SaveRootDirsHandler(BaseHandler, ABC):
class SaveRootDirsHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
sickrage.app.config.general.root_dirs = self.get_argument('rootDirString', '')
sickrage.app.config.save()
class SaveAddShowDefaultsHandler(BaseHandler, ABC):
class SaveAddShowDefaultsHandler(BaseHandler):
@authenticated
def get(self, *args, **kwargs):
default_status = self.get_argument('defaultStatus', '5')
......@@ -99,7 +98,7 @@ class SaveAddShowDefaultsHandler(BaseHandler, ABC):
sickrage.app.config.save()
class SaveGeneralHandler(BaseHandler, ABC):
class SaveGeneralHandler(BaseHandler):
@authenticated
def post(self, *args, **kwargs):
log_nr = self.get_argument('log_nr', '5')
......
......@@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
from abc import ABC
from tornado.web import authenticated
......@@ -30,7 +30,7 @@ from sickrage.core.webserver.handlers.base import BaseHandler