Skip to content

Commit

Permalink
Merge pull request #103 from getAlby/feat/expires-at-timestamp
Browse files Browse the repository at this point in the history
feat: allow passing expires_at as a timestamp in seconds
  • Loading branch information
rolznz authored Jul 1, 2023
2 parents 165955f + 08d8aa5 commit 28bfc52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ If the client creates the secret the client only needs to share the public key o
- `c`: the name of the client app
- `pubkey`: the public key of the client's secret for the user to authorize
- `return_to`: (optional) if a `return_to` URL is provided the user will be redirected to that URL after authorization. The `lud16`, `relay` and `pubkey` query parameters will be added to the URL.
- `expires_at` (optional) connection cannot be used after this date. Format: 2024-05-23
- `expires_at` (optional) connection cannot be used after this date. Unix timestamp in seconds.
- `max_amount` (optional) maximum amount in sats that can be sent per renewal period
- `budget_renewal` (optional) reset the budget at the end of the given budget renewal. Can be `never` (default), `daily`, `weekly`, `monthly`, `yearly`
- `editable` (optional) set to `false` to disable form editing by the user
Expand Down
7 changes: 5 additions & 2 deletions echo_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ func (svc *Service) AppsNewHandler(c echo.Context) error {
returnTo := c.QueryParam("return_to")
maxAmount := c.QueryParam("max_amount")
budgetRenewal := strings.ToLower(c.QueryParam("budget_renewal"))
expiresAt := c.QueryParam("expires_at") // YYYY-MM-DD or MM/DD/YYYY
expiresAt := c.QueryParam("expires_at") // YYYY-MM-DD or MM/DD/YYYY or timestamp in seconds
if expiresAtTimestamp, err := strconv.Atoi(expiresAt); err == nil {
expiresAt = time.Unix(int64(expiresAtTimestamp), 0).Format(time.RFC3339)
}
disabled := c.QueryParam("editable") == "false"
budgetEnabled := maxAmount != "" || budgetRenewal != ""
csrf, _ := c.Get(middleware.DefaultCSRFConfig.ContextKey).(string)
Expand Down Expand Up @@ -282,7 +285,7 @@ func (svc *Service) AppsCreateHandler(c echo.Context) error {
app := App{Name: name, NostrPubkey: pairingPublicKey}
maxAmount, _ := strconv.Atoi(c.FormValue("MaxAmount"))
budgetRenewal := c.FormValue("BudgetRenewal")
expiresAt, _ := time.Parse("2006-01-02", c.FormValue("ExpiresAt"))
expiresAt, _ := time.Parse(time.RFC3339, c.FormValue("ExpiresAt"))
if !expiresAt.IsZero() {
expiresAt = time.Date(expiresAt.Year(), expiresAt.Month(), expiresAt.Day(), 23, 59, 59, 0, expiresAt.Location())
}
Expand Down

0 comments on commit 28bfc52

Please sign in to comment.