observe_filestore/2
Resolve managed file storage operations. Records are defined in zotonic_file.hrl.
Type: first.
#filestore{} properties:
action:lookup,exists,upload,delete,delete_status,cancel_delete,purge_previews,cafs_adopt, orcafs_retire.path: path relative to the site's files directory, such asarchive/example.jpg. Deletion and deletion-status requests also accept{prefix, Prefix}.local_path: optional local filename used bylookupto prefer a retained local copy.mime: optional MIME type for upload queue metadata.target_path: canonical CAFS path forcafs_adoptandcafs_retire.older_than: timestamp text used bypurge_previewsas a fixed cutoff.filename: optional filename; the standard filestore handler does not use this field.
Return values depend on the action:
lookup:{ok, {filename, Filename, StoreEntry}}or{ok, {filezcache, Pid, StoreEntry}}.StoreEntryis a map of backend metadata. A cache miss may start a download. Returnundefinedto fall back to local storage or another observer; it does not establish that the remote file is absent.exists: read-only registry check, without network I/O or cache writes. Returntruefor a non-deleted entry without a recorded read error,falseif absent, or{error, Reason}if availability is uncertain. This is not a remote probe.upload:okafter queueing the upload, or{error, Reason}. This does not transfer file bytes. Queue insertion must participate in the caller's transaction.delete:okafter marking matching entries for delayed deletion, or an error. This does not confirm remote absence. Repeated requests must preserve retention.cafs_adopt: register an existing remote original attarget_pathwithout downloading it. Returnokor{error, Reason}. The caller holds the CAFS object lock and the handler must use the caller's transaction. The standard backend retargets the registry entry, retaining its remote URL; the caller must attach the logical filename in that same transaction.cafs_retire: retire the redundant legacypathonly oncetarget_pathis healthy. Schedule normal retained deletion for redundant remote objects. Returnokor{error, Reason}; queued legacy uploads must finish first. Use the caller's transaction.delete_status: request delayed deletion and returnabsentonly when neither remote entries nor queued uploads remain. Returnpendingwhile work remains, or{error, Reason}when unavailable or read-only. Exact paths and prefixes are supported. Repeated requests must preserve retention deadlines.purge_previews: delete a bounded batch of queued resizer uploads and mark remote generated previews for deletion, restricted topreview/and theolder_thancutoff. Never deletearchive/preview/images or medium originals. Returnpendingwhile more batches may remain,okonce remote deletion is queued, or{error, Reason}. Physical deletion follows backend retention. CAFS derivatives are handled separately by their reference-aware collector.cancel_delete:truewhen an undispatched deletion is cancelled or the path is absent;falseonce deletion may be in flight. Locking and cancellation must participate in the caller's transaction. An error is not confirmation of cancellation.
Return undefined for unhandled requests. A missing handler does not confirm
cancellation or remote absence. Backends persist the internal site.filestore_used
marker before accepting files. Core cleanup uses z_file_request:delete_remote/2
to distinguish local-only sites from an unavailable previously used backend.
Use a direct module observer for transaction-sensitive operations; passing work
to a separate process must not lose the caller's transaction or its locks.
See module#mod_filestore and model#cafs for storage and retention behavior.