Add support for direct downloads of server files

This commit is contained in:
Dane Everitt
2020-04-06 20:27:57 -07:00
parent cc54b99b55
commit 3edcd5f9c3
3 changed files with 70 additions and 0 deletions

25
router/tokens/file.go Normal file
View File

@@ -0,0 +1,25 @@
package tokens
import (
"github.com/gbrlsnchs/jwt/v3"
)
type FilePayload struct {
jwt.Payload
FilePath string `json:"file_path"`
ServerUuid string `json:"server_uuid"`
UniqueId string `json:"unique_id"`
}
// Returns the JWT payload.
func (p *FilePayload) GetPayload() *jwt.Payload {
return &p.Payload
}
// Determines if this JWT is valid for the given request cycle. If the
// unique ID passed in the token has already been seen before this will
// return false. This allows us to use this JWT as a one-time token that
// validates all of the request.
func (p *FilePayload) IsUniqueRequest() bool {
return getTokenStore().IsValidToken(p.UniqueId)
}