z_media_archive (zotonic_core v1.0.0-rc.17)

Media archiving utilities. Manages the files/archive directory of sites.

Summary

Functions

Return the absolute path of a file in the archive. The given filename must be relative to the archive directory.

Always archive a copy of a file in the archive directory.

Always archive a copy of a file in the archive directory.

Always archive a copy of a file in the archive directory.

Optionally archive a copy of a file in the archive directory (when it is not archived yet)

Optionally archive a copy of a file in the archive directory (when it is not archived yet).

Delete a filename in the archive. The Filename is relative to the base archive directory.

Move a file to the archive directory (when it is not archived yet)

Move a file to the archive directory (when it is not archived yet)

Return an unique filename for archiving the file. Used when storing a new file after upload.

Ensure that the filename is relative to the archive. If needed then move the file to the archive. Return the path of the original or moved file relative to the archive.

Ensure that the file is in the archive, when not then generate a new filename and move the file to the archive. If the file is already in the archive, then do nothing. Return the filename relative to the archive directory.

Check if the file is in the archive directory.

Return an unique filename for archiving a preview of a file. Used for storing a new file after preview generation.

Remove the path to the archive directory, return a filename relative to the archive directory Crash if the path is not referring to the archive directory.

Functions

abspath(File, Context)

-spec abspath(File, Context) -> file:filename_all()
                 when File :: file:filename_all(), Context :: z:context().

Return the absolute path of a file in the archive. The given filename must be relative to the archive directory.

archive_copy(Filename, Context)

-spec archive_copy(Filename, Context) -> ArchivedFilename
                      when
                          Filename :: file:filename_all(),
                          Context :: z:context(),
                          ArchivedFilename :: binary().

Always archive a copy of a file in the archive directory.

archive_copy(Filename, NewBasename, Context)

-spec archive_copy(Filename, NewBasename, Context) -> ArchivedFilename
                      when
                          Filename :: file:filename_all(),
                          NewBasename :: string() | binary(),
                          Context :: z:context(),
                          ArchivedFilename :: binary().

Always archive a copy of a file in the archive directory.

archive_copy(Type, Filename, NewBasename, Context)

-spec archive_copy(Type, Filename, NewBasename, Context) -> ArchivedFilename
                      when
                          Type :: archive | preview,
                          Filename :: file:filename_all(),
                          NewBasename :: string() | binary(),
                          Context :: z:context(),
                          ArchivedFilename :: binary().

Always archive a copy of a file in the archive directory.

archive_copy_opt(Filename, Context)

-spec archive_copy_opt(Filename, Context) -> ArchivedFilename
                          when
                              Filename :: file:filename_all(),
                              Context :: z:context(),
                              ArchivedFilename :: binary().

Optionally archive a copy of a file in the archive directory (when it is not archived yet)

archive_copy_opt(Filename, NewBasename, Context)

-spec archive_copy_opt(Filename, NewBasename, Context) -> ArchivedFilename
                          when
                              Filename :: file:filename_all(),
                              NewBasename :: string() | binary(),
                              Context :: z:context(),
                              ArchivedFilename :: binary().

Optionally archive a copy of a file in the archive directory (when it is not archived yet).

archive_delete(Filename, Context)

-spec archive_delete(Filename, Context) -> ok | {error, Reason}
                        when
                            Filename :: file:filename_all(),
                            Context :: z:context(),
                            Reason :: file:posix() | badarg.

Delete a filename in the archive. The Filename is relative to the base archive directory.

archive_file(Filename, Context)

-spec archive_file(Filename, Context) -> ArchivedFilename
                      when
                          Filename :: file:filename_all(),
                          Context :: z:context(),
                          ArchivedFilename :: binary().

Move a file to the archive directory (when it is not archived yet)

archive_file(Filename, NewBasename, Context)

-spec archive_file(Filename, NewBasename, Context) -> ArchivedFilename
                      when
                          Filename :: file:filename_all(),
                          NewBasename :: string() | binary(),
                          Context :: z:context(),
                          ArchivedFilename :: binary().

Move a file to the archive directory (when it is not archived yet)

archive_filename(Filename, Context)

-spec archive_filename(Filename, Context) -> UniqueArchiveFilename
                          when
                              Filename :: file:filename_all(),
                              UniqueArchiveFilename :: binary(),
                              Context :: z:context().

Return an unique filename for archiving the file. Used when storing a new file after upload.

ensure_relative(File, Context)

-spec ensure_relative(File, Context) -> file:filename_all()
                         when File :: file:filename_all(), Context :: z:context().

Ensure that the filename is relative to the archive. If needed then move the file to the archive. Return the path of the original or moved file relative to the archive.

ensure_relative(File, NewBasenameIfMoved, Context)

-spec ensure_relative(File, NewBasenameIfMoved, Context) -> RelativeFile
                         when
                             File :: file:filename_all(),
                             NewBasenameIfMoved :: string() | binary(),
                             Context :: z:context(),
                             RelativeFile :: binary().

Ensure that the file is in the archive, when not then generate a new filename and move the file to the archive. If the file is already in the archive, then do nothing. Return the filename relative to the archive directory.

is_archived(Filename, Context)

-spec is_archived(Filename, Context) -> boolean()
                     when Filename :: file:filename_all() | undefined, Context :: z:context().

Check if the file is in the archive directory.

preview_filename(Filename, Context)

-spec preview_filename(Filename, Context) -> UniqueArchiveFilename
                          when
                              Filename :: file:filename_all(),
                              Context :: z:context(),
                              UniqueArchiveFilename :: binary().

Return an unique filename for archiving a preview of a file. Used for storing a new file after preview generation.

rel_archive(Filename, Context)

Remove the path to the archive directory, return a filename relative to the archive directory Crash if the path is not referring to the archive directory.

safe_filename(B)