Back to ProximaNova/ipfs-kubo-rpc-api-for-cgi

usr/lib/cgi-bin/ipfsapi/v0_edit_mpc/add

Raw
 1#!/bin/bash
 2echo "Content-type: application/json"
 3echo; url="$REQUEST_URI"
 4
 5eval $(echo "$url" | awk -F'[=&?]' '{print $2}')=$(echo "$url" | awk -F'[=&?]' '{print $3}')
 6eval $(echo "$url" | awk -F'[=&?]' '{print $4}')=$(echo "$url" | awk -F'[=&?]' '{print $5}')
 7eval $(echo "$url" | awk -F'[=&?]' '{print $6}')=$(echo "$url" | awk -F'[=&?]' '{print $7}')
 8eval $(echo "$url" | awk -F'[=&?]' '{print $8}')=$(echo "$url" | awk -F'[=&?]' '{print $9}')
 9eval $(echo "$url" | awk -F'[=&?]' '{print $10}')=$(echo "$url" | awk -F'[=&?]' '{print $11}')
10eval $(echo "$url" | awk -F'[=&?]' '{print $12}')=$(echo "$url" | awk -F'[=&?]' '{print $13}')
11eval $(echo "$url" | awk -F'[=&?]' '{print $14}')=$(echo "$url" | awk -F'[=&?]' '{print $15}')
12eval $(echo "$url" | awk -F'[=&?]' '{print $16}')=$(echo "$url" | awk -F'[=&?]' '{print $17}')
13eval $(echo "$url" | awk -F'[=&?]' '{print $18}')=$(echo "$url" | awk -F'[=&?]' '{print $19}')
14eval $(echo "$url" | awk -F'[=&?]' '{print $20}')=$(echo "$url" | awk -F'[=&?]' '{print $21}')
15eval $(echo "$url" | awk -F'[=&?]' '{print $22}')=$(echo "$url" | awk -F'[=&?]' '{print $23}')
16eval $(echo "$url" | awk -F'[=&?]' '{print $24}')=$(echo "$url" | awk -F'[=&?]' '{print $25}')
17eval $(echo "$url" | awk -F'[=&?]' '{print $26}')=$(echo "$url" | awk -F'[=&?]' '{print $27}')
18eval $(echo "$url" | awk -F'[=&?]' '{print $28}')=$(echo "$url" | awk -F'[=&?]' '{print $29}')
19eval $(echo "$url" | awk -F'[=&?]' '{print $30}')=$(echo "$url" | awk -F'[=&?]' '{print $31}')
20eval $(echo "$url" | awk -F'[=&?]' '{print $32}')=$(echo "$url" | awk -F'[=&?]' '{print $33}')
21eval $(echo "$url" | awk -F'[=&?]' '{print $34}')=$(echo "$url" | awk -F'[=&?]' '{print $35}')
22eval $(echo "$url" | awk -F'[=&?]' '{print $36}')=$(echo "$url" | awk -F'[=&?]' '{print $37}')
23eval $(echo "$url" | awk -F'[=&?]' '{print $38}')=$(echo "$url" | awk -F'[=&?]' '{print $39}')
24eval $(echo "$url" | awk -F'[=&?]' '{print $40}')=$(echo "$url" | awk -F'[=&?]' '{print $41}')
25eval $(echo "$url" | awk -F'[=&?]' '{print $42}')=$(echo "$url" | awk -F'[=&?]' '{print $43}')
26eval $(echo "$url" | awk -F'[=&?]' '{print $44}')=$(echo "$url" | awk -F'[=&?]' '{print $45}')
27eval $(echo "$url" | awk -F'[=&?]' '{print $46}')=$(echo "$url" | awk -F'[=&?]' '{print $47}')
28
29if [ ! -z $quiet ]; then quiet_="&quiet=$quiet"; fi
30if [ ! -z $quieter ]; then quieter_="&resolve-type=$quieter"; fi
31if [ ! -z $silent ]; then silent_="&silent=$silent"; fi
32if [ ! -z $progress ]; then progress_="&progress=$progress"; fi
33if [ ! -z $trickle ]; then trickle_="&trickle=$trickle"; fi
34if [ ! -z $onlyhash ]; then onlyhash_="&only-hash=$onlyhash"; fi
35if [ ! -z $wrapwithdirectory ]; then wrapwithdirectory_="&wrap-with-directory=$wrapwithdirectory"; fi
36if [ ! -z $chunker ]; then chunker_="&chunker=$chunker"; fi
37if [ ! -z $rawleaves ]; then rawleaves_="&raw-leaves=$rawleaves"; fi
38if [ ! -z $nocopy ]; then nocopy_="&nocopy=$nocopy"; fi
39if [ ! -z $fscache ]; then fscache_="&fscache=$fscache"; fi
40if [ ! -z $cidversion ]; then cidversion_="&cid-version=$cidversion"; fi
41if [ ! -z $hash ]; then hash_="&hash=$hash"; fi
42if [ ! -z $inline ]; then inline_="&inline=$inline"; fi
43if [ ! -z $inlinelimit ]; then inlinelimit_="&inline-limit=$inlinelimit"; fi
44if [ ! -z $pin ]; then pin_="&pin=$pin"; fi
45if [ ! -z $tofiles ]; then tofiles_="&to-files=$tofiles"; fi
46if [ ! -z $preservemode ]; then preservemode_="&preserve-mode=$preservemode"; fi
47if [ ! -z $preservemtime ]; then preservemtime_="&preserve-mtime=$preservemtime"; fi
48if [ ! -z $mode ]; then mode_="&mode=$mode"; fi
49if [ ! -z $mtime ]; then mtime_="&mtime=$mtime"; fi
50if [ ! -z $mtimensecs ]; then mtimensecs_="&mtime-nsecs=$mtimensecs"; fi
51
52curl -X POST -F file=@"$file" "http://10.0.0.232:5001/api/v0/add?$quiet_$quieter_$silent_$progress_$trickle_$onlyhash_$wrapwithdirectory_$chunker_$rawleaves_$nocopy_$fscache_$cidversion_$hash_$inline_$inlinelimit_$pin_$tofiles_$preservemode_$preservemtime_$mode_$mtime_$mtimensecs_"
53
54# quiet [bool]: Write minimal output. Required: no.
55# quieter [bool]: Write only final hash. Required: no.
56# silent [bool]: Write no output. Required: no.
57# progress [bool]: Stream progress data. Required: no.
58# trickle [bool]: Use trickle-dag format for dag generation. Required: no.
59# only-hash [bool]: Only chunk and hash - do not write to disk. Required: no.
60# wrap-with-directory [bool]: Wrap files with a directory object. Required: no.
61# chunker [string]: Chunking algorithm, size-[bytes], rabin-[min]-[avg]-[max] or buzhash. Required: no.
62# raw-leaves [bool]: Use raw blocks for leaf nodes. Required: no.
63# nocopy [bool]: Add the file using filestore. Implies raw-leaves. (experimental). Required: no.
64# fscache [bool]: Check the filestore for pre-existing blocks. (experimental). Required: no.
65# cid-version [int]: CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. Passing version 1 will cause the raw-leaves option to default to true. Required: no.
66# hash [string]: Hash function to use. Implies CIDv1 if not sha2-256. (experimental). Required: no.
67# inline [bool]: Inline small blocks into CIDs. (experimental). Required: no.
68# inline-limit [int]: Maximum block size to inline. (experimental). Default: 32. Required: no.
69# pin [bool]: Pin locally to protect added files from garbage collection. Default: true. Required: no.
70# to-files [string]: Add reference to Files API (MFS) at the provided path. Required: no.
71# preserve-mode [bool]: Apply existing POSIX permissions to created UnixFS entries. Disables raw-leaves. (experimental). Required: no.
72# preserve-mtime [bool]: Apply existing POSIX modification time to created UnixFS entries. Disables raw-leaves. (experimental). Required: no.
73# mode [uint]: Custom POSIX file mode to store in created UnixFS entries. Disables raw-leaves. (experimental). Required: no.
74# mtime [int64]: Custom POSIX modification time to store in created UnixFS entries (seconds before or after the Unix Epoch). Disables raw-leaves. (experimental). Required: no.
75# mtime-nsecs [uint]: Custom POSIX modification time (optional time fraction in nanoseconds). Required: no.
76
77# PROBLEM: Bash variable with hyphen. They cannot contain any hyphen.
78# RENAMED URL vars: only-hash->onlyhash; wrap-with-directory->wrapwithdirectory
79# RENAMED URL vars: raw-leaves->rawleaves; cid-version->cidversion
80# RENAMED URL vars: inline-limit->inlinelimit; to-files->tofiles
81# RENAMED URL vars: preserve-mode->preservemode; preserve-mtime->preservemtime
82# RENAMED URL vars: mtime-nsecs->mtimensecs
83# ADDED URL var: file [string]: for "-F file=@myfile". Required: yes.
84# ?&