fp/packages/link2cid
CJ_Clippy 8d122573bf
ci / build (push) Has been cancelled Details
use .npmrc use-node-version instead of .nvmrc
2024-06-02 14:55:32 -08:00
..
src rewrite 2024-04-24 21:42:03 +00:00
.dockerignore make next.dockerfile more lightweight 2024-03-29 19:27:03 -08:00
.env.example add gitea ci 2024-03-28 23:28:02 -08:00
.gitignore re-add link2cid as NOT a submodule 2024-03-13 23:30:49 -08:00
.npmrc use .npmrc use-node-version instead of .nvmrc 2024-06-02 14:55:32 -08:00
Dockerfile re-add link2cid as NOT a submodule 2024-03-13 23:30:49 -08:00
README.md build the docker img 2024-04-24 22:37:49 +00:00
app.json 2024-03-14 update 2024-03-14 14:08:49 -08:00
index.js rewrite 2024-04-24 21:42:03 +00:00
package.json use .npmrc use-node-version instead of .nvmrc 2024-06-02 14:55:32 -08:00
pnpm-lock.yaml use .npmrc use-node-version instead of .nvmrc 2024-06-02 14:55:32 -08:00

README.md

link2cid

Motivation

I wish I could give kubo or IPFS cluster a URI to a file and then they would download the file and add to ipfs, returning me a CID.

However, neither kubo nor IPFS cluster can do this.

link2cid solves this issue with a REST API for adding a file at url to IPFS.

Usage

Configure environment

Create a .env file. See .env.example for an example. Important environment variables are API_KEY, PORT, and IPFS_URL.

Install and run

pnpm install
pnpm start

Make a GET REST request to /add with url as a query parameter. Expect a SSE response.

dokku

dokku builder-dockerfile:set link2cid dockerfile-path link2cid.Dockerfile

Examples

HTTPIE

http -A bearer -a $API_KEY --stream 'http://localhost:3939/add?url=https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png' Accept:text/event-stream
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/event-stream; charset=utf-8
Date: Thu, 21 Dec 2023 11:20:24 GMT
Transfer-Encoding: identity
X-Powered-By: Express

:ok

event: dlProgress
data: {
    "percent": 100
}

event: addProgress
data: {
    "percent": 100
}

event: end
data: {
    "cid": "bafkreidj3jo7efguloaixz6vgivljlmowagagjtqv4yanyqgty2hrvg6km"
}

Javascript

@todo this is incomplete/untested

await fetch('http://localhost:3939/add?url=https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png', {
    headers: {
        'accept': 'text/event-stream',
        'authorization': `Bearer ${API_KEY}`
    }
});

Dev notes

Generate API_KEY

require('crypto').randomBytes(64).toString('hex')

TypeError: data.split is not a function

If you see this error, make sure data in SSE event payload is a string, not a number.