MediaServiceV2 Class
Provides functions to interact with media objects. This also includes interacting with the media contents
Constructor
MediaServiceV2
-
context
Parameters:
-
contextObject-
siteString -
onlyThisSiteBoolean -
[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:
-
eventString -
dataObject -
cbFunction
_get
-
id -
[options] -
cb
Parameters:
-
idString -
[options]Object optional -
cbFunction
_retrieveOnUpdateAndMerge
-
dto -
options -
cb
Parameters:
-
dtoObject -
optionsObject-
[isCreate]Boolean optional
-
-
cbFunction
add
-
dto -
[options] -
cb
Parameters:
-
dtoObject -
[options]Object optional -
cbFunctionA 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
-
-
cbFunctionA 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:
-
idString -
optionsObject -
cbFunction
deleteSingle
-
[options] -
cb
Parameters:
-
[options]Object optionalSee BaseObjectService#getSingle-
[where]Object optional
-
-
cbFunction
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:
-
contentStringThe 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:
-
mediaArrayThe 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:
-
originalFilenameString
Returns:
generateMediaPath
-
originalFilename
Generates the path to uploaded media
Parameters:
-
originalFilenameString
Returns:
get
-
id -
[options] -
cb
Parameters:
-
idString -
[options]Object optional -
cbFunction(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
-
-
cbFunctionA 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
-
-
cbFunctionA 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:
-
idString -
cbFunction
getContentStreamByPath
-
mediaPath -
cb
Parameters:
-
mediaPathString -
cbFunction
getContext
-
[data]
Parameters:
-
[data]String | Object | Number | Boolean optional
Returns:
getIdWhere
-
dto
Parameters:
-
dtoObject
Returns:
getMediaFlag
-
mid -
[options]
Generates a media placeholder for templating
Parameters:
-
midStringThe 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:
-
mediaTypeString
Returns:
getRendererByType
-
mediaUrl -
[isFile=false]
Retrieves a media renderer for the specified URL
Parameters:
-
mediaUrlStringThe 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:
-
typeStringThe 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
-
-
cbFunctionA 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:
-
positionStringCan 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:
-
rendererMediaRendererAn implementation of MediaRenderer
-
viewStringThe 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:
-
mediaUrlStringA URI string that points to a media resource
isRegistered
-
interfaceImplementation
Indicates if a media renderer is already registered
Parameters:
-
interfaceImplementationFunction | ObjectA prototype or object that implements the media renderer interface
Returns:
TRUE if registered, FALSE if not
loadMediaProvider
-
context
Parameters:
-
contextObject-
siteString
-
Returns:
An instance of a media provider or NULL when no provider can be loaded.
onBeforeSave
-
context -
cb
Parameters:
-
contextObject-
dataObjectThe media descriptor object
-
serviceMediaServiceV2
-
-
cbFunction(Error)
onFormat
-
context -
cb
Parameters:
-
contextObject-
dataObjectThe incoming request body
-
serviceMediaServiceV2An instance of the service that triggered the event that called this handler
-
-
cbFunctionA callback that takes a single parameter: an error if occurred
onMerge
-
context -
cb
Parameters:
-
contextObject-
dataObjectThe incoming request body
-
objectObjectThe object to be persisted
-
serviceMediaServiceV2An instance of the service that triggered the event that called this handler
-
-
cbFunctionA callback that takes a single parameter: an error if occurred
onValidate
-
context -
cb
Parameters:
-
contextObject-
dataObjectThe DTO that was provided for persistence
-
serviceMediaServiceV2An instance of the service that triggered the event that called this handler
-
-
cbFunctionA 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:
-
flagStringThe 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:
-
contextObject-
dataObject-
contentFileFormidable file descriptor
-
-
-
cbFunction(Error)
registerRenderer
-
interfaceImplementation
Registers a media renderer
Parameters:
-
interfaceImplementationFunction | 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:
-
mediaObjectThe media resource ID
-
media_typeString
-
-
optionsObject-
[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.
-
-
cbFunctionA 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:
-
idStringThe media resource ID
-
optionsObject-
[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.
-
-
cbFunctionA 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:
-
optionsObject-
locationStringThe 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
-
-
cbFunctionA callback that provides two parameters. An Error if exists and the rendered HTML content for the media resource.
save
-
dto -
[options] -
cb
Parameters:
-
dtoObject -
[options]Object optional-
[isCreate]Boolean optional
-
-
cbFunctionA 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:
-
interfaceToUnregisterFunction | ObjectA prototype or object that implements the media renderer interface
Returns:
TRUE if unregistered, FALSE if not
update
-
dto -
[options] -
cb
Parameters:
-
dtoObject -
[options]Object optional -
cbFunctionA 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:
-
contextObject-
dataObjectThe DTO that was provided for persistence
-
serviceMediaServiceV2An instance of the service that triggered the event that called this handler
-
-
cbFunctionA callback that takes a single parameter: an error if occurred
validateName
-
context -
cb
Parameters:
-
contextObject-
dataObject-
nameString
-
-
validationErrorsArray
-
-
cbFunction(Error)
validateTopicReferences
-
context -
cb
Validates any references to topic objects in the data object passed through the context.
Parameters:
-
contextObject-
dataObject-
media_topicsArray
-
-
validationErrorsArray
-
-
cbFunction(Error)
Properties
MEDIA_PROVIDERS
Object
private
static
provider
MediaProvider
REGISTERED_MEDIA_RENDERERS
Array
private
static
Contains the list of media renderers
