+ updated readme and no more .env files

This commit is contained in:
Itsigo
2025-11-12 15:56:28 +01:00
parent b3193a10f9
commit 5467ddcbba
7 changed files with 65 additions and 18 deletions

View File

@@ -1,2 +0,0 @@
PORT=3000
TMDB_API_KEY=YOUR_KEY

View File

@@ -8,5 +8,14 @@ build:
@go build -o tmp/main cmd/api/main.go @go build -o tmp/main cmd/api/main.go
setup: 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/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 @curl -o cmd/web/assets/css/fonts/jersey15.woff2 https://fonts.gstatic.com/s/jersey15/v3/_6_9EDzuROGsUuk2TWjiZYAg.woff2

View File

@@ -1,3 +1,23 @@
# PocketMovie # PocketMovie
A small database to keep track of the movies you have seen or want to see. 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
```

View File

@@ -1,13 +1,15 @@
package main package main
import ( import (
"context"
"flag"
"fmt" "fmt"
"os" "os"
"strconv"
"git.itsigo.dev/istigo/pocketmovie/internal/apis"
"git.itsigo.dev/istigo/pocketmovie/internal/database"
"git.itsigo.dev/istigo/pocketmovie/internal/server" "git.itsigo.dev/istigo/pocketmovie/internal/server"
"github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3"
_ "github.com/joho/godotenv/autoload"
) )
func initial() { func initial() {
@@ -20,15 +22,27 @@ func initial() {
} }
func main() { func main() {
var port int
flag.IntVar(&port, "p", 3000, "Provide a port number")
flag.Parse()
initial() 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() app.RegisterFiberRoutes()
port, _ := strconv.Atoi(os.Getenv("PORT")) err := app.Listen(fmt.Sprint(":", port), fiber.ListenConfig{
err := app.Listen(fmt.Sprintf(":%d", port), fiber.ListenConfig{ DisableStartupMessage: false,
DisableStartupMessage: true,
}) })
if err != nil { if err != nil {
panic(fmt.Sprintf("http server error: %s", err)) panic(fmt.Sprintf("http server error: %s", err))

View File

@@ -6,16 +6,17 @@ import (
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"os"
_ "github.com/joho/godotenv/autoload"
) )
var ( var (
token = os.Getenv("TMDB_API_KEY")
apiurl = "https://api.themoviedb.org/3/" apiurl = "https://api.themoviedb.org/3/"
token = ""
) )
func Init(apitoken string) {
token = apitoken
}
func request(requrl string) (*http.Response, []byte) { func request(requrl string) (*http.Response, []byte) {
req, _ := http.NewRequest("GET", apiurl+requrl, nil) req, _ := http.NewRequest("GET", apiurl+requrl, nil)

View File

@@ -15,11 +15,17 @@ import (
"git.itsigo.dev/istigo/pocketmovie/internal/middleware/apikeychecker" "git.itsigo.dev/istigo/pocketmovie/internal/middleware/apikeychecker"
"github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/log" "github.com/gofiber/fiber/v3/log"
"github.com/gofiber/fiber/v3/middleware/compress"
"github.com/gofiber/fiber/v3/middleware/static" "github.com/gofiber/fiber/v3/middleware/static"
) )
func (s *FiberServer) RegisterFiberRoutes() { 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{ s.App.Use("/assets", static.New("./assets", static.Config{
FS: web.Files, FS: web.Files,
@@ -28,6 +34,8 @@ func (s *FiberServer) RegisterFiberRoutes() {
s.App.Use("/movie/posters", static.New("./data/img")) s.App.Use("/movie/posters", static.New("./data/img"))
s.App.Use("/apikey", s.apikeyinput)
s.App.Use( s.App.Use(
//basicauth.New(basicauth.Config{ //basicauth.New(basicauth.Config{
// Users: map[string]string{ // Users: map[string]string{
@@ -35,9 +43,6 @@ func (s *FiberServer) RegisterFiberRoutes() {
// "john": "{SHA256}eZ75KhGvkY4/t0HfQpNPO1aO0tk6wd908bjUGieTKm8=", // "john": "{SHA256}eZ75KhGvkY4/t0HfQpNPO1aO0tk6wd908bjUGieTKm8=",
// }, // },
//}), //}),
//compress.New(compress.Config{
// Level: compress.LevelBestSpeed, // 1
//}),
apikeychecker.New(apikeychecker.Config{DB: *s.db}), apikeychecker.New(apikeychecker.Config{DB: *s.db}),
) )

View File

@@ -11,13 +11,13 @@ type FiberServer struct {
db *database.Queries db *database.Queries
} }
func New() *FiberServer { func New(db *database.Queries) *FiberServer {
server := &FiberServer{ server := &FiberServer{
App: fiber.New(fiber.Config{ App: fiber.New(fiber.Config{
ServerHeader: "PocketMovie", ServerHeader: "PocketMovie",
AppName: "PocketMovie", AppName: "PocketMovie",
}), }),
db: database.Init(), db: db,
} }
return server return server
} }