Skip to content

Commit

Permalink
update release 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
codev911 committed Oct 21, 2024
1 parent 8725a4a commit d871740
Show file tree
Hide file tree
Showing 8 changed files with 6,264 additions and 23 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish to npm

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '22' # specify node version 22
registry-url: 'https://registry.npmjs.org/'

# Install dependencies
- name: Install dependencies
run: npm install

# Build the project
- name: Build the project
run: npm run build

# Testung the project
- name: Testing the project
run: npm run test

- name: Publish package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
node_modules
yarn.lock
package-lock.json
dist
coverage.data
coverage
26 changes: 23 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import https from 'https';

const gateways: string[] = [
'https://ipfs.io/ipfs/{hash}',
Expand All @@ -11,8 +12,14 @@ const gateways: string[] = [
'https://{hash}.ipfs.cf-ipfs.com',
'https://{hash}.ipfs.4everland.io',
'https://{hash}.ipfs.gw3.io',
'https://gateway.pinata.cloud/ipfs/{hash}',
'https://ipfs.quicknode.com/ipfs/{hash}',
];

const agent = new https.Agent({
rejectUnauthorized: true,
});

export const getAllGateway = (ipfsUrl: string): string[] => {
const finalUrl: string[] = [];
const getHash = ipfsUrl.replace('ipfs://', '');
Expand All @@ -31,10 +38,10 @@ export const getAllGateway = (ipfsUrl: string): string[] => {
return finalUrl;
};

export const getLiveGateway = async (
export const getAllLiveGateway = async (
ipfsUrl: string,
timeout?: number
): Promise<string> => {
): Promise<string[]> => {
const listLoop: unknown[] = [];
const finalUrl: string[] = [];
const getHash = ipfsUrl.replace('ipfs://', '');
Expand All @@ -48,7 +55,9 @@ export const getLiveGateway = async (
}

finalUrl.push(url);
listLoop.push(axios.head(url, { timeout: timeout || 5000 }));
listLoop.push(
axios.head(url, { httpsAgent: agent, timeout: timeout || 3000 })
);
});

const result = await Promise.allSettled(listLoop);
Expand All @@ -60,6 +69,17 @@ export const getLiveGateway = async (
}
}

return fullfilled;
};

export const getLiveGateway = async (
ipfsUrl: string,
timeout?: number
): Promise<string> => {
const finalUrl = getAllGateway(ipfsUrl);
const rto = timeout || 5000;
const fullfilled: string[] = await getAllLiveGateway(ipfsUrl, rto);

if (fullfilled.length > 0) {
return fullfilled[0];
} else {
Expand Down
Loading

0 comments on commit d871740

Please sign in to comment.