MediaServiceV2 Class
Provides functions to interact with media objects. This also includes interacting with the media contents
Constructor
MediaServiceV2
-
context
Parameters:
-
context
Object-
site
String -
onlyThisSite
Boolean -
[provider]
MediaProvider optional
-
Item Index
Methods
- _emit
- _get
- _retrieveOnUpdateAndMerge
- add
- count
- deleteById
- deleteSingle
- extractNextMediaFlag static
- findProviderType static
- formatMedia static
- generateFilename static
- generateMediaPath static
- get
- getAll
- getAllWithCount
- getContentStreamById
- getContentStreamByPath
- getContext
- getIdWhere
- getMediaFlag static
- getMediaIcon static
- getRendererByType static
- getRendererByType static
- getSingle
- getStyleForPosition static
- getStyleForView static
- getSupportedExtensions static
- getType
- isFile static
- isRegistered static
- loadMediaProvider static
- onBeforeSave static
- onFormat static
- onMerge static
- onValidate static
- parseMediaFlag static
- persistContent
- registerRenderer static
- render
- renderById
- renderByLocation
- save
- unregisterRenderer static
- update
- validate
- validateName
- validateTopicReferences
Properties
- dao
- MEDIA_PROVIDERS static
- provider
- REGISTERED_MEDIA_RENDERERS static
- topicService
- TYPE static
- type
Methods
_emit
-
event
-
data
-
cb
Parameters:
-
event
String -
data
Object -
cb
Function
_get
-
id
-
[options]
-
cb
Parameters:
-
id
String -
[options]
Object optional -
cb
Function
_retrieveOnUpdateAndMerge
-
dto
-
options
-
cb
Parameters:
-
dto
Object -
options
Object-
[isCreate]
Boolean optional
-
-
cb
Function
add
-
dto
-
[options]
-
cb
Parameters:
-
dto
Object -
[options]
Object optional -
cb
FunctionA callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query
count
-
[options]
-
cb
Parameters:
-
[options]
Object optional-
[where]
Object optional
-
-
cb
FunctionA callback that takes two parameters. The first is an error, if occurred. The second is the number of results that match the specified query
deleteById
-
id
-
options
-
cb
Parameters:
-
id
String -
options
Object -
cb
Function
deleteSingle
-
[options]
-
cb
Parameters:
-
[options]
Object optionalSee BaseObjectService#getSingle-
[where]
Object optional
-
-
cb
Function
extractNextMediaFlag
-
content
Given a content string the function will search for and extract the first occurrence of a media flag. The parsed value that is returned will include:
- startIndex - The index where the flag was found to start
- endIndex - The position in the content string of the last character of the media flag
- flag - The entire media flag including the start and end markers
- id - The media descriptor id that is referenced by the media flag
- style - A hash of the style properties declared for the flag
- cleanFlag - The media flag stripped of the start and end markers
Parameters:
-
content
StringThe content string that potentially contains 1 or more media flags
Returns:
An object that contains the information about the parsed media flag.
findProviderType
()
MediaProvider
static
Looks up the prototype for the media provider based on the configuration
Returns:
formatMedia
-
media
Sets the proper icon and link for an array of media items
Parameters:
-
media
ArrayThe array of media objects to format
Returns:
The same array of media that was passed in
generateFilename
-
originalFilename
Generates a filename for a new media object
Parameters:
-
originalFilename
String
Returns:
generateMediaPath
-
originalFilename
Generates the path to uploaded media
Parameters:
-
originalFilename
String
Returns:
get
-
id
-
[options]
-
cb
Parameters:
-
id
String -
[options]
Object optional -
cb
Function(Error, object|null) A callback that takes two parameters. The first is an error, if occurred. The second is the object with the specified ID
getAll
-
[options]
-
cb
Parameters:
-
[options]
Object optional-
[select]
Object optional -
[where]
Object optional -
[order]
Array optional -
[limit]
Integer optional -
[offset]
Integer optional
-
-
cb
FunctionA callback that takes two parameters. The first is an error, if occurred. The second is an array representing the results of the query.
getAllWithCount
-
[options]
-
cb
Parameters:
-
[options]
Object optional-
[select]
Object optional -
[where]
Object optional -
[order]
Array optional -
[limit]
Integer optional -
[offset]
Integer optional
-
-
cb
FunctionA callback that takes two parameters. The first is an error, if occurred. The second is an object representing the results of the query.
getContentStreamById
-
id
-
cb
Parameters:
-
id
String -
cb
Function
getContentStreamByPath
-
mediaPath
-
cb
Parameters:
-
mediaPath
String -
cb
Function
getContext
-
[data]
Parameters:
-
[data]
String | Object | Number | Boolean optional
Returns:
getIdWhere
-
dto
Parameters:
-
dto
Object
Returns:
getMediaFlag
-
mid
-
[options]
Generates a media placeholder for templating
Parameters:
-
mid
StringThe media descriptor ID
-
[options]
Object optionalThe list of attributes to be provided to the rendering element.
Returns:
getMediaIcon
-
mediaType
Retrieves the font awesome icon for the media type.
Parameters:
-
mediaType
String
Returns:
getRendererByType
-
mediaUrl
-
[isFile=false]
Retrieves a media renderer for the specified URL
Parameters:
-
mediaUrl
StringThe media URL
-
[isFile=false]
Boolean optionalTRUE if the URL represents an uploaded file, FALSE if not
Returns:
A media renderer interface implementation or NULL if none support the given URL.
getRendererByType
-
type
Retrieves a media renderer for the specified type
Parameters:
-
type
StringThe media type
Returns:
A media renderer interface implementation or NULL if none support the given type.
getSingle
-
[options]
-
cb
Parameters:
-
[options]
Object optional-
[select]
Object optional -
[where]
Object optional -
[order]
Array optional -
[offset]
Integer optional
-
-
cb
FunctionA callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query
getStyleForPosition
-
position
The default editor implementations all for three position values to declared for embedded media (none, left, right, center). These values map to HTML alignments. This function retrieves the HTML style attribute for the provided position.
Parameters:
-
position
StringCan be one of 4 values: none, left, right, center
Returns:
The HTML formatted style attribute(s)
getStyleForView
-
renderer
-
view
-
[overrides]
Retrieves the base style for the given renderer and view. Overrides will be applied on top of the base style.
Parameters:
-
renderer
MediaRendererAn implementation of MediaRenderer
-
view
StringThe view to retrieve the default styling for (view, editor, post)
-
[overrides]
Object optionalA hash of style properties that will be applied to the base style for the given view
getSupportedExtensions
()
Array
static
Provides a mechanism to retrieve all of the supported extension types that can be uploaded into the system.
Returns:
provides an array of strings
getType
()
String
Returns:
isFile
-
mediaUrl
Determines if the media URI is a file. It is determined to be a file if and only if the URI does not begin with "http" or "//".
Parameters:
-
mediaUrl
StringA URI string that points to a media resource
isRegistered
-
interfaceImplementation
Indicates if a media renderer is already registered
Parameters:
-
interfaceImplementation
Function | ObjectA prototype or object that implements the media renderer interface
Returns:
TRUE if registered, FALSE if not
loadMediaProvider
-
context
Parameters:
-
context
Object-
site
String
-
Returns:
An instance of a media provider or NULL when no provider can be loaded.
onBeforeSave
-
context
-
cb
Parameters:
-
context
Object-
data
ObjectThe media descriptor object
-
service
MediaServiceV2
-
-
cb
Function(Error)
onFormat
-
context
-
cb
Parameters:
-
context
Object-
data
ObjectThe incoming request body
-
service
MediaServiceV2An instance of the service that triggered the event that called this handler
-
-
cb
FunctionA callback that takes a single parameter: an error if occurred
onMerge
-
context
-
cb
Parameters:
-
context
Object-
data
ObjectThe incoming request body
-
object
ObjectThe object to be persisted
-
service
MediaServiceV2An instance of the service that triggered the event that called this handler
-
-
cb
FunctionA callback that takes a single parameter: an error if occurred
onValidate
-
context
-
cb
Parameters:
-
context
Object-
data
ObjectThe DTO that was provided for persistence
-
service
MediaServiceV2An instance of the service that triggered the event that called this handler
-
-
cb
FunctionA callback that takes a single parameter: an error if occurred
parseMediaFlag
-
flag
Parses a media flag and returns each part in an object. The parsed value that is returned will include:
- id - The media descriptor id that is referenced by the media flag
- style - A hash of the style properties declared for the flag
- cleanFlag - The media flag stripped of the start and end markers
Parameters:
-
flag
StringThe content string that potentially contains 1 or more media flags
Returns:
An object that contains the information about the parsed media flag.
persistContent
-
context
-
cb
Persists the uploaded media content to the provider
Parameters:
-
context
Object-
data
Object-
content
FileFormidable file descriptor
-
-
-
cb
Function(Error)
registerRenderer
-
interfaceImplementation
Registers a media renderer
Parameters:
-
interfaceImplementation
Function | ObjectA prototype or object that implements the media renderer interface.
Returns:
TRUE if the implementation was registered, FALSE if not
render
-
media
-
options
-
cb
Renders the media represented by the provided media descriptor.
Parameters:
-
media
ObjectThe media resource ID
-
media_type
String
-
-
options
Object-
[attrs]
Object optionalThe desired HTML attributes that will be added to the element that provides the rendering
-
[style]
Object optionalThe desired style overrides for the media
-
[view]
String optionalThe view type that the media will be rendered for (view, editor, post). Any style options provided will override those provided by the default style associated with the view.
-
-
cb
FunctionA callback that provides two parameters. An Error if exists and the rendered HTML content for the media resource.
renderById
-
id
-
options
-
cb
Renders a media resource by ID where ID refers the to the media descriptor id.
Parameters:
-
id
StringThe media resource ID
-
options
Object-
[attrs]
Object optionalThe desired HTML attributes that will be added to the element that provides the rendering
-
[style]
Object optionalThe desired style overrides for the media
-
[view]
String optionalThe view type that the media will be rendered for (view, editor, post). Any style options provided will override those provided by the default style associated with the view.
-
-
cb
FunctionA callback that provides two parameters. An Error if exists and the rendered HTML content for the media resource.
renderByLocation
-
options
-
cb
Renders a resource by type and location (mediaId).
Parameters:
-
options
Object-
location
StringThe unique media identifier for the type
-
[type]
String optionalThe type of provider that knows how to render the resource
-
[attrs]
Object optionalThe desired HTML attributes that will be added to the element that provides the rendering
-
[style]
Object optionalThe desired style overrides for the media
-
[view]
String optionalThe view type that the media will be rendered for (view, editor, post). Any style options provided will override those provided by the default style associated with the view.
-
[isFile=false]
Boolean optional
-
-
cb
FunctionA callback that provides two parameters. An Error if exists and the rendered HTML content for the media resource.
save
-
dto
-
[options]
-
cb
Parameters:
-
dto
Object -
[options]
Object optional-
[isCreate]
Boolean optional
-
-
cb
FunctionA callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query
unregisterRenderer
-
interfaceToUnregister
Unregisters a media renderer
Parameters:
-
interfaceToUnregister
Function | ObjectA prototype or object that implements the media renderer interface
Returns:
TRUE if unregistered, FALSE if not
update
-
dto
-
[options]
-
cb
Parameters:
-
dto
Object -
[options]
Object optional -
cb
FunctionA callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query
validate
-
context
-
cb
Parameters:
-
context
Object-
data
ObjectThe DTO that was provided for persistence
-
service
MediaServiceV2An instance of the service that triggered the event that called this handler
-
-
cb
FunctionA callback that takes a single parameter: an error if occurred
validateName
-
context
-
cb
Parameters:
-
context
Object-
data
Object-
name
String
-
-
validationErrors
Array
-
-
cb
Function(Error)
validateTopicReferences
-
context
-
cb
Validates any references to topic objects in the data object passed through the context.
Parameters:
-
context
Object-
data
Object-
media_topics
Array
-
-
validationErrors
Array
-
-
cb
Function(Error)
Properties
MEDIA_PROVIDERS
Object
private
static
provider
MediaProvider
REGISTERED_MEDIA_RENDERERS
Array
private
static
Contains the list of media renderers