libraryapi

package
v1.166.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package libraryapi serves a person's library over the portal (#2504, #2509): recents and favorites, and the trash, unused assets and possible duplicates an owner tidies their assets from.

Every route is mounted on the portal's authenticated mux (portal.Deps Mounts) and decides access with the portal's authorization core. Starring or recording an open needs the caller to open the item, and every list of recents or favorites is read under the reach rule, so nothing here names an item the caller cannot open. The trash, unused and duplicates lists are the caller's own rows; an administrator may ask for everyone's.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mount

func Mount(cfg Config) func(*http.ServeMux, *access.Checker)

Mount returns the hook that registers the library routes on the portal's authenticated mux with its authorization core.

Types

type API

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

API serves the library routes.

type Config

type Config struct {
	Library     Library
	Assets      portaldomain.AssetStore
	Collections portaldomain.CollectionStore
	// Purger removes a trash item for good; nil leaves Delete permanently
	// to the retention sweep.
	Purger Purger
	// Retention is how long a deleted item stays in the trash
	// (portal.deleted_retention_days).
	Retention time.Duration
	// Now is the clock the unused cutoff is read from; nil is time.Now.
	Now func() time.Time
}

Config is what the routes read.

type DismissRequest

type DismissRequest struct {
	Digest string `json:"digest" example:"9f2c4e"`
}

DismissRequest names the group to dismiss by its digest.

type DuplicatesResponse

type DuplicatesResponse struct {
	Groups []library.DuplicateGroup `json:"groups"`
}

DuplicatesResponse is the possible-duplicates groups.

type ItemsResponse

type ItemsResponse struct {
	Items []library.Item `json:"items"`
}

ItemsResponse is a list of recents or favorites.

type Library

type Library interface {
	RecordOpen(ctx context.Context, userID string, kind library.Kind, id string) error
	Recents(ctx context.Context, userID string, reach *portaldomain.Reach, limit int) ([]library.Item, error)
	Star(ctx context.Context, userID string, kind library.Kind, id string) error
	Unstar(ctx context.Context, userID string, kind library.Kind, id string) error
	Favorites(ctx context.Context, userID string, reach *portaldomain.Reach, limit int) ([]library.Item, error)
	Trash(ctx context.Context, scope library.Scope, retention time.Duration, limit, offset int) (library.Page[library.TrashItem], error)
	Restore(ctx context.Context, kind library.Kind, id string) error
	Unused(ctx context.Context, scope library.Scope, since time.Time, limit, offset int) (library.Page[library.UnusedItem], error)
	Duplicates(ctx context.Context, userID string, scope library.Scope) ([]library.DuplicateGroup, error)
	Dismiss(ctx context.Context, userID, digest string) error
	Undismiss(ctx context.Context, userID, digest string) error
}

Library is the store the routes read and write.

type OpenRequest

type OpenRequest struct {
	Kind string `json:"kind" example:"asset"`
	ID   string `json:"id" example:"asset_01HK7R8Z8M0Y6A5G1R6FQ2VQNK"`
}

OpenRequest names the item a person opened.

type Purger

type Purger interface {
	PurgeAsset(ctx context.Context, id string) error
	PurgeCollection(ctx context.Context, id string) error
}

Purger removes one deleted item for good (internal/portal/portalpurge).

type TrashResponse

type TrashResponse struct {
	Items []library.TrashItem `json:"items"`
	Total int                 `json:"total"`
	// RetentionDays is how long a deleted item stays before it is purged.
	RetentionDays int `json:"retention_days" example:"30"`
}

TrashResponse is a page of the trash.

type UnusedResponse

type UnusedResponse struct {
	Items []library.UnusedItem `json:"items"`
	Total int                  `json:"total"`
	// Days is the period the page was read for.
	Days int `json:"days" example:"90"`
}

UnusedResponse is a page of unused assets.

Jump to

Keyboard shortcuts

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