lib/qpm_media.js
function addMedia(uri, contentType, safe) {
  if (!uri || uri === '') {
    return 'You must enter a valid uri'
  }
  safe = safe || 0
  return new Promise((resolve, reject) => {

    var config = require('../config/config.js')
    var conn = wc_db.getConnection(config.db)

    // sniff content type
    if (!contentType) {
      // image
      if (uri.indexOf('.jpg') !== -1) {
        contentType = 'image'
      }
      if (uri.indexOf('.png') !== -1) {
        contentType = 'image'
      }
      if (uri.indexOf('.gif') !== -1) {
        contentType = 'image'
      }
      if (uri.indexOf('.svg') !== -1) {
        contentType = 'image'
      }
      // video
      if (uri.indexOf('.mp4') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.mpg') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.mov') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.wmv') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.avi') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.m4v') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.mkv') !== -1) {
        contentType = 'video'
      }
      // audio
      if (uri.indexOf('.mp3') !== -1) {
        contentType = 'audio'
      }
      if (uri.indexOf('.ogg') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.flv') !== -1) {
        contentType = 'video'
      }
    }

    var sql = 'INSERT into Media values (NULL, :uri, NULL, NULL, NULL, :contentType, ' + safe + ')'

    conn.query(sql, { replacements: { "uri" : uri, "contentType" : contentType } }).then(function(ret){
      return resolve({"ret" : ret, "conn" : conn})
    }).catch(function(err) {
      return reject(err)
    })

  })

}
function addMedia(uri, contentType, safe) {
  if (!uri || uri === '') {
    return 'You must enter a valid uri'
  }
  safe = safe || 0
  return new Promise((resolve, reject) => {

    var config = require('../config/config.js')
    var conn = wc_db.getConnection(config.db)

    // sniff content type
    if (!contentType) {
      // image
      if (uri.indexOf('.jpg') !== -1) {
        contentType = 'image'
      }
      if (uri.indexOf('.png') !== -1) {
        contentType = 'image'
      }
      if (uri.indexOf('.gif') !== -1) {
        contentType = 'image'
      }
      if (uri.indexOf('.svg') !== -1) {
        contentType = 'image'
      }
      // video
      if (uri.indexOf('.mp4') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.mpg') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.mov') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.wmv') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.avi') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.m4v') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.mkv') !== -1) {
        contentType = 'video'
      }
      // audio
      if (uri.indexOf('.mp3') !== -1) {
        contentType = 'audio'
      }
      if (uri.indexOf('.ogg') !== -1) {
        contentType = 'video'
      }
      if (uri.indexOf('.flv') !== -1) {
        contentType = 'video'
      }
    }

    var sql = 'INSERT into Media values (NULL, :uri, NULL, NULL, NULL, :contentType, ' + safe + ')'

    conn.query(sql, { replacements: { "uri" : uri, "contentType" : contentType } }).then(function(ret){
      return resolve({"ret" : ret, "conn" : conn})
    }).catch(function(err) {
      return reject(err)
    })

  })

}
function addMedia ( uri , contentType , safe ) { if ( ! uri || uri === '' ) { return 'You must enter a valid uri' } safe = safe || 0 return new Promise ( ( resolve , reject ) => { var config = require ( '../config/config.js' ) var conn = wc_db . getConnection ( config . db ) // sniff content type if ( ! contentType ) { // image if ( uri . indexOf ( '.jpg' ) !== - 1 ) { contentType = 'image' } if ( uri . indexOf ( '.png' ) !== - 1 ) { contentType = 'image' } if ( uri . indexOf ( '.gif' ) !== - 1 ) { contentType = 'image' } if ( uri . indexOf ( '.svg' ) !== - 1 ) { contentType = 'image' } // video if ( uri . indexOf ( '.mp4' ) !== - 1 ) { contentType = 'video' } if ( uri . indexOf ( '.mpg' ) !== - 1 ) { contentType = 'video' } if ( uri . indexOf ( '.mov' ) !== - 1 ) { contentType = 'video' } if ( uri . indexOf ( '.wmv' ) !== - 1 ) { contentType = 'video' } if ( uri . indexOf ( '.avi' ) !== - 1 ) { contentType = 'video' } if ( uri . indexOf ( '.m4v' ) !== - 1 ) { contentType = 'video' } if ( uri . indexOf ( '.mkv' ) !== - 1 ) { contentType = 'video' } // audio if ( uri . indexOf ( '.mp3' ) !== - 1 ) { contentType = 'audio' } if ( uri . indexOf ( '.ogg' ) !== - 1 ) { contentType = 'video' } if ( uri . indexOf ( '.flv' ) !== - 1 ) { contentType = 'video' } } var sql = 'INSERT into Media values (NULL, :uri, NULL, NULL, NULL, :contentType, ' + safe + ')' conn . query ( sql , { replacements : { "uri" : uri , "contentType" : contentType } } ) . then ( function ( ret ) { return resolve ( { "ret" : ret , "conn" : conn } ) } ) . catch ( function ( err ) { return reject ( err ) } ) } ) }
Adds media to the database
@param {string} uri         The URI to add.
@param {string} contentType The content type.
@param {Object} callback    The callback.
Adds media to the database