RIF Marketplace Upload Service
Service that allow to upload file to IPFS
Warning: This project is in alpha state. There might (and most probably will) be changes in the future to its API and working. Also, no guarantees can be made about its stability, efficiency, and security at this stage.
Lead Maintainer
Nazar Duchak
See what "Lead Maintainer" means here.
Table of Contents
Introduction
This is a backend service for uploading files to IPFS which communicate with pinners using libp2p.
It is build using FeathersJS
API
Upload
This api allow you to upload file
POST: /upload
MultiPartFormData: {
files: File1,
files: File2,
account: string,
offerId: string,
peerId: string,
contractAddress: string
}
{
message: 'File uploaded',
fileHash: 'Qmasv234cksldmfFileHash'
}
Get File Size
This api allow you to get size of the file by file hash
GET: /fileSize?hash=<fileHash>
{
fileHash: 'Qmasv234cksldmfFileHash',
fileSizeBytes: 10231
}
Get File Size Limit
This endpoint exposes the max supported size in bytes
GET: /fileSizeLimit
{
fileSizeLimit: 1073741824
}
Configuration
Required reading: node-config docs
There are several ways how to configure this application:
- Using JSON file
- Using Environmental variables
- Using CLI parameters
To run this upload service there is minimum configuration needed, which is supported with all the configuration ways mentioned above:
- Database connection
- Storage provider connection (IPFS)
- Libp2p bootstrap nodes list
For general overview of complete configuration options see Config interface
that describe configuration object's properties. If you need advanced configuration you can build your own JSON configuration
file and load that either using the --config
CLI parameter or using environment variable RIFMUS_CONFIG
.
Environment variables overview
RIFMUS_PORT
(number): port on which the server should listen toRIFMUS_DB
(string): database connection URIRIFMUS_NETWORK_ID
(number): network idRIFMUS_IPFS_URL
(string): IPFS Node urlRIFMUS_COMMS_LISTEN
(array
) - Defines an array of multiaddress that the Upload service libp2p node will listen on. Same as libp2p config's address.listen
property.RIFMUS_COMMS_BOOTSTRAP_ENABLED
(true
/false
) - Defines if bootstrap should be used. Same as libp2p config's bootstrap.enabled
property.RIFMUS_COMMS_BOOTSTRAP_LIST
(array
) - Defines an array of multiaddress that the Upload service libp2p node will use to bootstrap its connectivity. Same as libp2p config's bootstrap.list
property.- CORS settings (see more on expressjs documentation):
RIFMUS_CORS_ORIGIN
(boolean | string | regexp): Configures the Access-Control-Allow-Origin CORS headerRIFMUS_CORS_METHODS
(string) Configures the Access-Control-Allow-Methods CORS header
- Logging related (see bellow):
LOG_LEVEL
(string)LOG_FILTER
(string)LOG_PATH
(string)LOG_NO_COLORS
(boolean) - if set the output won't be colorized
Usage
$ npm install -g @rsksmart/rif-marketplace-upload-service
// Connection to your database
$ export RIFMUS_DB=myDbFile.sqlite
// Database migrations
$ rif-marketplace-upload-service db-migration --up
// Start the server
$ rif-marketplace-upload-service start --port 8000
Commands
rif-marketplace-cache db-migration
migrate database schema
USAGE
$ rif-marketplace-upload-service db-migration
OPTIONS
-d, --down Undo db migrations
-d, --generate=generate Generate migrations using template [--generate=migration_name]
-m, --migration=migration Migration file
-t, --to=to Migrate to
-u, --up Migrate DB
--config=config path to JSON config file to load
--db=db database connection URI
--log=error|warn|info|verbose|debug [default: info] what level of information to log
--log-filter=log-filter what components should be logged (+-, chars allowed)
--log-path=log-path log to file, default is STDOUT
EXAMPLES
$ rif-marketplace-upload-service db-migration --up
$ rif-marketplace-upload-service db-migration --down
$ rif-marketplace-upload-service db-migration --up --to 0-test
$ rif-marketplace-upload-service db-migration --up --migrations 01-test --migrations 02-test
$ rif-marketplace-upload-service db-migration --up --db ./test.sqlite --to 09-test
$ rif-marketplace-upload-service db-migration --down --db ./test.sqlite --to 09-test
$ rif-marketplace-upload-service db-migration --generate my_first_migration
rif-marketplace-upload-service purge
purge cached data
USAGE
$ rif-marketplace-upload-service purge
OPTIONS
--config=config path to JSON config file to load
--log=error|warn|info|verbose|debug [default: warn] what level of information to log
--log-filter=log-filter what components should be logged (+-, chars allowed)
--log-path=log-path log to file, default is STDOUT
EXAMPLE
$ rif-marketplace-upload-service purge
rif-marketplace-upload-service start
start the upload service
USAGE
$ rif-marketplace-upload-service start
OPTIONS
-p, --port=port port to attach the server to
--config=config path to JSON config file to load
--db=db database connection URI
--log=error|warn|info|verbose|debug [default: warn] what level of information to log
--log-filter=log-filter what components should be logged (+-, chars allowed)
--log-path=log-path log to file, default is STDOUT
EXAMPLE
$ rif-marketplace-upload-service start
License
MIT