Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 8a6e82d

Browse files
authored
Merge branch 'master' into swarmy
2 parents 79d8e36 + 95c711b commit 8a6e82d

8 files changed

Lines changed: 62 additions & 43 deletions

File tree

api/v2/routes_rtfs.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,9 @@ func (api *API) extendPin(c *gin.Context) {
364364
Fail(c, err)
365365
return
366366
}
367-
// find usage model
368-
usage, err := api.usage.FindByUserName(username)
367+
usg, err := api.usage.FindByUserName(username)
369368
if err != nil {
370-
api.LogError(c, err, eh.UserSearchError)(http.StatusBadRequest)
371-
return
372-
}
373-
// make sure they aren't a free account
374-
if usage.Tier == models.Free {
375-
Fail(c, errors.New("free accounts are not allowed to extend pin times"))
369+
api.LogError(c, err, eh.UserSearchError)
376370
return
377371
}
378372
// find upload
@@ -382,7 +376,7 @@ func (api *API) extendPin(c *gin.Context) {
382376
return
383377
}
384378
// ensure even with pin time extension, it wont breach two year limit
385-
if err := api.ensureTwoYearMax(upload, holdTimeInt); err != nil {
379+
if err := api.ensureLEMaxPinTime(upload, holdTimeInt, usg.Tier); err != nil {
386380
Fail(c, err)
387381
return
388382
}

api/v2/routes_utils.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,16 @@ func (api *API) handleUserCreate(c *gin.Context, forms map[string]string, create
329329
es := queue.EmailSend{
330330
Subject: emailSubject,
331331
Content: fmt.Sprintf(
332-
"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
332+
"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
333333
"Thanks for signing up with Temporal, before you get started it's important we discuss our pinning system.\n",
334334
"When uploading to Temporal you must specify a \"hold time\" which tells our system how long your data should be around for.\n",
335-
"When you're using Temporal via the playground, or the API directly you can configure this for up to 24 months with paid accounts, and up to 1 month for free accounts.\n",
335+
"When you're using Temporal via the playground, or the API directly you can configure this for up to 24 months with paid accounts, and up to 12 months for free accounts.\n",
336336
"Temporal’s free tier offers 3GB of storage on the house, paid tier rates are just $0.07/GB and partner tier rates are $0.05/GB.\n",
337337
"<br>",
338338
"<br>",
339-
"When using Temporal through third-party implementations like our IPFS HTTP API reverse proxy, or the ENS management app, we use a default hold time of 1 month.\n",
340-
"For example if you used the ENS management app to upload your website, and want it to stick around for longer than 1 month you need to extend your pin.\n",
339+
"When using Temporal through third-party implementations like our IPFS HTTP API reverse proxy, or the ENS management app, we use a default hold time of 12 months for free users and 1 month for paid users.\n",
340+
"We use 1 month for paid users because being in the paid tier means you have to pay for the data consumption and we don't want to overcharge paid users.\n",
341+
"For example if you used the ENS management app to upload your website, and want it to stick around for longer than the default duration you need to extend the pin.\n",
341342
"Pin extension can be done via the <a href=\"https://play2.temporal.cloud\">Temporal Playground</a> or via the API.\n",
342343
"<br>",
343344
"<br>",

api/v2/utils.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ func (api *API) extractPostForms(c *gin.Context, formNames ...string) (map[strin
234234
// returning an int64 type of the provided hold time
235235
func (api *API) validateHoldTime(username, holdTime string) (int64, error) {
236236
var (
237-
// 1 month
238-
freeHoldTimeLimitInMonths int64 = 1
237+
// 1 year
238+
freeHoldTimeLimitInMonths int64 = 12
239239
// two years
240240
nonFreeHoldTimeLimitInMonths int64 = 24
241241
)
@@ -248,20 +248,24 @@ func (api *API) validateHoldTime(username, holdTime string) (int64, error) {
248248
return 0, err
249249
}
250250
if usageTier.Tier == models.Free && holdTimeInt > freeHoldTimeLimitInMonths {
251-
return 0, errors.New("free accounts are limited to maximum hold times of 1 month")
251+
return 0, errors.New("free accounts are limited to maximum hold times of 12 month")
252252
} else if usageTier.Tier != models.Free && holdTimeInt > nonFreeHoldTimeLimitInMonths {
253253
return 0, errors.New("non free accounts are limited to a maximum hold time of 24 months")
254254
}
255255
return holdTimeInt, nil
256256
}
257257

258-
func (api *API) ensureTwoYearMax(upload *models.Upload, holdTime int64) error {
259-
// get current time
260-
now := time.Now()
261-
// get future time while factoring for additional hold time
262-
then := upload.GarbageCollectDate.AddDate(0, int(holdTime), 0)
263-
// get the time difference and ensure its less than the 2 year limit
264-
if then.Sub(now).Hours() > 17520 {
258+
func (api *API) ensureLEMaxPinTime(upload *models.Upload, holdTime int64, tier models.DataUsageTier) error {
259+
var limit time.Time
260+
switch tier {
261+
case models.Free:
262+
limit = time.Now().AddDate(1, 0, 0)
263+
case models.Paid, models.Partner, models.WhiteLabeled:
264+
limit = time.Now().AddDate(2, 0, 0)
265+
default:
266+
return errors.New("invalid usage tier")
267+
}
268+
if upload.GarbageCollectDate.AddDate(0, int(holdTime), 0).After(limit) {
265269
return errors.New(eh.MaxHoldTimeError)
266270
}
267271
return nil

api/v2/utils_test.go

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,40 +133,57 @@ func Test_Ensure_Two_Year_Max(t *testing.T) {
133133
randUtils := utils.GenerateRandomUtils()
134134
randString := randUtils.GenerateString(32, utils.LetterBytes)
135135
um := models.NewUploadManager(db)
136-
upload, err := um.NewUpload(
137-
randString,
138-
"file",
139-
models.UploadOptions{
140-
Username: "testuser",
141-
NetworkName: "public",
142-
HoldTimeInMonths: 1,
143-
Encrypted: false,
144-
},
145-
)
146136
if err != nil {
147137
t.Fatal(err)
148138
}
149139
type args struct {
150140
holdTimeInMonths int64
151-
upload *models.Upload
141+
tier models.DataUsageTier
152142
}
153143
tests := []struct {
154144
name string
155145
args args
156146
wantErr bool
157147
}{
158-
{"12-Months", args{12, upload}, false},
159-
{"22-Months", args{22, upload}, false},
160-
{"25-Months", args{25, upload}, true},
148+
{"12-Months-paid", args{12, models.Paid}, false},
149+
{"22-Months-paid", args{22, models.Paid}, false},
150+
{"25-Months-paid", args{25, models.Paid}, true},
151+
{"10-Months-free", args{10, models.Free}, false},
152+
{"11-Months-free", args{11, models.Free}, false},
153+
{"12-Months-free", args{12, models.Free}, true},
154+
{"22-Months-free", args{22, models.Free}, true},
155+
{"25-Months-free", args{25, models.Free}, true},
156+
{"12-Months-partner", args{12, models.Partner}, false},
157+
{"22-Months-partner", args{22, models.Partner}, false},
158+
{"25-Months-partner", args{25, models.Partner}, true},
159+
{"12-Months-whitelabeled", args{12, models.WhiteLabeled}, false},
160+
{"22-Months-whitelabeled", args{22, models.WhiteLabeled}, false},
161+
{"25-Months-whitelabeled", args{25, models.WhiteLabeled}, true},
162+
{"not-a-real-tier", args{12, models.DataUsageTier("thetierisalie")}, true},
161163
}
162164
for _, tt := range tests {
163165
t.Run(tt.name, func(t *testing.T) {
164-
if err := api.ensureTwoYearMax(
165-
tt.args.upload,
166+
upload, err := um.NewUpload(
167+
randString,
168+
"file",
169+
models.UploadOptions{
170+
Username: "testuser",
171+
NetworkName: "public",
172+
HoldTimeInMonths: 1,
173+
Encrypted: false,
174+
},
175+
)
176+
if err != nil {
177+
t.Fatal(err)
178+
}
179+
if err := api.ensureLEMaxPinTime(
180+
upload,
166181
tt.args.holdTimeInMonths,
182+
tt.args.tier,
167183
); (err != nil) != tt.wantErr {
168184
t.Fatalf("ensureTwoYearMax err = %v, wantErr %v", err, tt.wantErr)
169185
}
186+
um.DB.Unscoped().Delete(upload)
170187
})
171188
}
172189
}

eh/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const (
131131
// PinExtendError is an error message used when someone attempts to extend the pin for content they haven't uploaded
132132
PinExtendError = "failed to extend pin duration, this likely means you haven't actually uploaded this content before"
133133
// MaxHoldTimeError is an error message when the current hold time value would breach set pin time limits
134-
MaxHoldTimeError = "a hold time of this long would result in a longer maximum pin time of 2 years, please reduce your hold time and try again"
134+
MaxHoldTimeError = "a hold time of this long would result in a longer maximum pin time than what your account allow, please reduce your hold time and try again"
135135
// HostNameNotFoundError is an error message when api server has not hostname
136136
HostNameNotFoundError = "an api host has not hostname, please set hostname"
137137
)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/RTradeLtd/cmd/v2 v2.1.0
88
github.com/RTradeLtd/config/v2 v2.2.0
99
github.com/RTradeLtd/crypto/v2 v2.1.1
10-
github.com/RTradeLtd/database/v2 v2.7.3-rc1
10+
github.com/RTradeLtd/database/v2 v2.7.4
1111
github.com/RTradeLtd/entropy-mnemonics v0.0.0-20170316012907-7b01a644a636
1212
github.com/RTradeLtd/go-ipfs-api v0.0.0-20190522213636-8e3700e602fd
1313
github.com/RTradeLtd/gpaginator v0.0.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ github.com/RTradeLtd/crypto v2.0.0+incompatible h1:3+UEo0upD0p3A+7yLJ14UJpT6aZEh
4242
github.com/RTradeLtd/crypto v2.0.0+incompatible/go.mod h1:xhKwg748pxs2as6Ts65TiBBFrYzntioTqBIZEa1BUio=
4343
github.com/RTradeLtd/crypto/v2 v2.1.1 h1:P59zYkkNkl6K1KiTRvW52AYwLvwmtzuzZ9+AjLWmKsU=
4444
github.com/RTradeLtd/crypto/v2 v2.1.1/go.mod h1:saIQ67Btn4JWsOdzjn9U6Dl+aZlg+YKgg4RsQKXxjf4=
45-
github.com/RTradeLtd/database/v2 v2.7.3-rc1 h1:kHj0H1uwXqMhAj4S3qNelRA4Mee0h3+GLa0kF5kLwHw=
46-
github.com/RTradeLtd/database/v2 v2.7.3-rc1/go.mod h1:7t4vOzLgmvIz9qnZC0UY0cwdbpkVIhE6I9BaCKV4/us=
45+
github.com/RTradeLtd/database/v2 v2.7.4 h1:7kYdfjMpvnccrzxt/l29DUTRXsfiWBzuNmGsY+BmVJA=
46+
github.com/RTradeLtd/database/v2 v2.7.4/go.mod h1:2Q64z+Gdas9wgMpO72iKYW3tCsHs2SJHPzdROcj6MLE=
4747
github.com/RTradeLtd/entropy-mnemonics v0.0.0-20170316012907-7b01a644a636 h1:i/+1LBA+YMfD1m9UnQP52A7S6y2U3C0xpMBehPkDRug=
4848
github.com/RTradeLtd/entropy-mnemonics v0.0.0-20170316012907-7b01a644a636/go.mod h1:zpzHNRdCMCG9PM9QO5jVSldXCRMJ7lY42yJ5TEe//7M=
4949
github.com/RTradeLtd/go-ipfs-api v0.0.0-20190308091756-8b7099fd5e21/go.mod h1:ipDfy60LjYDddlX/zluSwRVtfGR0EB1HqADazGNMUmE=

utils/cmc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ REFRESH:
120120
}
121121
if quotemap["quote"] != nil {
122122
b, err = json.Marshal(quotemap["quote"])
123+
if err != nil {
124+
return pricer.coins[coin].price, err
125+
}
123126
if err := json.Unmarshal(b, &usdmap); err != nil {
124127
fmt.Println("error: ", err)
125128
return pricer.coins[coin].price, err

0 commit comments

Comments
 (0)