utils

package
v1.9.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	REDIS_HOST      string
	REDIS_PASSWORD  string
	REDIS_PORT      string
	REDIS_DB        string
	REDIS_PREFIX    string
	TOKEN_SEPARATOR string
	NO_SSL          bool = false
	APP_PORT        string
	APP_NAME        string
	DISCLAIMER      string
	COPYRIGHT       string
	FILEFOLDER      string
	MAXFILESIZE     string
	MaxFileSize     int64
	DataContext     pongo2.Context
)

Functions

func CleanFile

func CleanFile(fileName string)

func CleanFileWatch

func CleanFileWatch()

*

  • Subscribe to Redis and create a goroutine to check when a key expire then clean the associated file.

func Decrypt

func Decrypt(password []byte, decryptionKey string, ttl int) (string, error)

*

  • Decrypt a password (bytes) using the provided key (bytes) and return the plain-text password (bytes).
  • @param password
  • @param decryption_key

func Encrypt

func Encrypt(password string) ([]byte, string, error)

* Take a password string, encrypt it with Fernet symmetric encryption and return the result (bytes), with the decryption key (bytes). * @param password

func GenerateRandomString added in v1.9.2

func GenerateRandomString(n int) (string, error)

*

func GetBaseUrl

func GetBaseUrl(context echo.Context) string

*

  • Return url with http or https based on NO_SSL env value.

func GetDownloadsText added in v1.9.0

func GetDownloadsText(ttlViews int) (viewsDownload string)

* Transform Downloads to text.

func GetFile

func GetFile(f *models.File) *echo.HTTPError

func GetMaxFileSizeText

func GetMaxFileSizeText() string

func GetPassword

func GetPassword(p *models.Password) *echo.HTTPError

* Get a password from the Redis store. Source: https://gist.github.com/pohzipohzi/a202f8fb7cc30e33176dd97a9def5aac. Source: https://www.alexedwards.net/blog/working-with-redis.

func GetTTLText

func GetTTLText(ttl int) (ttlText string)

* Transform TTL to text.

func GetTtlSeconds

func GetTtlSeconds(ttl int) int

*

  • Transform TTL from form to seconds.

func GetViewsText added in v1.9.0

func GetViewsText(ttlViews int) (viewsText string)

* Transform Views to text.

func ParseToken

func ParseToken(token string) (string, string, error)

*

  • Return splitted token.
  • @param token

func Ping

func Ping(c redis.Conn) bool

Ping tests connectivity for redis (PONG should be returned)

func RemoveFile

func RemoveFile(f *models.File) *echo.HTTPError

func RemovePassword

func RemovePassword(p *models.Password) *echo.HTTPError

*

  • Remove a password from the Redis store. If an error occur we return a not found.

func RetrieveFilePassword

func RetrieveFilePassword(f *models.File) *echo.HTTPError

func RetrievePassword

func RetrievePassword(p *models.Password) *echo.HTTPError

func SetFile

func SetFile(password string, ttl, views int, deletable, provided bool, providedKey string) (string, *echo.HTTPError)

*

  • Encrypt and store the password for the specified lifetime.
  • Returns a token comprised of the key where the encrypted password is stored, and the decryption key.
  • @param {string} password
  • @param {number} ttl
  • @param {number} views
  • @param {boolean} deletable
  • @return {string} token

func SetPassword

func SetPassword(password string, ttl, views int, deletable bool) (string, *echo.HTTPError)

*

  • Encrypt and store the password for the specified lifetime.
  • Returns a token comprised of the key where the encrypted password is stored, and the decryption key.
  • @param {string} password
  • @param {number} ttl
  • @param {number} views
  • @param {boolean} deletable
  • @return {string, error} token, error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL