ldp.listContainer(path.join(__dirname, '/resources/sampleContainer/'), 'https://server.tld', '', 'text/turtle', function (err, data) {
        if (err) done(err)
        var graph = $rdf.graph()
        $rdf.parse(
          data,
          graph,
          'https://server.tld/sampleContainer',
          'text/turtle')

        var basicContainerStatements = graph.each(
          $rdf.sym('https://server.tld/basicContainerFile.ttl'),
          ns.rdf('type'),
          undefined)

        assert.equal(basicContainerStatements.length, 1)

        var containerStatements = graph.each(
          $rdf.sym('https://server.tld/containerFile.ttl'),
          ns.rdf('type'),
          undefined)

        assert.equal(containerStatements.length, 1)

        basicContainerStatements.forEach(function (statement) {
          assert.equal(statement.uri, ns.ldp('Resource').uri)
        })

        containerStatements.forEach(function (statement) {
          assert.equal(statement.uri, ns.ldp('Resource').uri)
        })

        rm('sampleContainer/containerFile.ttl')
        rm('sampleContainer/basicContainerFile.ttl')
        done()
      })
function match (graph, s, p, o) {
  var matches = graph.statementsMatching(
    s ? $rdf.sym(s) : undefined,
    p ? $rdf.sym(p) : undefined,
    o ? $rdf.sym(o) : undefined)
  return matches
}
    ldp.graph(hostname, '/' + ldp.suffixAcl, baseUri, function (err, graph) {
      if (err) {
        debug('cannot find graph of the user', req.body.webid || ldp.root, err)
        res.status(err.status || 500).send('Fail to find user')
        return
      }

      // TODO do a query
      let emailAddress
      graph
        .statementsMatching(undefined, sym('http://www.w3.org/ns/auth/acl#agent'))
        .some(function (statement) {
          if (statement.object.uri.startsWith('mailto:')) {
            emailAddress = statement.object.uri
            return true
          }
        })

      if (!emailAddress) {
        res.status(406).send('No emailAddress registered in your account')
        return
      }

      const token = tokenService.generate({ webid: req.body.webid })
      const email = generateEmail(req.get('host'), req.body.webid, emailAddress, token)
      emailService.sendMail(email, function (err, info) {
        if (err) {
          res.send(500, 'Failed to send the email for account recovery, try again')
          return
        }

        res.send('Requested')
      })
    })
Beispiel #4
0
      ldp.listContainer(path.join(__dirname, '/resources/sampleContainer/'), 'https://server.tld/resources/sampleContainer/', 'https://server.tld', '', 'text/turtle', function (err, data) {
        if (err) done(err)
        var graph = $rdf.graph()
        $rdf.parse(
          data,
          graph,
          'https://server.tld/sampleContainer',
          'text/turtle')

        var statements = graph
          .each(
            $rdf.sym('https://server.tld/magicType.ttl'),
            ns.rdf('type'),
            undefined)
          .map(function (d) {
            return d.uri
          })
        // statements should be:
        // [ 'http://www.w3.org/ns/iana/media-types/text/turtle#Resource',
        //   'http://www.w3.org/ns/ldp#MagicType',
        //   'http://www.w3.org/ns/ldp#Resource' ]
        assert.equal(statements.length, 3)
        assert.isAbove(statements.indexOf('http://www.w3.org/ns/ldp#MagicType'), -1)
        assert.isAbove(statements.indexOf('http://www.w3.org/ns/ldp#Resource'), -1)

        rm('sampleContainer/magicType.ttl')
        done()
      })
Beispiel #5
0
  createNewGroup (book) {
    const {groupIndex, groupContainer} = indexes(book)
    const group = rdf.sym(`${groupContainer.uri}${uuid.v4().slice(0, 8)}.ttl#this`)
    const name = this.options.defaultNewGroupName || 'Untitled Group'

    // NOTE that order matters here.  Unfortunately this type of update is
    // non-atomic in that solid requires us to send two PATCHes, either of which
    // might fail.
    const patchPromises = [group.doc(), groupIndex]
      .map(doc => {
        const typeStatement = rdf.st(group, ns.rdf('type'), ns.vcard('Group'), doc)
        const nameStatement = rdf.st(group, ns.vcard('fn'), name, group.doc(), doc)
        const includesGroupStatement = rdf.st(book, ns.vcard('includesGroup'), group, doc)
        const toIns = doc.equals(groupIndex)
          ? [typeStatement, nameStatement, includesGroupStatement]
          : [typeStatement, nameStatement]
        return patch(doc.uri, {toIns})
          .then(() => {
            toIns.forEach(st => {
              kb.add(st)
            })
          })
      })
    return Promise.all(patchPromises)
      .then(() => ({group}))
      .catch(err => {
        console.log('Could not create new group.  PATCH failed ' + err)
        throw new Error(`Couldn't create new group.  PATCH failed for (${err.xhr ? err.xhr.responseURL : ''} )`)
      })
  }
Beispiel #6
0
/**
 * Get the value or uri from an object
 * @param  {object} g And rdflib graph object
 * @param  {string} s And rdflib subject
 * @param  {string} p Predicate as a string
 * @return {string}   The value of the object or null
 */
function anyObj (g, s, p) {
  var obj
  obj = g.any(s, $rdf.sym(p))
  if (obj && obj.value) {
    return obj.value
  }
  if (obj && obj.uri) {
    return obj.uri
  }
}
Beispiel #7
0
/**
 * Create a delete patch
 * @param  {array}  params parameters for the patch
 * @param  {string} params.uri        The uri to delete
 * @param  {number} params.mtime      The mod time
 * @param  {string} params.base       The uri base
 * @param  {object} params.g          The graph
 * @return {string}                   The patch
 */
function createDeletePatch (params, g) {
  if (!params || !params.length) {
    return
  }
  var sparql = 'DELETE DATA { \n'
  for (var i = 0; i < params.length; i++) {
    var param = params[i]
    if (param.mtime) {
      sparql += $rdf.sym(param.base) + ' '
      sparql += $rdf.sym('http://www.w3.org/ns/ldp#contains') + ' '
      sparql += $rdf.sym(param.uri) + ' .\n'

      sparql += $rdf.sym(param.uri) + ' '
      sparql += $rdf.sym('http://www.w3.org/ns/posix/stat#mtime') + ' '
      sparql += param.mtime
      sparql += ' .\n'
    } else {
      sparql += $rdf.sym(param.base + '#this') + ' '
      sparql += $rdf.sym('http://purl.org/ontology/pbo/core#playlist_slot') + ' '
      sparql += $rdf.sym(param.obj) + ' .\n'

      var sts = g.statementsMatching($rdf.sym(param.obj))
      for (var i = 0; i < sts.length; i++) {
        var st = sts[i]
        sparql += st.toString()
        debug(st.toString())
      }

/*
      sparql += $rdf.sym(param.obj) + ' '
      sparql += $rdf.sym('http://purl.org/ontology/olo/core#index') + ' '
      sparql += '' + param.index + ''
      sparql += ' .\n'

      sparql += $rdf.sym(param.obj) + ' '
      sparql += $rdf.sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type') + ' '
      sparql += $rdf.sym('http://purl.org/ontology/pbo/core#PlaylistSlot')
      sparql += ' .\n'
      */

    }
  }

  sparql += ' }\n'

  return sparql
}
Beispiel #8
0
      ldp.listContainer(path.join(__dirname, '/resources/sampleContainer/'), 'https://server.tld/resources/sampleContainer/', 'https://server.tld', '', 'text/turtle', function (err, data) {
        if (err) done(err)
        var graph = $rdf.graph()
        $rdf.parse(
          data,
          graph,
          'https://server.tld/sampleContainer',
          'text/turtle')

        var basicContainerStatements = graph
          .each(
            $rdf.sym('https://server.tld/basicContainerFile.ttl'),
            ns.rdf('type'),
            undefined
          )
          .map(d => { return d.uri })

        let expectedStatements = [
          'http://www.w3.org/ns/iana/media-types/text/turtle#Resource',
          'http://www.w3.org/ns/ldp#Resource'
        ]
        assert.deepEqual(basicContainerStatements.sort(), expectedStatements)

        var containerStatements = graph
          .each(
            $rdf.sym('https://server.tld/containerFile.ttl'),
            ns.rdf('type'),
          undefined
          )
          .map(d => { return d.uri })

        assert.deepEqual(containerStatements.sort(), expectedStatements)

        rm('sampleContainer/containerFile.ttl')
        rm('sampleContainer/basicContainerFile.ttl')
        done()
      })
Beispiel #9
0
async function getQuota (root, serverUri) {
  const filename = path.join(root, 'settings/serverSide.ttl')
  var prefs
  try {
    prefs = await _asyncReadfile(filename)
  } catch (error) {
    debug('Setting no quota. While reading serverSide.ttl, got ' + error)
    return Infinity
  }
  var graph = $rdf.graph()
  const storageUri = serverUri + '/'
  try {
    $rdf.parse(prefs, graph, storageUri, 'text/turtle')
  } catch (error) {
    throw new Error('Failed to parse serverSide.ttl, got ' + error)
  }
  return Number(graph.anyValue($rdf.sym(storageUri), ns.solid('storageQuota'))) || Infinity
}
 .end(function (err, data) {
   if (err) {
     return done(err)
   }
   var graph = $rdf.graph()
   $rdf.parse(
     data.text,
     graph,
     'https://nicola.' + host + '/.meta',
     'text/turtle')
   var statements = graph.statementsMatching(
     undefined,
     $rdf.sym('http://www.w3.org/ns/solid/terms#account'),
     undefined)
   if (statements.length === 1) {
     done()
   } else {
     done(new Error('missing link to WebID of account'))
   }
 })
Beispiel #11
0
	process.stdout.on('error', function() {});
	process.stderr.on('data', function(data) {
		output.push('Error: '+data);
	});
	process.stderr.on('end', function() {});
	process.stderr.on('error', function() {});
	process.on('close', function(code) {
		console.log('process '+cmd+' exited ('+code+')');
		cont(code, output.join(''));
	});
	console.log('done spawn');
}
var DEFAULT_TIMEOUT = 30000;

var $rdf = require('rdflib');
var VAMP_PLUGIN = $rdf.sym('http://purl.org/ontology/vamp/Plugin');
var VAMP_PLUGIN_LIBRARY = $rdf.sym('http://purl.org/ontology/vamp/PluginLibrary');
var VAMP_IDENTIFIER = $rdf.sym('http://purl.org/ontology/vamp/identifier');
var VAMP_PARAMETER = $rdf.sym('http://purl.org/ontology/vamp/parameter');
var VAMP_MIN_VALUE = $rdf.sym('http://purl.org/ontology/vamp/min_value');
var VAMP_MAX_VALUE = $rdf.sym('http://purl.org/ontology/vamp/max_value');
var VAMP_DEFAULT_VALUE = $rdf.sym('http://purl.org/ontology/vamp/default_value');
var VAMP_QUANTIZE_STEP = $rdf.sym('http://purl.org/ontology/vamp/quantize_step');
var VAMP_VALUE_NAMES = $rdf.sym('http://purl.org/ontology/vamp/value_names');
var RDF_TYPE = $rdf.sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type');
var RDF_FIRST = $rdf.sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#first');
var RDF_REST = $rdf.sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#rest');
var RDF_NIL = $rdf.sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#nil');
var XSD_INTEGER = $rdf.sym('http://www.w3.org/2001/XMLSchema#integer');
// VAMP plugin metadata
var vampPlugins = {};
Beispiel #12
0
window.onpopstate = function(event) {
  window.document.outline.GotoSubject($rdf.sym(window.document.location.href), true, undefined, true, undefined)
}
Beispiel #13
0
/**
 * Create an insert patch
 * @param  {array}  params parameters for the patch
 * @param  {string} params.uri        The uri to delete
 * @param  {number} params.mtime      The mod time
 * @param  {string} params.base       The uri base
 * @return {string}                   The patch
 */
function createInsertPatch (params) {
  if (!params) {
    return
  }
  var sparql = 'INSERT DATA { \n'
  for (var i = 0; i < params.length; i++) {
    var param = params[i]

    if (!param.mtime) {
      var index = param.index || Math.floor(Math.random() * 1000000)
      sparql += $rdf.sym(param.base + '#this') + ' '
      sparql += $rdf.sym('http://purl.org/ontology/pbo/core#playlist_slot') + ' '
      sparql += $rdf.sym('#' + index) + ' .\n'

      sparql += $rdf.sym('#' + index) + ' '
      sparql += $rdf.sym('http://purl.org/ontology/olo/core#index') + ' '
      sparql += index
      sparql += ' .\n'

      sparql += $rdf.sym('#' + index) + ' '
      sparql += $rdf.sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type') + ' '
      sparql += $rdf.sym('http://purl.org/ontology/pbo/core#PlaylistSlot')
      sparql += ' .\n'

      sparql += $rdf.sym('#' + index) + ' '
      sparql += $rdf.sym('http://purl.org/ontology/pbo/core#playlist_item') + ' '
      sparql += $rdf.sym(param.uri) + ' .\n'

      if (param.startTime) {
        sparql += $rdf.sym('#' + index) + ' '
        sparql += $rdf.sym('https://schema.org/startTime') + ' '
        sparql += '"' + param.startTime + '" .\n'
      }

    } else {
      sparql += $rdf.sym(param.base) + ' '
      sparql += $rdf.sym('http://www.w3.org/ns/ldp#contains') + ' '
      sparql += $rdf.sym(param.uri) + ' .\n'

      sparql += $rdf.sym(param.uri) + ' '
      sparql += $rdf.sym('http://www.w3.org/ns/posix/stat#mtime') + ' '
      sparql += param.mtime
      sparql += ' .\n'
    }
  }

  sparql += ' }\n'

  return sparql
}
Beispiel #14
0
  shell.cat(playlistURI, function (err, content, uri) {
    if (err) {
      console.error(err)
    } else {
      var files = []
      var sort = 'asc'
      var g = $rdf.graph()
      $rdf.parse(content, g, uri, 'text/turtle')

      var arr = g.statementsMatching(null, $rdf.sym('http://www.w3.org/ns/ldp#contains'), null, $rdf.sym(uri))
      console.log(arr)
      for (var i = 0; i < arr.length; i++) {
        var file = arr[i]
        if (file.object && file.object.uri && /.ttl$/.test(file.object.uri)) {
          continue
        }
        var mtime = anyObj(g, file.object, 'http://www.w3.org/ns/posix/stat#mtime')
        var title = anyObj(g, file.object, 'http://purl.org/dc/terms/title')

        files.push({ 'uri': file.object.uri, 'mtime': mtime, 'title': title })
      }
      files = files.sort(function (a, b) {
        if (sort === 'desc') {
          return parseFloat(b.mtime) - parseFloat(a.mtime)
        } else {
          return parseFloat(a.mtime) - parseFloat(b.mtime)
        }
      })

      var patch = ''
      var params = []
      mtime = Math.floor(timestamp.now())
      params.push({ 'uri': mediaURI, 'mtime': mtime, 'base': playlistURI })
      debug('params', params)
      patch += createInsertPatch(params)

      var num
      if (files.length) {
        if (keep) {
          if ((files.length + 1 - keep) >= 0) {
            num = files.length + 1 - keep
          } else {
            num = 0
          }
        } else {
          num = 1
        }
        params = []
        for (i = 0; i < num; i++) {
          file = files[i]
          params.push({ 'uri': file.uri, 'mtime': file.mtime, 'base': playlistURI })
        }
        debug('params', params)
        var deletePatch = createDeletePatch(params, g)
        if (deletePatch) {
          patch += deletePatch
        }
      }

      console.log('patch', patch)
      shell.patch(uri, patch, function (err, ret) {
        if (err) {
          console.error(err)
        } else {
          console.log(ret)
        }
      })
    }
  })
Beispiel #15
0
  shell.cat(playlistURI, function (err, content, playlistURI) {
    if (err) {
      console.error(err)
    } else {
      var slots = false
      var files = []
      var sort = 'asc'
      var g = $rdf.graph()
      $rdf.parse(content, g, playlistURI, 'text/turtle')

      var arr = g.statementsMatching(null, $rdf.sym('http://www.w3.org/ns/ldp#contains'), null, $rdf.sym(playlistURI))
      if (!arr || !arr.length) {
        arr = g.statementsMatching(null, $rdf.sym('http://purl.org/ontology/pbo/core#playlist_slot'), null, $rdf.sym(playlistURI))
        slots = true
      }
      console.log(arr)

      for (var i = 0; i < arr.length; i++) {
        var file = arr[i]
        var obj = file.object
        if (file.object && file.object.uri && /.ttl$/.test(file.object.uri)) {
          continue
        }

        var mtime = anyObj(g, obj, 'http://www.w3.org/ns/posix/stat#mtime')
        var index = anyObj(g, obj, 'http://purl.org/ontology/olo/core#index')
        var title = anyObj(g, obj, 'http://purl.org/dc/terms/title')
        var startTime = anyObj(g, obj, 'https://schema.org/startTime')
        var subtitle = anyObj(g, obj, 'http://purl.org/ontology/po/Subtitle')

        if (slots) {
          var mediaURI = anyObj(g, obj, 'http://purl.org/ontology/pbo/core#playlist_item')
        } else {
          var mediaURI = obj.uri
        }

        files.push({ "uri" : mediaURI, "mtime" : mtime, "title" : title, "index" : index, "file" : file, 'startTime' : startTime, 'subject'  : obj.uri , 'subtitle' : subtitle, "obj" : obj.uri })
      }
      files = files.sort(sortFiles)

      var patch = ''

      num = num || 1
      if (keep && (files.length - keep) >= 0) {
        num = files.length - keep
      }

      var params = []
      var first = 0
      if (offset) {
        first = offset
      }
      var last = num
      if (offset) {
        last = num + offset
      }
      if (last > files.length) {
        last = files.length
      }
      debug('first', first, 'last', last, 'num', num, 'keep', keep, 'offset', offset)
      for (i = first; i < last; i++) {
        file = files[i]
        params.push({ 'uri': file.uri, 'mtime': file.mtime, 'base': playlistURI, 'index': file.index, 'obj' : file.obj })
      }
      debug('params', params)

      if (files && files.length) {
        patch += createDeletePatch(params, g)
        console.log('patch', patch)
        shell.patch(playlistURI, patch, function (err, ret) {
          if (err) {
            console.error(err)
          } else {
            console.log(ret)
          }
        })
      }
    }
  })