Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Int #44

Merged
3 commits merged into from
Jan 6, 2024
Merged

Int #44

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/openapi-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,10 @@ components:
in: header
description: Private url will be expires
schema:
description: Seconds, relative from now
description: Seconds, relative from now, Must be positive integer
type: integer
maximum: 604800 # 7 days
minimum: 0
format: int
fileMetaAutoDeletedAt:
name: File-Auto-Deleted-At
Expand Down
2 changes: 1 addition & 1 deletion internal/models/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type DataFile struct {
Url string `json:"url"`
ContentType string `json:"type"`
AutoDeletedAt int64 `json:"autoDeletedAt"` // in milliseconds
PrivateUrlExpires int `json:"privateUrlExpires"` // in seconds
PrivateUrlExpires uint `json:"privateUrlExpires"` // in seconds
UploadedAt int64 `json:"uploadedAt"` // in milliseconds
UpdatedAt int64 `json:"updatedAt"` // in milliseconds
Size int64 `json:"size"` // in bytes
Expand Down
9 changes: 5 additions & 4 deletions internal/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ func createClient(ctx context.Context) (*storage.Client, error) {
func UnmarshalMetadata(metadata map[string]string, fileData *models.DataFile) error {
autoDeletedAt, err := strconv.ParseInt(metadata[HeaderAutoDeletedAt], 10, 64)
if err != nil {
return err
return errors.New("auto_deleted_at_should_be_valid_integer")
}

privateUrlExpiredAt, err := strconv.Atoi(metadata[HeaderPrivateUrlExpires])
privateUrlInt64, err := strconv.ParseInt(metadata[HeaderPrivateUrlExpires], 10, 0)
if err != nil {
return err
return errors.New("private_url_expires_should_be_valid_positive_integer")
}
privateUrlExpiredAt := uint(privateUrlInt64)

// cutoff 7 days + 1 second from now
if cutoff := time.Now().Add(604801 * time.Second); !time.Now().Add(time.Duration(privateUrlExpiredAt) * time.Second).Before(cutoff) {
Expand All @@ -110,7 +111,7 @@ func UnmarshalMetadata(metadata map[string]string, fileData *models.DataFile) er
if err != nil {
boolInt, err := strconv.Atoi(metadata[HeaderIsPublic])
if err != nil {
return err
return errors.New("is_public_should_be_valid_boolean_or_integer")
}

switch boolInt {
Expand Down
2 changes: 1 addition & 1 deletion pkg/files/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func HandleUploadFile(ctx *fiber.Ctx) error {
})
}

func validateExpiry(urlExp int, autoDel int64) error {
func validateExpiry(urlExp uint, autoDel int64) error {
if time.Now().Add(time.Duration(urlExp)*time.Second).UnixMilli() > autoDel {
return errors.New("private_url_expires_cannot_be_later_than_auto_deleted_at_starting_from_now")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/files/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestValidateExpiry(test *testing.T) {
tableTests := []struct {
err any
name string
urlExp int
urlExp uint
autoDel int64
}{
{
Expand Down
2 changes: 1 addition & 1 deletion web