-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alan Shaw
committed
May 20, 2021
1 parent
a501f9c
commit 19602da
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Cron Pinata Sync | ||
|
||
on: | ||
schedule: | ||
- cron: '0 */12 * * *' | ||
|
||
jobs: | ||
update: | ||
name: Sync with Pinata | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
env: ['staging', 'production'] | ||
timeout-minutes: 60 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 15 | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: Run job | ||
env: | ||
DEBUG: '*' | ||
ENV: ${{ matrix.env }} | ||
CF_ACCOUNT: ${{ secrets.CF_ACCOUNT }} | ||
CF_TOKEN: ${{ secrets.CF_TOKEN }} | ||
PINATA_JWT: ${{ secrets.PINATA_JWT }} | ||
run: yarn --cwd packages/cron start:pinata |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { URL } from 'url' | ||
import fetch from 'node-fetch' | ||
|
||
const endpoint = 'https://api.pinata.cloud' | ||
|
||
export class Pinata { | ||
/** | ||
* @param {{ apiToken: string }} config | ||
*/ | ||
constructor({ apiToken }) { | ||
this.apiToken = apiToken | ||
} | ||
|
||
/** | ||
* @param {string} cid | ||
* @param {{ pinataOptions?: { hostNodes?: string[] }, pinataMetadata?: { name?: string } }} [options] | ||
* @returns {Promise<{ id: string, ipfsHash: string, status: string, name: string }>} | ||
*/ | ||
async pinByHash(cid, options) { | ||
const url = new URL('/pinning/pinByHash', endpoint) | ||
|
||
const res = await fetch(url.toString(), { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${this.apiToken}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ hashToPin: cid, ...(options || {}) }), | ||
}) | ||
|
||
const text = await res.text() | ||
if (!res.ok) { | ||
throw Object.assign( | ||
new Error(`${res.status} ${res.statusText}: ${text}`), | ||
{ response: res } | ||
) | ||
} | ||
|
||
return JSON.parse(text) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters