Skip to content

Commit

Permalink
Merge pull request #36 from decentldotland/staging
Browse files Browse the repository at this point in the history
feat: batch AR TXs metadata fetching
  • Loading branch information
charmful0x authored Mar 22, 2023
2 parents e30b610 + 2b36f4d commit 161fd37
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ molecules/
### Endpoints
| molecule | endpoint | atoms | stability |
| :-------------: |:-------------:| :-------------:| :-------------:|
| Arweave (`ar`) | `ar.molecule.sh` | `tx-gql` `ota` | 🟩 |
| Arweave (`ar`) | `ar.molecule.sh` | `tx-gql` `ota` `mime` | 🟩 |
| EVM (`evm`) | `evm.molecule.sh` | `signer` | 🟩 |
| Solana (`sol`) | `sol.molecule.sh` | `auth` | 🟩 |
| Zilliqa (`zil`) | `zil.molecule.sh` | `zil-auth` | 🟩 |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "molecule",
"version": "0.2.4",
"version": "0.2.5",
"type": "module",
"description": "reusable EXM components and helper functions for a faster development",
"main": "./src/api.js",
Expand Down
15 changes: 15 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { readNearOracleState } from "./molecules/near/atoms/read-contract.js";
import { getEverTxObject } from "./molecules/everpay/atoms/tx.js";
import { getTokenPrice } from "./molecules/redstone/atoms/oracle.js";
import { postExmData } from "./molecules/exm/atoms/bundlr.js";
import { getTxsMimeType } from "./molecules/ar/atoms/mime.js";

const app = express();
const port = process.env.PORT || 3000;
Expand Down Expand Up @@ -76,6 +77,20 @@ app.get("/ar/tx-gql/:txid", async (req, res) => {
}
});

app.get("/ar/mime/:txids", async (req, res) => {
try {
res.setHeader("Content-Type", "application/json");

const response = await getTxsMimeType(req.params?.txids);
res.send(response);
return;
} catch (error) {
console.log(error);
res.send({});
return;
}
});

app.get("/ota/:pubkey", async (req, res) => {
try {
res.setHeader("Content-Type", "application/json");
Expand Down
22 changes: 22 additions & 0 deletions src/molecules/ar/atoms/mime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { getArTxObject } from "./tx-gql.js";

export async function getTxsMimeType(txs) {
try {
const res = {};
const txsArray = JSON.parse(atob(txs));
for (const tx of txsArray) {
res[tx] = {};

const metadata = await getArTxObject(tx);
res[tx].mime = metadata?.tags.find(
(tag) => tag.name.toLowerCase() === "content-type"
)?.value;
res[tx]["size"] = metadata?.data?.size;
}

return res;
} catch (error) {
console.log(error);
return {};
}
}

0 comments on commit 161fd37

Please sign in to comment.