diff --git a/.env.sample b/.env.sample deleted file mode 100644 index 6db3791..0000000 --- a/.env.sample +++ /dev/null @@ -1,2 +0,0 @@ -PORT=3000 -TMDB_API_KEY=YOUR_KEY diff --git a/Makefile b/Makefile index c6dd43a..3c3ff14 100644 --- a/Makefile +++ b/Makefile @@ -8,5 +8,14 @@ build: @go build -o tmp/main cmd/api/main.go setup: + @command -v templ >/dev/null 2>&1 || { \ + echo "Installing templ..."; \ + go install github.com/a-h/templ/cmd/templ@latest; \ + } + @command -v sqlc >/dev/null 2>&1 || { \ + echo "Installing sqlc..."; \ + go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest; \ + } @curl -o cmd/web/assets/js/datastar.js https://cdn.jsdelivr.net/gh/starfederation/datastar@main/bundles/datastar.js + @curl -o cmd/web/assets/css/pico.min.css https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css @curl -o cmd/web/assets/css/fonts/jersey15.woff2 https://fonts.gstatic.com/s/jersey15/v3/_6_9EDzuROGsUuk2TWjiZYAg.woff2 diff --git a/README.md b/README.md index 0329c88..417b7c2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,23 @@ # PocketMovie A small database to keep track of the movies you have seen or want to see. + +I made this so I can directly see where I can watch a movie I put on my watchlist. Since I'm only subscribed to a hand full of services. + +What you can do with it: + +- Add movies you have seen or want to see +- Document wether you own the movie or not +- See where movies are streamed via flatrate in your watchlist. You can add or remove streaming services in your settings. + +## Installation + +The project comes in a single binary. You execute it and the web server is running. It will create a data directory to store the sqllite database and the movie posters. + +```bash +// just execute the binary +./pocketmovie + +// You can also specify the port you want to use +./pocketmovie -p 6000 +``` diff --git a/cmd/api/main.go b/cmd/api/main.go index 219d52f..66432f7 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -1,13 +1,15 @@ package main import ( + "context" + "flag" "fmt" "os" - "strconv" + "git.itsigo.dev/istigo/pocketmovie/internal/apis" + "git.itsigo.dev/istigo/pocketmovie/internal/database" "git.itsigo.dev/istigo/pocketmovie/internal/server" "github.com/gofiber/fiber/v3" - _ "github.com/joho/godotenv/autoload" ) func initial() { @@ -20,15 +22,27 @@ func initial() { } func main() { + var port int + + flag.IntVar(&port, "p", 3000, "Provide a port number") + + flag.Parse() + initial() - app := server.New() + db := database.Init() + app := server.New(db) + + ctx := context.Background() + + // api key to request manager + token, _ := db.ListSetting(ctx, 2) + apis.Init(token.Value) app.RegisterFiberRoutes() - port, _ := strconv.Atoi(os.Getenv("PORT")) - err := app.Listen(fmt.Sprintf(":%d", port), fiber.ListenConfig{ - DisableStartupMessage: true, + err := app.Listen(fmt.Sprint(":", port), fiber.ListenConfig{ + DisableStartupMessage: false, }) if err != nil { panic(fmt.Sprintf("http server error: %s", err)) diff --git a/internal/apis/tmdb.go b/internal/apis/tmdb.go index bb985ce..ea14b22 100644 --- a/internal/apis/tmdb.go +++ b/internal/apis/tmdb.go @@ -6,16 +6,17 @@ import ( "io" "net/http" "net/url" - "os" - - _ "github.com/joho/godotenv/autoload" ) var ( - token = os.Getenv("TMDB_API_KEY") apiurl = "https://api.themoviedb.org/3/" + token = "" ) +func Init(apitoken string) { + token = apitoken +} + func request(requrl string) (*http.Response, []byte) { req, _ := http.NewRequest("GET", apiurl+requrl, nil) diff --git a/internal/server/routes.go b/internal/server/routes.go index c3624d6..c19e4d7 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -15,11 +15,17 @@ import ( "git.itsigo.dev/istigo/pocketmovie/internal/middleware/apikeychecker" "github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3/log" + "github.com/gofiber/fiber/v3/middleware/compress" "github.com/gofiber/fiber/v3/middleware/static" ) func (s *FiberServer) RegisterFiberRoutes() { - s.App.Use("/apikey", s.apikeyinput) + + s.App.Use( + compress.New(compress.Config{ + Level: compress.LevelBestSpeed, // 1 + }), + ) s.App.Use("/assets", static.New("./assets", static.Config{ FS: web.Files, @@ -28,6 +34,8 @@ func (s *FiberServer) RegisterFiberRoutes() { s.App.Use("/movie/posters", static.New("./data/img")) + s.App.Use("/apikey", s.apikeyinput) + s.App.Use( //basicauth.New(basicauth.Config{ // Users: map[string]string{ @@ -35,9 +43,6 @@ func (s *FiberServer) RegisterFiberRoutes() { // "john": "{SHA256}eZ75KhGvkY4/t0HfQpNPO1aO0tk6wd908bjUGieTKm8=", // }, //}), - //compress.New(compress.Config{ - // Level: compress.LevelBestSpeed, // 1 - //}), apikeychecker.New(apikeychecker.Config{DB: *s.db}), ) diff --git a/internal/server/server.go b/internal/server/server.go index cba90d1..ac467cf 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -11,13 +11,13 @@ type FiberServer struct { db *database.Queries } -func New() *FiberServer { +func New(db *database.Queries) *FiberServer { server := &FiberServer{ App: fiber.New(fiber.Config{ ServerHeader: "PocketMovie", AppName: "PocketMovie", }), - db: database.Init(), + db: db, } return server }