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.
This requires MongoDb
to work. head over to the download section and install the proper release for your system.
$ 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 :)
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
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
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
Search in users collection:
GET /api/v1/users
available indexed (and full text searchable) fields:
- name
Mixed search (quiet useless at the moment):
keyword=<keyword>&email=<email>
Get user document:
GET /api/v1/users/<id>
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>
Currently obSERVER is configure to listen to:
module.videoObserver = require('./video')(paratii)
module.userObserver = require('./user')(paratii)
module.transactionObserver = require('./transaction')(paratii)
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
}
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'}
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
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/