-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4fee65e
Showing
48 changed files
with
1,955 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
root = "." | ||
testdata_dir = "testdata" | ||
tmp_dir = "tmp" | ||
|
||
[build] | ||
args_bin = ['serve'] | ||
bin = "./tmp/main" | ||
cmd = "go build -o ./tmp/main ." | ||
delay = 1000 | ||
exclude_dir = ["assets", "tmp", "vendor", "testdata"] | ||
exclude_file = [] | ||
exclude_regex = ["_test.go"] | ||
exclude_unchanged = false | ||
follow_symlink = false | ||
full_bin = "" | ||
include_dir = [] | ||
include_ext = ["go", "tpl", "tmpl", "html"] | ||
include_file = [] | ||
kill_delay = "0s" | ||
log = "build-errors.log" | ||
poll = false | ||
poll_interval = 0 | ||
post_cmd = [] | ||
pre_cmd = [] | ||
rerun = false | ||
rerun_delay = 500 | ||
send_interrupt = false | ||
stop_on_error = false | ||
|
||
[color] | ||
app = "" | ||
build = "yellow" | ||
main = "magenta" | ||
runner = "green" | ||
watcher = "cyan" | ||
|
||
[log] | ||
main_only = false | ||
time = false | ||
|
||
[misc] | ||
clean_on_exit = false | ||
|
||
[proxy] | ||
app_port = 0 | ||
enabled = false | ||
proxy_port = 0 | ||
|
||
[screen] | ||
clear_on_rebuild = false | ||
keep_scroll = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.iml | ||
.idea | ||
secrets.json | ||
podcast-sync-server | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:1.22 as builder | ||
|
||
WORKDIR /app | ||
|
||
COPY go.* ./ | ||
RUN go mod download | ||
|
||
COPY . ./ | ||
|
||
RUN go build -o podcast-sync-server | ||
|
||
FROM debian:bookworm | ||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --assume-yes libsqlite3-0 | ||
|
||
COPY --from=builder /app/podcast-sync-server /app/podcast-sync-server | ||
|
||
CMD ["/app/podcast-sync-server", "serve"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2024 Christian Bianchi | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# podcast-sync-server | ||
|
||
This project provides (or tries to provide) an implementation of a subset of gpodder.net spec as small | ||
as possible to be compatible with the AntennaPod podcast app. | ||
|
||
## How to run | ||
|
||
go run main.go serve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/whites11/podcast-sync-server/internal/db" | ||
"github.com/whites11/podcast-sync-server/internal/models" | ||
"github.com/whites11/podcast-sync-server/internal/repository" | ||
) | ||
|
||
// createCmd represents the create command | ||
var createCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a new user", | ||
Long: `Create a new user`, | ||
RunE: runCreateUser, | ||
} | ||
|
||
const ( | ||
flagUsername = "username" | ||
) | ||
|
||
func init() { | ||
usersCmd.AddCommand(createCmd) | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
createCmd.Flags().StringP(flagUsername, "u", "", "Username") | ||
|
||
} | ||
|
||
func runCreateUser(cmd *cobra.Command, args []string) error { | ||
username, err := cmd.Flags().GetString(flagUsername) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
dbfactory, err := db.NewSqliteFactory() | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
db, err := dbfactory.Build() | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
usersRepository, err := repository.NewUsersRepository(db) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
fmt.Println("Enter the password of the new user: ") | ||
var pwd string | ||
// Read the users input | ||
_, err = fmt.Scan(&pwd) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
user, err := usersRepository.CreateUser(models.User{ | ||
Username: username, | ||
Password: pwd, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
fmt.Printf("User %s created (id = %d)\n", username, user.ID) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "podcast-sync-server", | ||
Short: "A brief description of your application", | ||
Long: `A longer description that spans multiple lines and likely contains | ||
examples and usage of using your application. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
// Run: func(cmd *cobra.Command, args []string) { }, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
// Here you will define your flags and configuration settings. | ||
// Cobra supports persistent flags, which, if defined here, | ||
// will be global for your application. | ||
|
||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.podcast-sync-server.yaml)") | ||
|
||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/go-chi/chi/v5" | ||
"github.com/go-chi/chi/v5/middleware" | ||
"github.com/go-chi/render" | ||
"github.com/gorilla/securecookie" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/whites11/podcast-sync-server/internal/db" | ||
"github.com/whites11/podcast-sync-server/internal/dependencies" | ||
"github.com/whites11/podcast-sync-server/internal/repository" | ||
"github.com/whites11/podcast-sync-server/internal/routes" | ||
"github.com/whites11/podcast-sync-server/internal/settings" | ||
) | ||
|
||
const ( | ||
flagPort = "port" | ||
) | ||
|
||
// serveCmd represents the serve command | ||
var serveCmd = &cobra.Command{ | ||
Use: "serve", | ||
Short: "Start listening", | ||
Long: `Start listening`, | ||
RunE: run, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(serveCmd) | ||
|
||
serveCmd.Flags().Uint16P(flagPort, "p", 3000, "Port to listen to") | ||
} | ||
|
||
func run(cmd *cobra.Command, args []string) error { | ||
port, err := cmd.Flags().GetUint16(flagPort) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
var deps *dependencies.Dependencies | ||
{ | ||
dbfactory, err := db.NewSqliteFactory() | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
db, err := dbfactory.Build() | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
usersRepository, err := repository.NewUsersRepository(db) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
devicesRepository, err := repository.NewDevicesRepository(db) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
subscriptionsRepository, err := repository.NewSubscriptionsRepository(db) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
episodesActionsRepository, err := repository.NewEpisodeActionsRepository(db) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
secretsStorage, err := settings.NewDatabaseStorage(db) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
secretsProvider, err := settings.New(secretsStorage) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
// Hash keys should be at least 32 bytes long | ||
hashKey, err := secretsProvider.GetOrGenerate("cookies-hash-key", 32) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
// Block keys should be 16 bytes (AES-128) or 32 bytes (AES-256) long. | ||
blockKey, err := secretsProvider.GetOrGenerate("cookies-block-key", 32) | ||
if err != nil { | ||
return fmt.Errorf("%w", err) | ||
} | ||
|
||
secureCookie := securecookie.New([]byte(hashKey), []byte(blockKey)) | ||
|
||
deps = dependencies.New(devicesRepository, episodesActionsRepository, subscriptionsRepository, usersRepository, secureCookie) | ||
} | ||
|
||
r := chi.NewRouter() | ||
r.Use(middleware.RequestID) | ||
r.Use(middleware.RealIP) | ||
r.Use(middleware.Logger) | ||
r.Use(middleware.Recoverer) | ||
r.Use(render.SetContentType(render.ContentTypeJSON)) | ||
|
||
routes.NewProbesRouter().Setup(r) | ||
|
||
r.Route("/api", func(r chi.Router) { | ||
routes.NewV2Router(r, deps).Setup() | ||
}) | ||
|
||
fmt.Printf("Listening on 0.0.0.0:%d\n", port) | ||
return http.ListenAndServe(fmt.Sprintf(":%d", port), r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// usersCmd represents the users command | ||
var usersCmd = &cobra.Command{ | ||
Use: "users", | ||
Short: "Manage users", | ||
Long: `Manage users`, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(usersCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// usersCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// usersCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module github.com/whites11/podcast-sync-server | ||
|
||
go 1.22 | ||
|
||
require ( | ||
github.com/ajg/form v1.5.1 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect | ||
github.com/go-chi/chi/v5 v5.0.14 // indirect | ||
github.com/go-chi/render v1.0.3 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.22.0 // indirect | ||
github.com/gorilla/securecookie v1.1.2 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/jinzhu/inflection v1.0.0 // indirect | ||
github.com/jinzhu/now v1.1.5 // indirect | ||
github.com/leodido/go-urn v1.4.0 // indirect | ||
github.com/mattn/go-sqlite3 v1.14.22 // indirect | ||
github.com/spf13/cobra v1.8.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
golang.org/x/crypto v0.19.0 // indirect | ||
golang.org/x/net v0.21.0 // indirect | ||
golang.org/x/sys v0.17.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
gorm.io/driver/sqlite v1.5.6 // indirect | ||
gorm.io/gorm v1.25.10 // indirect | ||
) |
Oops, something went wrong.