diff --git a/README.md b/README.md index 5e6db78..a907ed7 100644 --- a/README.md +++ b/README.md @@ -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` | 🟩 | diff --git a/package.json b/package.json index 60371c3..52fbff4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/api.js b/src/api.js index 3edb45a..8f72f23 100644 --- a/src/api.js +++ b/src/api.js @@ -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; @@ -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"); diff --git a/src/molecules/ar/atoms/mime.js b/src/molecules/ar/atoms/mime.js new file mode 100644 index 0000000..bf75f10 --- /dev/null +++ b/src/molecules/ar/atoms/mime.js @@ -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 {}; + } +}