Skip to content

Mongodb mirror of the Paratii's video contracts, used for indexing, querying and aggregating video info.

License

Notifications You must be signed in to change notification settings

Paratii-Video/paratii-db

Repository files navigation

CircleCI

Paratii-Db aka Paratii-obServer

WORK IN PROGRESS

The Mongodb mirror of the paratii smartcontract data. This is mainly used to make it easier to index and search the video data and do all sorts of aggregations that would be too hard to do on the blockchain data.

Dependencies

This requires MongoDb to work. head over to the download section and install the proper release for your system.

Installation

$ git clone https://github.com/Paratii-Video/paratii-db.git
$ cd paratii-db
$ npm install

# for development (needs Parity node running) & .env with LOCAL_IP
# this command will fail if you don't have previously ran yarn run build:dev on paratii-portal
$ npm run dev

# for production against Paratii Chain
$ npm run start

# Note: You can also use yarn. I'm not gonna judge :)

Testing

First start the mongoDB service:

$ sudo service mongod start

The tests expect a locally running parity node, so start that:

$ npm run parity

And now run the tests in another terminal:

$ npm run test

Documentation

API

REST API are available on db.paratii.video. You can use API also using paratii-lib and paratii.core features, check the docs at:

https://github.com/Paratii-Video/paratii-lib/blob/dev/docs/paratii-core.md

Videos

Get all videos collection:

GET /api/v1/videos

Get all staked videos collection:

GET /api/v1/videos/?staked=true

Get all non staked videos collection:

GET /api/v1/videos?staked=false

Get a paginated videos collection, for example 10 videos with an offset of 20 (a third page):

GET /api/v1/videos?limit=10&offset=20

Search in videos collections:

keyword=<keyword>

available indexed (and full text searchable) fields:

  • video
  • description
  • owner
  • uploader.name
  • uplaoder.address
  • tags

Mixed search:

keyword=<keyword>&owner=<address>

Get single video document:

GET /api/v1/videos/<id>

Get related videos collection (TBD):

GET /api/v1/videos/<id>/related

Get in csv

GET /api/v1/videos/?format=csv

Get in csv and download

GET /api/v1/videos/?format=csv&download=true

Users

Search in users collection:

GET /api/v1/users

available indexed (and full text searchable) fields:

  • name
  • email

Mixed search (quiet useless at the moment):

keyword=<keyword>&email=<email>

Get user document:

GET /api/v1/users/<id>

Transactions

Search in transactions collection:

GET /api/v1/transactions

available indexed (and full text searchable) fields:

  • from
  • to
  • description

Mixed search:

keyword=<keyword>&description=<description>

Get transaction document:

GET /api/v1/transactions/<id>

Overlooking Blockchain obSERVER

Currently obSERVER is configure to listen to:

module.videoObserver = require('./video')(paratii)
module.userObserver = require('./user')(paratii)
module.transactionObserver = require('./transaction')(paratii)

Collection Model

Transaction:

{
_id: String,
blockNumber: Number,
event: String,
description: String,
from: String,
logIndex: Number,
nonce: Number,
source: String,
to: String,
value: Number
}

Video:

{
_id: String,
title: {type: String},
description: {type: String},
price: Number, // FIXME this should be bignumber.js
src: String,
mimetype: String,
owner: {type: String},
stats: {
likes: Number,
dislikes: Number,
likers: Array,
dislikers: Array
},
uploader: {
name: {type: String},
address: {type: String}
},
tags: {type: [String]}
}

User:

{
_id: {type: String},
name: {type: String},
email: {type: String},
ipfsData: String
}

Mongo indexing

Transaction:

{from: 'text', to: 'text', description: 'text'}

Video:

{title: 'text', description: 'text', owner: 'text', 'uploader.name': 'text', 'uploader.address': 'text', tags: 'text'}

User:

{name: 'text', email: 'text'}

Request cors access

Currently our API has limited cors access. Want to develop a project that use Paratii API? Write us on our beloved telegram channel =)

https://t.me/joinchat/EWZMBQ9mnqJ1--NKHpyF8A

Troubleshooting

If you get an error like MongoError: exception: Unrecognized pipeline stage name: '$sample', you may have a Mongo version < 3.2, and you need to upgrade.

Check the version with mongo --version, and follow the instructions here https://docs.mongodb.com/manual/release-notes/3.2-upgrade/

About

Mongodb mirror of the Paratii's video contracts, used for indexing, querying and aggregating video info.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages