utils

package
v0.0.0-...-86fb063 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MediaFormatBase = 1000 // base used for comparisons

	MediaFormatImage           = 1000 // image base code
	MediaFormatDetailImageJpeg = 1001 // jpeg
	MediaFormatDetailImagePng  = 1002 // png
	MediaFormatDetailImageHeic = 1003 // heic

	MediaFormatAudio          = 2000 // audio base code
	MediaFormatDetailAudioMp3 = 2001 // mp3
	MediaFormatDetailAudioMp4 = 2002 // audio only mp4
	MediaFormatDetailAudioAac = 2003 // audio only aac
	MediaFormatDetailAudioOgg = 2004 // audio only ogg

	MediaFormatVideo          = 3000 // video base code
	MediaFormatDetailVideoMp4 = 3001 // mp4
	MediaFormatDetailVideoMov = 3002 // mov

	Thumb_p100  = "p100"
	Thumb_p1080 = "p1080"
	Size_Actual = "actual"
)
View Source
const ThumbnailSuffixDelim = "_"

Variables

This section is empty.

Functions

func AddFileToTarWriter

func AddFileToTarWriter(pathOnDisk string, pathInTar string, tarWriter *tar.Writer) error

AddFileToTarWriter adds a file to a tar file

func AddSuffixToBasename

func AddSuffixToBasename(fullpath string, suffix string) string

AddSuffixToBasename adds suffix to base of filename, for example filename.jpg to filename_t1.jpg

func ChangeSuffix

func ChangeSuffix(filename string, newSuffix string) string

ChangeSuffix changes the suffix of filename from .from to .to

func ConvertHeicJpg

func ConvertHeicJpg(inputPath string) error

ConvertHeicJpg converts an heic file to jpeg in place by using temp folder to create new file then copies to original convert -format jpg input.heic output.jpg

func ConvertM4aMp4

func ConvertM4aMp4(inputPath string) error

ConvertM4aMp4 converts an m4a file to mp4 in place by using temp folder to create new file then copies to original ffmpeg -y -i input.m4a -c:a copy output.mp4

func CopyDir

func CopyDir(source, destination string) error

CopyDir is a recursive file copy

func CopyFile

func CopyFile(src, dst string) (int64, error)

CopyFile copies a file from src to dest full path

func CreateAltSizes

func CreateAltSizes(mediaPath string, altName string) (imagePathsThumbs []string, altNameThumbs []string, err error)

CreateAltSizes creates thumbnails of mediaPath, saves thumbnails, and returns paths and names of uploaded images. Thumbnail size is set to max of width or height. mediaPath is the path to the file, altName is an alternate name that gets thumbnail suffixes added to it

func CreateThumbnailsInFolder

func CreateThumbnailsInFolder(mediaPath string) error

CreateThumbnailsInFolder creates thumbnails for all images in the folder. The thumbnails appear next to the images with _p1080 basename suffix, like this a.jpg => a_p1080.jpg

func DeleteFile

func DeleteFile(path string) error

DeleteFile deletes a file

func ExpandTarFile

func ExpandTarFile(tarFilePath string, expandDirPath string) error

ExpandTarFile expands a tar file tarFilePath to expandDirPath

func ExpandTarReader

func ExpandTarReader(r io.Reader, expandDirPath string) error

ExpandTarReader expands a tar stream to expandDirPath

func GenerateBase64Rand

func GenerateBase64Rand() string

GenerateBase64Rand generates a base64 random string

func GenerateCid

func GenerateCid() (string, error)

Generate ipfs style cid

func GenerateRandomNumber

func GenerateRandomNumber() int

GenerateRandomNumber generates a random number

func GeoBoundingBox

func GeoBoundingBox(lat float64, lon float64, d float64) (lat1 float64, lon1 float64, lat2 float64, lon2 float64)

GeoBoundingBox returns bounding box given center point and range d in kilometers This is an estimate since uses the hypotenuse at NW and SE

func GeoDistance

func GeoDistance(lat1 float64, lon1 float64, lat2 float64, lon2 float64) float64

GeoDistance returns the greater circle distance in kilometers between two points

func GetFileContentType

func GetFileContentType(out *os.File) (string, error)

GetFileContentType detects the content type of a file

func GetMediaFormatAndMetadata

func GetMediaFormatAndMetadata(path string, suffix string) (mediaFormat int, mediaFormatDetail int, metadata map[string]string, err error)

GetMediaFormatAndMetadata returns media format (image, audio, video), detail (jpeg, png, etc.) and metadata map for a media file

func GetMediaSuffix

func GetMediaSuffix(path string) (suffix string)

GetMediaSuffix returns the suffix of a file name

func GetThumbnailName

func GetThumbnailName(imageName string, format string) string

GetThumbnailName returns thumbnail name given image name and format. Format could be p100, p1080, etc.

func InitMediaStorage

func InitMediaStorage()

InitMediaStorage initializes media storage

Types

type IPFS_Driver

type IPFS_Driver struct {
	// contains filtered or unexported fields
}

IPFS_Driver struct manages IPFS

var Ipfs IPFS_Driver

func (*IPFS_Driver) DownloadDirectory

func (i *IPFS_Driver) DownloadDirectory(localDirPath string, cid string) error

DownloadDirectory downloads all the files in a folder identified by CID

func (*IPFS_Driver) Init

func (i *IPFS_Driver) Init() error

Init initializes IPFS shell

func (*IPFS_Driver) UploadDirectory

func (i *IPFS_Driver) UploadDirectory(localDirPath string) (cid string, err error)

UploadDirectory uploads all the files in a folder. Files are stored in IPFS in directory prefixPath.

func (*IPFS_Driver) UploadFile

func (i *IPFS_Driver) UploadFile(localPath string, relPath string) (cid string, err error)

UploadFile loads a file to IPFS with relPath relative path. Files are stored in IPFS in directory prefixPath.

func (*IPFS_Driver) UploadString

func (i *IPFS_Driver) UploadString(body string, relPath string) (cid string, err error)

Upload loads a string with relPath relative path. Files are stored in IPFS in directory prefixPath.

type S3_1Driver

type S3_1Driver struct {
	// contains filtered or unexported fields
}

S3_1Driver struct manages S3 uploads and URL generation

var S3 S3_1Driver

func (*S3_1Driver) CreateFolderNameBase64

func (s *S3_1Driver) CreateFolderNameBase64(text string) string

CreateFolderNameBase64 creates folder name from a string. Creates an base64 HMAC given the string. Sanitizes by removing all non-alphanumerics

func (*S3_1Driver) Download

func (s *S3_1Driver) Download(localPath string, key string) error

Download loads a file FROM S3

func (*S3_1Driver) DownloadDirectory

func (s *S3_1Driver) DownloadDirectory(localDirPath string, cid string) error

DownloadDirectory downloads all the files in a folder

func (*S3_1Driver) GetExpiringURL

func (s *S3_1Driver) GetExpiringURL(key string) (string, http.Header, error)

GetExpiringURL gets a URL to s3 asset that expires, given folder and filename for config set bucket name

func (*S3_1Driver) Init

func (s *S3_1Driver) Init() error

Init initializes AWS S3 stuff

func (*S3_1Driver) Upload

func (s *S3_1Driver) Upload(localPath string, key string) error

Upload loads a file TO S3

func (*S3_1Driver) UploadDirectory

func (s *S3_1Driver) UploadDirectory(localDirPath string, cid string) error

UploadDirectory uploads all the files in a folder

func (*S3_1Driver) UploadString

func (s *S3_1Driver) UploadString(body string, contentType string, folder string, key string) error

Upload loads a string TO S3, must specify mimeType (contentType)

type ThumbnailSizeSuffix

type ThumbnailSizeSuffix struct {
	MaxSize int
	Suffix  string
}

Jump to

Keyboard shortcuts

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