Skip to content
This repository was archived by the owner on Jun 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f75c4ab
Refactors API and enhances authentication
FinnTheHero Aug 20, 2025
302aa4c
Refactor: Streamlines package structure and introduces token cache
FinnTheHero Aug 20, 2025
b4e77fb
Refactors JWT token handling
FinnTheHero Aug 20, 2025
64cc661
Refactor: Move token generation to `middleware/token` package
FinnTheHero Aug 20, 2025
7763590
Feat: Implement automatic token refresh and refresh token endpoint
FinnTheHero Aug 20, 2025
6d71b50
Refactor: Streamline token validation middleware and handlers
FinnTheHero Aug 20, 2025
d3527cf
chore: Update build artifact name in air.toml
FinnTheHero Aug 22, 2025
cf265d6
chore: Exclude .github directory from air watch
FinnTheHero Aug 22, 2025
a709ac9
feat(common): Add GetDomains utility function
FinnTheHero Aug 22, 2025
67a7a60
refactor(domain): Rename token config struct to LookupUser
FinnTheHero Aug 22, 2025
a1cfb8a
refactor(jwt): Use `any` type for jwt.ParseWithClaims callbacks
FinnTheHero Aug 22, 2025
4d34430
refactor(middleware): Split token validation and user lookup
FinnTheHero Aug 22, 2025
8395362
feat(middleware): Adapt token middleware usage to new design
FinnTheHero Aug 22, 2025
7d0e5c6
feat(server): Use GetDomains for CORS configuration
FinnTheHero Aug 22, 2025
7903ab6
feat: Extract chapter processing to processChap function
FinnTheHero Aug 22, 2025
843e1b1
refactor: Reorder chapters and use processChap in CreateNovelFromEPUB
FinnTheHero Aug 22, 2025
1935819
feat: Prefix all API routes with `/api/`
FinnTheHero Aug 22, 2025
1a36cba
Fix: Handle empty domains slice when initializing in debug mode
FinnTheHero Aug 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/codex"
cmd = "go build -o ./tmp/codex ./api/cmd/codex"
bin = "./tmp/web"
cmd = "go build -o ./tmp/web ./api/cmd/web"
delay = 1000
exclude_dir = [
".git",
Expand All @@ -15,6 +15,7 @@ exclude_dir = [
"node_modules",
".vscode",
".idea",
".github",
]
exclude_file = []
exclude_regex = ["_test\\.go$", "\\.git", "\\.DS_Store"]
Expand Down
4 changes: 2 additions & 2 deletions api/cmd/web/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
cmn "Codex-Backend/api/internal/common"
firestore_server "Codex-Backend/api/internal/interfaces/rest"
cmn "Codex-Backend/api/common"
firestore_server "Codex-Backend/api/internal/server"
"os"

_ "github.com/heroku/x/hmetrics/onload"
Expand Down
4 changes: 2 additions & 2 deletions api/cmd/worker/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
cmn "Codex-Backend/api/internal/common"
queue "Codex-Backend/api/internal/common/river"
cmn "Codex-Backend/api/common"
queue "Codex-Backend/api/common/river"
"context"
"log"
"os"
Expand Down
12 changes: 12 additions & 0 deletions api/internal/common/env.go → api/common/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"net/http"
"os"
"strings"

"github.com/joho/godotenv"
)
Expand All @@ -24,3 +25,14 @@ func GetEnvVariable(v string) string {

return env_variable
}

func GetDomains(v string) []string {
env_variable := os.Getenv(v)
if env_variable == "" {
log.Fatal(&Error{Err: errors.New("Environmental Variable " + v + " Not Found"), Status: http.StatusNotFound})

Copilot AI Aug 22, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.Fatal will terminate the program immediately, but the Error struct with Status field suggests this should return an error instead of calling log.Fatal

Copilot uses AI. Check for mistakes.
}

result := strings.Split(env_variable, ",")

return result

Copilot AI Aug 22, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function will never reach this return statement if the environment variable is empty due to log.Fatal being called above

Copilot uses AI. Check for mistakes.
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package queue

import (
"Codex-Backend/api/internal/usecases/worker"
"Codex-Backend/api/internal/service/worker"
"context"
"log"
"log/slog"
Expand Down
34 changes: 0 additions & 34 deletions api/internal/common/token.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package firestore_client

import (
cmn "Codex-Backend/api/internal/common"
cmn "Codex-Backend/api/common"
"context"
"errors"
"net/http"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package firestore_collections

import (
cmn "Codex-Backend/api/internal/common"
cmn "Codex-Backend/api/common"
"Codex-Backend/api/internal/domain"
"context"
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package firestore_collections

import (
cmn "Codex-Backend/api/internal/common"
cmn "Codex-Backend/api/common"
"Codex-Backend/api/internal/domain"
"context"
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package firestore_collections

import (
cmn "Codex-Backend/api/internal/common"
cmn "Codex-Backend/api/common"
"Codex-Backend/api/internal/domain"
"context"
"errors"
Expand Down
52 changes: 52 additions & 0 deletions api/internal/domain/token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package domain

import (
"sync"
"time"

"github.com/golang-jwt/jwt/v5"
)

type Claims struct {
ID string `json:"id"`
Email string `json:"email"`
Type string `json:"type"`
jwt.RegisteredClaims
}

type TokenConfig struct {
SigningKey string
AccessTTL time.Duration
RefreshTTL time.Duration
Issuer string // e.g., "your-app-name"
Audience string // e.g., "your-app-users"
}

type TokenPair struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresAt time.Time `json:"expires_at"`
TokenType string `json:"token_type"`
}

// TokenCache interface for optional token caching
type TokenCache interface {
Get(key string) (any, bool)
Set(key string, value any, duration time.Duration)
Delete(key string)
}

type LookupUser struct {
Cache TokenCache
CacheDuration time.Duration
}

type InMemoryCache struct {
mu sync.RWMutex
items map[string]cacheItem
}

type cacheItem struct {
value any
expiresAt time.Time
}
7 changes: 0 additions & 7 deletions api/internal/domain/user.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package domain

import "github.com/golang-jwt/jwt/v5"

type User struct {
ID string `json:"id"`
Username string `json:"username"`
Expand All @@ -17,11 +15,6 @@ type Credentials struct {
Password string `json:"password"`
}

type Claims struct {
Email string `json:"email"`
jwt.RegisteredClaims
}

type NewUser struct {
Username string `json:"username"`
Password string `json:"password"`
Expand Down
106 changes: 0 additions & 106 deletions api/internal/interfaces/rest/middleware/token.go

This file was deleted.

Loading