repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
b139718
parent
dca976a
author
Eric Bower
date
2024-03-01 17:06:58 +0000 UTC
fix(scripts): make pico-plus script more flexible
4 files changed,  +19, -9
M Makefile
+4, -3
 1@@ -74,9 +74,10 @@ store-clean:
 2 .PHONY: store-clean
 3 
 4 pico-plus:
 5-	# USER=picouser TXID=pi_xxx make pico-plus
 6-	# TXID is from stripe, but can be empty
 7-	go run ./cmd/scripts/pico-plus/main.go $(USER) $(TXID)
 8+	# USER=picouser PTYPE=stripe TXID=pi_xxx make pico-plus
 9+	# USER=picouser PTYPE=snail make pico-plus
10+	# USER=picouser make pico-plus
11+	go run ./cmd/scripts/pico-plus/main.go $(USER) $(PTYPE) $(TXID)
12 .PHONY: pico-plus
13 
14 scripts:
M cmd/scripts/pico-plus/main.go
+10, -2
 1@@ -14,15 +14,23 @@ func main() {
 2 
 3 	args := os.Args
 4 	username := args[1]
 5-	txId := args[2]
 6+	paymentType := ""
 7+	if len(args) > 2 {
 8+		paymentType = args[2]
 9+	}
10+	txId := ""
11+	if len(args) > 3 {
12+		txId = args[2]
13+	}
14 
15 	logger.Info(
16 		"Upgrading user to pico+",
17 		"username", username,
18+		"paymentType", paymentType,
19 		"txId", txId,
20 	)
21 
22-	err := dbpool.AddPicoPlusUser(username, txId)
23+	err := dbpool.AddPicoPlusUser(username, paymentType, txId)
24 	if err != nil {
25 		logger.Error("Failed to add pico+ user", "err", err)
26 		os.Exit(1)
M db/db.go
+1, -1
1@@ -324,7 +324,7 @@ type DB interface {
2 
3 	AddViewCount(postID string) (int, error)
4 
5-	AddPicoPlusUser(username string, txId string) error
6+	AddPicoPlusUser(username string, paymentType, txId string) error
7 	FindFeatureForUser(userID string, feature string) (*FeatureFlag, error)
8 	HasFeatureForUser(userID string, feature string) bool
9 	FindTotalSizeForUser(userID string) (int, error)
M db/postgres/storage.go
+4, -3
 1@@ -1541,7 +1541,7 @@ func (me *PsqlDB) FindTokensForUser(userID string) ([]*db.Token, error) {
 2 	return keys, nil
 3 }
 4 
 5-func (me *PsqlDB) AddPicoPlusUser(username, txId string) error {
 6+func (me *PsqlDB) AddPicoPlusUser(username, paymentType, txId string) error {
 7 	user, err := me.FindUserForName(username)
 8 	if err != nil {
 9 		return err
10@@ -1556,14 +1556,15 @@ func (me *PsqlDB) AddPicoPlusUser(username, txId string) error {
11 		err = tx.Rollback()
12 	}()
13 
14-	if txId != "" {
15+	if paymentType != "" {
16 		data := db.PaymentHistoryData{
17 			Notes: "",
18 			TxID:  txId,
19 		}
20 		_, err := tx.Exec(
21-			`INSERT INTO payment_history (user_id, payment_type, amount, data) VALUES ($1, 'stripe', 20 * 1000000, $2);`,
22+			`INSERT INTO payment_history (user_id, payment_type, amount, data) VALUES ($1, $2, 20 * 1000000, $3);`,
23 			user.ID,
24+			paymentType,
25 			data,
26 		)
27 		if err != nil {