From 334c54be4af90d582d7f44a4ac8f906d515088c4 Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 21 Sep 2021 10:45:52 +0200 Subject: [PATCH] fix linter warnings one method to add handlers --- .eslintrc.js | 3 ++- apiGo/api/API.go | 9 +++++++++ apiGo/api/Actors.go | 2 +- apiGo/api/Settings.go | 2 +- apiGo/api/TVShows.go | 2 +- apiGo/api/Tags.go | 2 +- apiGo/api/Video.go | 2 +- apiGo/api/api/ApiBase.go | 5 ++++- apiGo/main.go | 28 +++++++++++++++++----------- src/pages/HomePage/HomePage.tsx | 1 - src/utils/Api.ts | 1 - 11 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 apiGo/api/API.go diff --git a/.eslintrc.js b/.eslintrc.js index a6e3655..49f4aa6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -97,6 +97,7 @@ module.exports = { rules: { "@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/explicit-function-return-type": "error", + "@typescript-eslint/no-shadow": "warn", // General 'comma-dangle': [1, 'never'], // allow or disallow trailing commas @@ -182,7 +183,7 @@ module.exports = { 'no-catch-shadow': 1, // disallow the catch clause parameter name being the same as a variable in the outer scope (off by default in the node environment) 'no-delete-var': 1, // disallow deletion of variables 'no-label-var': 1, // disallow labels that share a name with a variable - 'no-shadow': 1, // disallow declaration of variables already declared in the outer scope + // 'no-shadow': 1, // disallow declaration of variables already declared in the outer scope 'no-shadow-restricted-names': 1, // disallow shadowing of names such as arguments 'no-undef': 2, // disallow use of undeclared variables unless mentioned in a /*global */ block 'no-undefined': 0, // disallow use of undefined variable (off by default) diff --git a/apiGo/api/API.go b/apiGo/api/API.go new file mode 100644 index 0000000..020a7f1 --- /dev/null +++ b/apiGo/api/API.go @@ -0,0 +1,9 @@ +package api + +func AddHandlers() { + addVideoHandlers() + addSettingsHandlers() + addTagHandlers() + addActorsHandlers() + addTvshowHandlers() +} diff --git a/apiGo/api/Actors.go b/apiGo/api/Actors.go index df17514..20bbc8b 100644 --- a/apiGo/api/Actors.go +++ b/apiGo/api/Actors.go @@ -7,7 +7,7 @@ import ( "openmediacenter/apiGo/database" ) -func AddActorsHandlers() { +func addActorsHandlers() { saveActorsToDB() getActorsFromDB() } diff --git a/apiGo/api/Settings.go b/apiGo/api/Settings.go index 1775ed0..fb1f1ce 100644 --- a/apiGo/api/Settings.go +++ b/apiGo/api/Settings.go @@ -11,7 +11,7 @@ import ( "strings" ) -func AddSettingsHandlers() { +func addSettingsHandlers() { saveSettingsToDB() getSettingsFromDB() reIndexHandling() diff --git a/apiGo/api/TVShows.go b/apiGo/api/TVShows.go index 0650abc..dcf0856 100644 --- a/apiGo/api/TVShows.go +++ b/apiGo/api/TVShows.go @@ -7,7 +7,7 @@ import ( "openmediacenter/apiGo/database" ) -func AddTvshowHandlers() { +func addTvshowHandlers() { // do not add handlers if tvshows not enabled if config.GetConfig().Features.DisableTVSupport { return diff --git a/apiGo/api/Tags.go b/apiGo/api/Tags.go index 357ee25..5c3bfb1 100644 --- a/apiGo/api/Tags.go +++ b/apiGo/api/Tags.go @@ -7,7 +7,7 @@ import ( "regexp" ) -func AddTagHandlers() { +func addTagHandlers() { getFromDB() addToDB() deleteFromDB() diff --git a/apiGo/api/Video.go b/apiGo/api/Video.go index aa31057..09886cb 100644 --- a/apiGo/api/Video.go +++ b/apiGo/api/Video.go @@ -11,7 +11,7 @@ import ( "strconv" ) -func AddVideoHandlers() { +func addVideoHandlers() { getVideoHandlers() loadVideosHandlers() addToVideoHandlers() diff --git a/apiGo/api/api/ApiBase.go b/apiGo/api/api/ApiBase.go index 8297d1b..375a4f0 100644 --- a/apiGo/api/api/ApiBase.go +++ b/apiGo/api/api/ApiBase.go @@ -55,7 +55,10 @@ func callHandler(ctx *apicontext, handler func(ctx Context), writer http.Respons } } -func ServerInit() { +func ServerInit(port uint16) error { // initialize auth service and add corresponding auth routes InitOAuth() + + fmt.Printf("OpenMediacenter server up and running on port %d\n", port) + return http.ListenAndServe(fmt.Sprintf(":%d", port), nil) } diff --git a/apiGo/main.go b/apiGo/main.go index d307415..b2a547e 100644 --- a/apiGo/main.go +++ b/apiGo/main.go @@ -2,19 +2,19 @@ package main import ( "fmt" - "log" - "net/http" "openmediacenter/apiGo/api" api2 "openmediacenter/apiGo/api/api" "openmediacenter/apiGo/config" "openmediacenter/apiGo/database" "openmediacenter/apiGo/static" "openmediacenter/apiGo/videoparser" + "os" + "os/signal" ) func main() { fmt.Println("init OpenMediaCenter server") - port := 8081 + const port uint16 = 8081 config.Init() @@ -25,19 +25,25 @@ func main() { database.InitDB() defer database.Close() - api.AddVideoHandlers() - api.AddSettingsHandlers() - api.AddTagHandlers() - api.AddActorsHandlers() - api.AddTvshowHandlers() + api.AddHandlers() videoparser.SetupSettingsWebsocket() // add the static files static.ServeStaticFiles() - api2.ServerInit() + // init api + errc := make(chan error, 1) + go func() { + errc <- api2.ServerInit(port) + }() - fmt.Printf("OpenMediacenter server up and running on port %d\n", port) - log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, os.Interrupt) + select { + case err := <-errc: + fmt.Printf("failed to serve: %v\n", err) + case sig := <-sigs: + fmt.Printf("terminating server: %v\n", sig) + } } diff --git a/src/pages/HomePage/HomePage.tsx b/src/pages/HomePage/HomePage.tsx index 752e259..4a8be75 100644 --- a/src/pages/HomePage/HomePage.tsx +++ b/src/pages/HomePage/HomePage.tsx @@ -14,7 +14,6 @@ import {DefaultTags} from '../../types/GeneralTypes'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faSortDown} from '@fortawesome/free-solid-svg-icons'; -// eslint-disable-next-line no-shadow export enum SortBy { date, likes, diff --git a/src/utils/Api.ts b/src/utils/Api.ts index 1f30e16..e0d344d 100644 --- a/src/utils/Api.ts +++ b/src/utils/Api.ts @@ -97,7 +97,6 @@ function generalAPICall( * API nodes definitions */ -// eslint-disable-next-line no-shadow export enum APINode { Login = 'login', Settings = 'settings',