0proxy

module
v1.0.1-beta.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2021 License: MIT

README

0proxy

0proxy is used to do CRUD operations on 0chain via web interface using REST APIs. It uses GoSDK internally and exposes the SDK methods in the form of APIs. You can find the API documentation on 0chain website.

Setup

Clone the repo and run the following command inside the cloned directory

$ ./docker.local/bin/init.sh

Building and Starting the Node

build zproxy_base first

$ ./docker.local/bin/build.base.sh

If there is new code, do a git pull and run the following command

$ ./docker.local/bin/build.zproxy.sh

Go to the bin directory (cd docker.local/bin) and run the container using

$ ./start.sh

Point to another blockchain

You can point the server to any instance of 0chain blockchain you like, Just go to config (docker.local/config) and update the 0proxy.yaml.

block_worker: http://198.18.0.98:9091

We use blockWorker to connect to the network instead of giving network details directly, It will fetch the network details automatically from the blockWorker's network API.

There are other configurable properties as well which you can update as per the requirement.

Cleanup

Get rid of old data when the blockchain is restarted or if you point to a different network:

$ ./docker.local/bin/clean.sh
Network issue

If there is no test network, run the following command

docker network create --driver=bridge --subnet=198.18.0.0/15 --gateway=198.18.0.255 testnet0

API

Upload

To upload OR update a file to 0chain network.

Path : /upload

Details:

Download

To download a file from 0chain network

Path: /download

Details: https://0chain.net/page-documentation.html#tag/0proxy/paths/~1download/get

Stream

To stream a file from 0chain network

Path: /stream

Details: https://0chain.net/page-documentation.html#tag/0proxy/paths/~1stream/get

Delete

To delete a file from 0chain network

Path: /delete

Details: https://0chain.net/page-documentation.html#tag/0proxy/paths/~1delete/delete

Copy

To copy a file on 0chain network

Path: /copy

Details: https://0chain.net/page-documentation.html#tag/0proxy/paths/~1copy/put

Rename

To rename a file on 0chain network

Path: /rename

Details: https://0chain.net/page-documentation.html#tag/0proxy/paths/~1rename/put

Move

To move a file on 0chain network

Path: /move

Details: https://0chain.net/page-documentation.html#tag/0proxy/paths/~1move/put

Share

To share a file on 0chain network

Path: /share

Details: https://0chain.net/page-documentation.html#tag/0proxy/paths/~1share/put

Sync

sync live stream to 0Storage

start a sync upload worker

Path: /sync Method: POST

Parameter Description Default Required Valid Values
allocation download files to store allocation information yes string
client_json wallet json yes object json
encrypt encrypt files on 0storage false no boolean
feed remote live stream feed(eg. youtube feed) yes url
downloader_args pass args to youtube-dl to download video. -q -f best no youtube-dl
ffmpeg-args pass args to ffmpeg to build segments -loglevel warning no ffmpeg
remote_path remote path to upload file to, use to access file later yes relative file path
file_name how to name and encoding download file yes *.m3u8
delay set segment duration to seconds. 5 no int

Example:

POST /sync HTTP/1.1
Host: 127.0.0.1:9082
Content-Type: application/x-www-form-urlencoded
Content-Length: 951

allocation=bf65fe5f5cd628a489afba9ee3b63b5c935d4de258698bc3f7dea2cd538bbbe8&client_json={"client_id":"01fda2ac3d29b561a8ecb21fdb259967924284d2104956f081f2ed0d9a75e297","client_key":"10a5c5dcc1ce65eb4a97f5ad687eb394258a6061d44c4b9f2a25707ea9da220ddfa804c243f16ac4a825d1a587726590c1eed52abc158c551f87c65a45993503","keys":[{"public_key":"10a5c5dcc1ce65eb4a97f5ad687eb394258a6061d44c4b9f2a25707ea9da220ddfa804c243f16ac4a825d1a587726590c1eed52abc158c551f87c65a45993503","private_key":"a97e99be553ee66e2a6fac824b8cf16ccdcbd99a1375bede6a80faf496320915"}],"mnemonics":"gadget modify shift face obvious season slice owner faint repair unveil wolf bottom refuse ship plastic soul frozen type decline pioneer program truly one","version":"1.0","date_created":"53810-05-04 03:04:20"}&encrypt=false&feed=https://www.youtube.com/watch?v=21qNxnCS8WU&downloader_args=-f best&ffmpeg_args=&delay=5&remote_path=/sync/t1&file_name=video.m3u8
Get logs of current sync upload worker

Path: /sync Method: GET

Output:

"\r 0 / 435972    0.00%\r 435972 / 435972  100.00%\r 435972 / 435972  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video1.ts\n\r 0 / 459848    0.00%\r 459848 / 459848  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video2.ts\n\r 0 / 452704    0.00%\r 452704 / 452704  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video3.ts\n\r 0 / 447252    0.00%\r 447252 / 447252  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video4.ts\n\r 0 / 441236    0.00%\r 441236 / 441236  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video5.ts\n\r 0 / 465864    0.00%\r 465864 / 465864  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video6.ts\n\r 0 / 435972    0.00%\r 435972 / 435972  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video7.ts\n\r 0 / 435972    0.00%\r 435972 / 435972  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video8.ts\n\r 0 / 466804    0.00%\r 466804 / 466804  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video9.ts\n\r 0 / 330316    0.00%\r 330316 / 330316  100.00%\r 330316 / 330316  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video10.ts\n\r 0 / 456840    0.00%\r 456840 / 456840  100.00%\r 456840 / 456840  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video11.ts\n\r 0 / 443680    0.00%\r 443680 / 443680  100.00%\r 443680 / 443680  100.00% 0s\nStatus completed callback. Type = application/octet-stream. Name = video12.ts\n"
stop and clean sync upload worker

Path: /sync Method: DELETE

Troubleshooting

Unable to build docker.local

You might get an error => ERROR [zproxy_build 10/10] RUN go build -v -tags "bn256 development" -ldflags "-X 0chain.net/core/build.BuildTag=$GIT_COMMIT" during docker build process.

Steps to fix it:

  1. go mod tidy

  2. Try to build again, if error still appearing go to step #3

  3. Check logs, it might be error in code.

Directories

Path Synopsis
mux

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL