galldir

package module
v0.0.0-...-7683db2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: GPL-3.0 Imports: 21 Imported by: 0

README

Go Report Card

Galldir galldir

The idea of this project is a photo gallery that is entirely driven from the filesystem - no databases, no image upload interfaces, (almost) no configuration.

Each directory within the filesystem is considered to be an album with all image files within the directory being photos in the album. Albums may be nested.

Each album has a human-readable name that is generated from the name of its directory. This can be overridden by a text file called .title within the directory.

Albums are displayed in date order, most recent first. The date of an album is taken from the modification date of its directory, but this can be overridden by a text file called .date within the directory that contains the album's time in the format YYY-MM-DD hh:mm:ss. This is required when using S3 that does not have directories per se.

Galldir example album

Installation

go get github.com/jamesfcarter/galldir/cmd/galldir

Invocation

galldir requires two arguments: the address to listen on and the directory of pictures to serve:

galldir -addr :3000 -dir ~/pictures

It is also possible to serve pictures from an S3 bucket:

galldir -addr :3000 -dir https://s3.eu-central-1.wasabisys.com/examplebucket

In both cases, browsing to http://localhost:3000/ would reach the gallery.

License

This project is distributed under the GNU GPL license v3, see LICENSE for more information.

Uses lightgallery.js which has its own license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheName

func CacheName(class, path string) string

CacheName generates a unique key for the cache

func IsImage

func IsImage(path string) bool

IsImage takes a path name and returns true if it refers to an image file

func NameFromPath

func NameFromPath(path string) string

NameFromPath tries to generate a human friendly name from a path

func ThumbName

func ThumbName(class string, size int, path string) string

ThumbName generates a unique key for a thumbname in the cache

Types

type Album

type Album struct {
	Path        string
	Name        string
	Description string
	Images      []Image
	Time        time.Time
}

Album specifies a photo album.

func (*Album) Albums

func (a *Album) Albums() []Image

Albums returns a list of images from an album that are sub-albums

func (*Album) Image

func (a *Album) Image(path string) *Image

Image returns an Image from an Album or nil if it cannot be found

func (*Album) Photos

func (a *Album) Photos() []Image

Photos returns a list of images from an album that are not sub-albums

type Image

type Image struct {
	Path        string
	Name        string
	Description string
	Time        time.Time
	IsAlbum     bool
}

Image specifies an image. An image may be the cover of a sub-album.

type ImagesByName

type ImagesByName []Image

ImagesByName implements sort.Interface for []Image to do a case insensitive sort by Name.

func (ImagesByName) Len

func (a ImagesByName) Len() int

func (ImagesByName) Less

func (a ImagesByName) Less(i, j int) bool

func (ImagesByName) Swap

func (a ImagesByName) Swap(i, j int)

type ImagesByTime

type ImagesByTime []Image

ImagesByTime implements sort.Interface for []Image to sort by Time, most recent first.

func (ImagesByTime) Len

func (a ImagesByTime) Len() int

func (ImagesByTime) Less

func (a ImagesByTime) Less(i, j int) bool

func (ImagesByTime) Swap

func (a ImagesByTime) Swap(i, j int)

type Provider

type Provider struct {
	FS    http.FileSystem
	Cache *cache.Cache
	// ImageCacheEntries limits the number of cached full size images.
	// This is done to limit the amount of memory consumed, but also puts
	// an effective limit on the number of images that may be transferred
	// concurrently.
	ImageCacheEntries [cachedImages]struct {
		sync.Mutex
		Name string
	}
}

Provider is used to fetch Albums and Images from a Backend

func NewProvider

func NewProvider(backend http.FileSystem) *Provider

NewProvider returns an initialized Provider

func (*Provider) Album

func (p *Provider) Album(path string, refreshCache bool) (*Album, error)

Album retrieves a (possibly cached) Album from the backend, or returns an error if it is unable to.

func (*Provider) CachedThumb

func (p *Provider) CachedThumb(cacheName string, size int, src io.ReadSeeker) (io.ReadSeeker, error)

CachedThumb returns a (potentially cached) thumbnail of the supplied source image

func (*Provider) CoverThumb

func (p *Provider) CoverThumb(album *Album, size int) (io.ReadSeeker, error)

CoverThumb returns a (potentially cached) thumbnail of the album cover, scaled to the size

func (*Provider) ImageContent

func (p *Provider) ImageContent(path string) (io.ReadSeeker, error)

ImageContent returns an io.ReadSeeker for an image stored in the backend at the given path (that may have been cached). Any attempt to read anything other than an image will result in an error.

func (*Provider) ImageThumb

func (p *Provider) ImageThumb(path string, size int) (io.ReadSeeker, error)

ImageThumb returns a (potentially cached) thumbnail of the image at the given path, scaled to the size.

type Server

type Server struct {
	Provider *Provider
	Assets   http.FileSystem
}

Server implements to http.Handler interface to serve a photo gallery

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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