bin/view.js
function addMediaToBuffer (uri, cert, mode, user, safe, bufferURI) {
  // var bufferPath = root
  // if (bufferURI) {
  //  bufferPath += '/../' + url.parse(bufferURI).path
  // }

  setTimeout(() => {
    try {
      // fs.unlinkSync(lastFile)
    } catch (e) {
      console.error(e)
    }
    var params = {}
    params.reviewer = user
    if (safe && safe === 'off') {
      params.safe = 0
    } else {
      params.safe = 1
    }
    algos.getRandomUnseenImage.function(params).then(function (row) {
      debug('unseen', row.ret)
      var cacheURI = row.ret[0][0].cacheURI
      var filePath = cacheURI.substr('file://'.length)
      debug('copying', filePath)

      // copyMedia(filePath, bufferPath + urlencode(cacheURI), function (err) {
      copyMedia(filePath, bufferURI + urlencode(cacheURI), cert, function (err) {
        if (err) {
          debug(err)
        } else {
          console.log('success!')
          // 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
          debug(credit)
          pay(credit)

          if (row && row.conn) {
            row.conn.close()
          }
        }
      })
    })
  }, 500)
}
function addMediaToBuffer (uri, cert, mode, user, safe, bufferURI) {
  // var bufferPath = root
  // if (bufferURI) {
  //  bufferPath += '/../' + url.parse(bufferURI).path
  // }

  setTimeout(() => {
    try {
      // fs.unlinkSync(lastFile)
    } catch (e) {
      console.error(e)
    }
    var params = {}
    params.reviewer = user
    if (safe && safe === 'off') {
      params.safe = 0
    } else {
      params.safe = 1
    }
    algos.getRandomUnseenImage.function(params).then(function (row) {
      debug('unseen', row.ret)
      var cacheURI = row.ret[0][0].cacheURI
      var filePath = cacheURI.substr('file://'.length)
      debug('copying', filePath)

      // copyMedia(filePath, bufferPath + urlencode(cacheURI), function (err) {
      copyMedia(filePath, bufferURI + urlencode(cacheURI), cert, function (err) {
        if (err) {
          debug(err)
        } else {
          console.log('success!')
          // 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
          debug(credit)
          pay(credit)

          if (row && row.conn) {
            row.conn.close()
          }
        }
      })
    })
  }, 500)
}
function addMediaToBuffer ( uri , cert , mode , user , safe , bufferURI ) { // var bufferPath = root // if (bufferURI) { //  bufferPath += '/../' + url.parse(bufferURI).path // } setTimeout ( ( ) => { try { // fs.unlinkSync(lastFile) } catch ( e ) { console . error ( e ) } var params = { } params . reviewer = user if ( safe && safe === 'off' ) { params . safe = 0 } else { params . safe = 1 } algos . getRandomUnseenImage . function ( params ) . then ( function ( row ) { debug ( 'unseen' , row . ret ) var cacheURI = row . ret [ 0 ] [ 0 ] . cacheURI var filePath = cacheURI . substr ( 'file://' . length ) debug ( 'copying' , filePath ) // copyMedia(filePath, bufferPath + urlencode(cacheURI), function (err) { copyMedia ( filePath , bufferURI + urlencode ( cacheURI ) , cert , function ( err ) { if ( err ) { debug ( err ) } else { console . log ( 'success!' ) // 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 debug ( credit ) pay ( credit ) if ( row && row . conn ) { row . conn . close ( ) } } } ) } ) } , 500 ) }
Adds media to buffer
@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.
Adds media to buffer