Module: @bldr/media-server

@bldr/media-server

The REST API and command line interface of the BALDR media server.

Media types:

  • presentation (Presentation())
  • asset (Asset())
    • multipart asset (filename.jpg, filename_no02.jpg, filename_no03.jpg)

Definition of the objects:

A presentation is a YAML file for the BALDR presentation app. It must have the file name scheme *.baldr.yml. The media server stores the whole YAML file in the MongoDB database.

A asset is a media file which has a meta data file in the YAML format. The file name scheme for this meta data file is media-file.jpg.yml. The suffix .yml has to be appended. Only the content of the meta data file is stored into the database.

REST API

  • get
    • folder-title-tree: Get the folder title tree as a hierarchical json object.
  • mgmt
    • flush: Delete all media files (assets, presentations) from the database.
    • init: Initialize the MongoDB database
    • open: Open a media file specified by an ID. This query parameters are available:
      • id: The ID of the media file (required).
      • type: presentations, assets. The default value is presentations.
      • with: editor specified in config.mediaServer.editor (/etc/baldr.json) or folder to open the parent folder of the given media file. The default value is editor
      • archive: True if present, false by default. Open the file or the folder in the corresponding archive folder structure.
      • create: True if present, false by default. Create the possibly non existing directory structure in a recursive manner.
    • re-init: Re-Initialize the MongoDB database (Drop all collections and initialize)
    • update: Update the media server database (Flush and insert).
    • query: Getting results by using query parameters. This query parameters are available:
      • type: assets (default), presentations (what)
      • method: exactMatch, substringSearch (default) (how).
        • exactMatch: The query parameter search must be a perfect match to a top level database field to get a result.
        • substringSearch: The query parameter search is only a substring of the string to search in.
      • field: id (default), title, etc ... (where).
      • search: Some text to search for (search for).
      • result: fullObjects (default), dynamicSelect
  • stats:
    • count: Count / sum of the media files (assets, presentations) in the database.
    • updates: Journal of the update processes with timestamps.

Classes

Asset
FolderTitle
FolderTitleTree
HierarchicalFolderTitles
LocationIndicator
MediaFile
Presentation

Members

basePath innerconstant

Base path of the media server file store.

config innerconstant

The configuration object from /etc/baldr.json

db mongodb~Db inner

The MongoDB Db instance

errors inner

A container array for all error messages send out via the REST API.

helpMessages Object innerconstant

This object hold jsons for displaying help messages in the browser on some entry point urls.

Update docs on the top of this file in the JSDoc block.

mongoClient innerconstant

Methods

connectDb ()Promise asyncinner

Returns:
Type Description
Promise

dropDb ()Promise asyncinner

Returns:
Type Description
Promise

flushMediaFiles ()Promise asyncinner

Returns:
Type Description
Promise

getAbsPathFromId (id, mediaType)String asyncinner

Resolve a ID from a given media type (assets, presentations) to a absolute path.

Name Type Default Description
id String

The id of the media type.

mediaType String presentations

At the moment assets and presentation

Returns:
Type Description
String

getExtension (filePath)String inner

Get the extension from a file path.

Name Type Description
filePath String
Returns:
Type Description
String

initializeDb ()Promise asyncinner

Returns:
Type Description
Promise

insertObjectIntoDb (filePath) asyncinner

Name Type Description
filePath String

isAsset (fileName) inner

Check if the given file is a media asset.

Name Type Description
fileName String

isPresentation (fileName) inner

Check if the given file is a presentation.

Name Type Description
fileName String

mirrorFolderStructure (currentPath)Object inner

Mirror the folder structure of the media folder into the archive folder or vice versa. Only folders with two prefixed numbers followed by an underscore (for example “10_”) are mirrored.

Name Type Description
currentPath String

Must be a relative path within one of the folder structures.

Returns:
Type Description
Object
  • Status informations of the action.

openEditor (id, mediaType)Object asyncinner

Open a media file specified by an ID with an editor specified in config.mediaServer.editor (/etc/baldr.json).

Name Type Description
id String

The id of the media type.

mediaType String

At the moment assets and presentation

Returns:
Type Description
Object

openFolder (currentPath, create) inner

Open a file path using the linux command xdg-open.

Name Type Description
currentPath String
create Boolean

Create the directory structure of the given currentPath in a recursive manner.

openFolderWithArchives (currentPath, create) inner

Open the current path multiple times.

  1. In the main media server directory
  2. In a archive directory structure.
  3. In a second archive directory structure ... and so on.
Name Type Description
currentPath String
create Boolean

Create the directory structure of the given currentPath in a recursive manner.

openParentFolder (id, mediaType, archive, create)Object asyncinner

Open the parent folder of a presentation, a media asset in a file explorer GUI application.

Name Type Description
id String

The id of the media type.

mediaType String

At the moment assets and presentation

archive Boolean

Addtionaly open the corresponding archive folder.

create Boolean

Create the directory structure of the relative path in the archive in a recursive manner.

Returns:
Type Description
Object

openWith () inner

Open a file path with an executable.

To launch apps via the REST API the systemd unit file must run as the user you login in in your desktop environment. You also have to set to environment variables: DISPLAY=:0 and DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/bus

Environment=DISPLAY=:0
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
User=1000
Group=1000
See:

registerRestApi () inner

Register the express js rest api in a giant function.

reInitializeDb ()Promise asyncinner

Returns:
Type Description
Promise

setupMongoUrl () inner

stripTags (text)String inner

Strip HTML tags from a string.

Name Type Description
text String

A text containing HTML tags.

Returns:
Type Description
String

untildify (filePath) inner

Name Type Description
filePath String
See:

update ()Object asyncinner

Update the media server.

Returns:
Type Description
Object

validateMediaType (mediaType)String inner

Throw an error if the media type is unkown. Provide a default value.

Name Type Description
mediaType String

At the moment assets and presentation

Returns:
Type Description
String

walk (func, opt) asyncinner

Execute a function on one file or walk trough all files matching a regex in the current working directory or in the given directory path.

Name Type Description
func function | Object

A single function or an object containing functions. Properties:

  • presentation: This function is called on each presentation.
  • asset: This function is called on each asset.
  • all (presentation, asset): This function is called on all media types, at the moment on presentations and assets.
  • everyFileThis function is called on every file.
opt Object
Properties:
Name Type Description
opt.payload Object

The function/s is/are called with with this object. Multiple arguments have to be bundled as a single object.

opt.path Array | String

An array of paths of a directory or paths of a file. A single path of a directory or a single path of a file. If this property is not set, the current working directory is used.

opt.regex String | Regex

If this property is set, func have to be an single function. Each resolved file path must match this regular expression to execute the function. If you specified a string, this string is converted into the regexp *.ext.