Module m_media

Model for medium database.

Copyright © 2009-2020 Marc Worrell

Behaviours: zotonic_model.

Authors: Marc Worrell (marc@worrell.nl).

Description

Model for medium database

Data Types

media_url()

media_url() = binary() | string()

Function Index

delete/2Delete the medium at the id.
depiction/2Get the medium record that depicts the resource id.
depicts/2Return the list of resources that is depicted by the medium (excluding the rsc itself).
download_file/1Download a file from a http or data url.
download_file/2
duplicate/3Duplicate the media item from the id to the new-id.
exists/2Check if a medium record exists.
get/2Get the medium record with the id.
get_by_filename/2Fetch a medium by filename.
identify/2Return the identification of a medium.
insert_file/2Make a new resource for the file, when the file is not in the archive dir then a copy is made in the archive dir.
insert_file/3
insert_file/4
insert_medium/4Insert a medium, together with rsc props and an optional preview_url.
insert_url/2Make a new resource for the file based on a URL.
insert_url/3
insert_url/4
is_unique_file/2
m_get/3Fetch the value for the key from a model source.
make_preview_unique/3
merge/3Move a medium between resources, iff the destination doesn't have an associated medium.
mime_to_category/1
replace/3Replace or insert a medium record for the page.
replace_file/3Replaces a medium file, when the file is not in archive then a copy is made in the archive.
replace_file/4
replace_file/5
replace_file/6
replace_medium/5
replace_url/4
replace_url/5
reupload/2Re-upload a file so that identify and previews are regenerated.
save_preview/4Save a preview for a medium record.
save_preview_url/3Save a new file from a preview_url as the preview of a medium.

Function Details

delete/2

delete(Id::m_rsc:resource_id(), Context::z:context()) -> ok | {error, term()}

Delete the medium at the id. The file is queued for later deletion.

depiction/2

depiction(Id::m_rsc:resource_id(), Context::z:context()) -> map() | undefined

Get the medium record that depicts the resource id. "depiction" Predicates are preferred, when they are missing then the attached medium record itself is returned. We must be able to generate a preview from the medium.

depicts/2

depicts(Id::m_rsc:resource_id(), Context::z:context()) -> [m_rsc:resource_id()]

Return the list of resources that is depicted by the medium (excluding the rsc itself)

download_file/1

download_file(Url) -> any()

Download a file from a http or data url.

download_file/2

download_file(Url, Options) -> any()

duplicate/3

duplicate(FromId::m_rsc:resource(), ToId::m_rsc:resource(), Context::z:context()) -> ok | {error, term()}

Duplicate the media item from the id to the new-id. Called by m_rsc:duplicate/3

exists/2

exists(Name::undefined | string() | binary() | integer(), Context::z:context()) -> boolean()

Check if a medium record exists. The argument should be undefined, or a (textual) integer.

get/2

get(Id::m_rsc:resource_id(), Context::z:context()) -> z_media_identify:media_info() | undefined

Get the medium record with the id

get_by_filename/2

get_by_filename(Filename::binary(), Context::z:context()) -> z_media_identify:media_info() | undefined

Fetch a medium by filename

identify/2

identify(Id::m_rsc:resource_id(), Context::z:context()) -> {ok, z_media_identify:media_info()} | {error, term()}

Return the identification of a medium. Used by z_media_identify:identify()

insert_file/2

insert_file(File::file:filename_all() | #upload{}, Context::z:context()) -> {ok, m_rsc:resource_id()} | {error, term()}

Make a new resource for the file, when the file is not in the archive dir then a copy is made in the archive dir

insert_file/3

insert_file(File::file:filename_all() | #upload{}, RscProps::m_rsc:props_all(), Context::z:context()) -> {ok, m_rsc:resource_id()} | {error, term()}

insert_file/4

insert_file(File::file:filename_all() | #upload{}, RscProps::m_rsc:props_all(), Options::list(), Context::z:context()) -> {ok, m_rsc:resource_id()} | {error, term()}

insert_medium/4

insert_medium(Medium, RscProps, Options, Context) -> any()

Insert a medium, together with rsc props and an optional preview_url. This is used for importing media

insert_url/2

insert_url(Url::media_url(), Context::z:context()) -> {ok, pos_integer()} | {error, term()}

Make a new resource for the file based on a URL.

insert_url/3

insert_url(Url::media_url(), RscProps::z_props:props_all(), Context::z:context()) -> {ok, pos_integer()} | {error, term()}

insert_url/4

insert_url(Url::media_url(), RscProps::z_props:props_all(), Options::list(), Context::z:context()) -> {ok, pos_integer()} | {error, term()}

is_unique_file/2

is_unique_file(Filename, Context) -> any()

m_get/3

m_get(Rest::list(), Msg::zotonic_model:opt_msg(), Context::z:context()) -> zotonic_model:return()

Fetch the value for the key from a model source

make_preview_unique/3

make_preview_unique(RscId::integer() | insert_rsc, Extension::binary(), Context::z:context()) -> file:filename()

merge/3

merge(WinnerId, LoserId, Context) -> any()

Move a medium between resources, iff the destination doesn't have an associated medium. This is called when merging two resources (and the FromId is subsequently deleted).

mime_to_category/1

mime_to_category(Mime::string() | binary()) -> image | video | audio | document

replace/3

replace(Id::m_rsc:resource_id(), Props::map(), Context::z:context()) -> ok | {error, term()}

Replace or insert a medium record for the page. This is useful for non-file related media. Resets all non mentioned attributes.

replace_file/3

replace_file(File, RscId, Context) -> any()

Replaces a medium file, when the file is not in archive then a copy is made in the archive. When the resource is in the media category, then the category is adapted depending on the mime type of the uploaded file.

replace_file/4

replace_file(File, RscId, RscProps, Context) -> any()

replace_file/5

replace_file(File, RscId, RscProps, Opts, Context) -> any()

replace_file/6

replace_file(File, RscId, RscProps, MediaInfo, Opts, Context) -> any()

replace_medium/5

replace_medium(Medium, RscId, RscProps, Options, Context) -> any()

replace_url/4

replace_url(Url, RscId, RscProps, Context) -> any()

replace_url/5

replace_url(Url, RscId, RscProps, Options, Context) -> any()

reupload/2

reupload(Id::m_rsc:resource_id(), Context::z:context()) -> {ok, m_rsc:resource_id()} | {error, term()}

Re-upload a file so that identify and previews are regenerated.

save_preview/4

save_preview(RscId::m_rsc:resource_id(), Data::iodata(), Mime::binary() | string(), Context::z:context()) -> {ok, file:filename_all()} | {error, eacces | term()}

Save a preview for a medium record. The data is saved to a file in the archive directory.

save_preview_url/3

save_preview_url(RscId, Url, Context) -> any()

Save a new file from a preview_url as the preview of a medium


Generated by EDoc