prefetchstore

package
v1.5.1-0...-475df33 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package prefetchstore ports storage.ts: a generic, content-hash-deduped file store. link.go uses it to cache a link preview's thumbnail locally (Config.values.prefetchStorage) rather than showing it as a direct link to the original, unauthenticated remote URL - avoiding leaking every viewer's IP to arbitrary third-party image hosts on each render, and deduping identical thumbnails fetched from different messages/channels down to one file on disk.

Unrelated to internal/uploads (token-authed, expiring, user-uploaded files) despite both living under a data directory - this store has no auth or expiration concept, just content-addressed dedup, and its directory is wiped wholesale on every server start/stop (cmd/relay/ start.go's clearStorageDir, already the Go port of storage.ts's own emptyDir - that part of Node's Storage class was already ported, only store()/dereference() were missing).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store mirrors storage.ts's Storage class.

func New

func New(dir string) *Store

New mirrors `new Storage()`. dir is Config.getStoragePath().

func (*Store) Dereference

func (s *Store) Dereference(url string)

Dereference mirrors Storage.dereference: drop one reference to url (previously returned by Save), deleting the underlying file once nothing references it anymore.

func (*Store) Save

func (s *Store) Save(data []byte, extension string) (string, error)

Save mirrors Storage.store: hash data, and write it under dir/<hash[:2]>/<hash[2:4]>/<hash[4:]>.<extension> unless a file with that exact content (and thus exact hash) is already stored, bumping its reference count either way. Returns the "storage/aa/bb/rest.ext" URL the client is served this content under (relative to the app's own static file serving, matching Node's own url shape).

Jump to

Keyboard shortcuts

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