Skip to content

Commit

Permalink
Use a config option to enable subscription features
Browse files Browse the repository at this point in the history
  • Loading branch information
mdouchement committed Oct 31, 2022
1 parent 888d795 commit d3bb398
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
version: '3'

vars:
VERSION: 0.9.2
VERSION: 0.10.0
REVISION: { sh: git rev-parse HEAD }
WORKDIR: { sh: pwd }

Expand Down
3 changes: 2 additions & 1 deletion cmd/standardfile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func kdf(l int, k []byte) []byte {
return payload
}

/// keyFromConfig reads a key from the configuration, and if it's not present, tries to read it from a file instead
// keyFromConfig reads a key from the configuration, and if it's not present, tries to read it from a file instead
func keyFromConfig(konf *koanf.Koanf, path string) (out []byte, err error) {
// check if the key is directly placed in the config file
out = konf.Bytes(path)
Expand Down Expand Up @@ -171,6 +171,7 @@ var (
Database: db,
NoRegistration: konf.Bool("no_registration"),
ShowRealVersion: konf.Bool("show_real_version"),
EnableSubscription: konf.Bool("enable_subscription"),
SigningKey: configSecretKey,
SessionSecret: kdf(32, configSessionSecret),
AccessTokenExpirationTime: konf.MustDuration("session.access_token_ttl"),
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 13 additions & 10 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (

// A Controller is an Iversion Of Control pattern used to init the server package.
type Controller struct {
Version string
Database database.Client
NoRegistration bool
ShowRealVersion bool
Version string
Database database.Client
NoRegistration bool
ShowRealVersion bool
EnableSubscription bool
// JWT params
SigningKey []byte
// Session params
Expand Down Expand Up @@ -146,12 +147,14 @@ func EchoEngine(ctrl Controller) *echo.Echo {
//
// subscription handlers
//
subscription := &subscription{}
router.GET("/v2/subscriptions", func(c echo.Context) error {
return c.HTML(http.StatusInternalServerError, "getaddrinfo EAI_AGAIN payments")
})
v1restricted.GET("/users/:id/subscription", subscription.SubscriptionV1)
v1restricted.GET("/users/:id/features", subscription.Features)
if ctrl.EnableSubscription {
subscription := &subscription{}
router.GET("/v2/subscriptions", func(c echo.Context) error {
return c.HTML(http.StatusInternalServerError, "getaddrinfo EAI_AGAIN payments")
})
v1restricted.GET("/users/:id/subscription", subscription.SubscriptionV1)
v1restricted.GET("/users/:id/features", subscription.Features)
}

return engine
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type subscription struct{}
func (h *subscription) SubscriptionV1(c echo.Context) error {
user := currentUser(c)

// The official standard notes client has a race condition,
// The official Standard Notes client has a race condition,
// the features endpoint will only be called when delaying response...
time.Sleep(1 * time.Second)

Expand Down
12 changes: 12 additions & 0 deletions standardfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ session:
secret: paseto-development
access_token_ttl: 1440h # 60 days expressed in Golang's time.Duration format
refresh_token_ttl: 8760h # 1 year
# This option enables paid features in the official StandardNotes client.
# If you want to enables these features, you should consider to
# donate to the StandardNotes project as they say:
#
# Building Standard Notes has high costs. If everyone evaded contributing financially,
# we would no longer be here to continue to build upon and improve these services for you.
# Please consider [donating](https://standardnotes.com/donate) if you do not plan on purchasing a subscription.
# https://docs.standardnotes.com/self-hosting/subscriptions/
#
# This project https://github.com/mdouchement/standardfile does not intend to
# conflict with the business model of StandardNotes project or seek compensation.
enable_subscription: true

0 comments on commit d3bb398

Please sign in to comment.