bin/view.js
function getMediaByAPI (uri, cert, mode, user, safe, bufferURI) {
  return new Promise(function (resolve, reject) {
    balance(user).then((ret) => {
      return ret
    }).then(function (ret) {
      if (ret >= algos.getRandomUnseenImage.cost) {
        qpm_media.getRandomUnseenImage().then(function (row) {
          row.conn.close()
          resolve(row.ret[0][0])

          // pay
          var credit = {}
          credit['https://w3id.org/cc#source'] = user
          credit['https://w3id.org/cc#amount'] = algos.getRandomUnseenImage.cost
          credit['https://w3id.org/cc#currency'] = 'https://w3id.org/cc#bit'
          credit['https://w3id.org/cc#destination'] = algos.getRandomUnseenImage.counterparty
          pay(credit)
        }).catch(function (err) {
          row.conn.close()
          reject(err)
        })
      } else {
        reject(new Error('not enough funds'))
      }
    })
  })
}
function getMediaByAPI (uri, cert, mode, user, safe, bufferURI) {
  return new Promise(function (resolve, reject) {
    balance(user).then((ret) => {
      return ret
    }).then(function (ret) {
      if (ret >= algos.getRandomUnseenImage.cost) {
        qpm_media.getRandomUnseenImage().then(function (row) {
          row.conn.close()
          resolve(row.ret[0][0])

          // pay
          var credit = {}
          credit['https://w3id.org/cc#source'] = user
          credit['https://w3id.org/cc#amount'] = algos.getRandomUnseenImage.cost
          credit['https://w3id.org/cc#currency'] = 'https://w3id.org/cc#bit'
          credit['https://w3id.org/cc#destination'] = algos.getRandomUnseenImage.counterparty
          pay(credit)
        }).catch(function (err) {
          row.conn.close()
          reject(err)
        })
      } else {
        reject(new Error('not enough funds'))
      }
    })
  })
}
function getMediaByAPI ( uri , cert , mode , user , safe , bufferURI ) { return new Promise ( function ( resolve , reject ) { balance ( user ) . then ( ( ret ) => { return ret } ) . then ( function ( ret ) { if ( ret >= algos . getRandomUnseenImage . cost ) { qpm_media . getRandomUnseenImage ( ) . then ( function ( row ) { row . conn . close ( ) resolve ( row . ret [ 0 ] [ 0 ] ) // pay var credit = { } credit [ 'https://w3id.org/cc#source' ] = user credit [ 'https://w3id.org/cc#amount' ] = algos . getRandomUnseenImage . cost credit [ 'https://w3id.org/cc#currency' ] = 'https://w3id.org/cc#bit' credit [ 'https://w3id.org/cc#destination' ] = algos . getRandomUnseenImage . counterparty pay ( credit ) } ) . catch ( function ( err ) { row . conn . close ( ) reject ( err ) } ) } else { reject ( new Error ( 'not enough funds' ) ) } } ) } ) }
Get Media item from API
@param  {string} uri       The uri to get it from.
@param  {string} cert      Location of an X.509 cert.
@param  {string} mode      Mode api | http | buffer.
@param  {string} user      The WebID of the user.
@param  {number} safe      Whether safe search is on.
@param  {string} bufferURI The URI of the buffer.
@return {object}           Promise with the row.
Get Media item from API