fp/packages/link2cid
Chris Grimmett 0fd947c78f
ci / build (push) Failing after 26s Details
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s Details
add gitea ci
2024-03-28 23:28:02 -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 link2cid is k8s-ified 2024-03-15 19:48:24 -08:00
.nvmrc link2cid is k8s-ified 2024-03-15 19:48:24 -08:00
Dockerfile re-add link2cid as NOT a submodule 2024-03-13 23:30:49 -08:00
README.md re-add link2cid as NOT a submodule 2024-03-13 23:30:49 -08:00
app.json 2024-03-14 update 2024-03-14 14:08:49 -08:00
index.js add gitea ci 2024-03-28 23:28:02 -08:00
package.json re-add link2cid as NOT a submodule 2024-03-13 23:30:49 -08:00
pnpm-lock.yaml re-add link2cid as NOT a submodule 2024-03-13 23:30:49 -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.