ମୂଳ ବିଷୟବସ୍ତୁକୁ ଯାଆନ୍ତୁ
API key ନିଅନ୍ତୁ

ଗାଇଡ୍ · ଅଡିଓ

ଏକ ପବିତ୍ର ରେକର୍ଡିଂ ବଜାନ୍ତୁ

ରେକର୍ଡିଂ ଥିବା ଏଣ୍ଟ୍ରି ପାଇଁ ଏକ ଅସ୍ଥାୟୀ ପ୍ଲେବ୍ୟାକ୍ URL ମାଗନ୍ତୁ।

ସ୍ୟାଣ୍ଡବକ୍ସରେ ଏହି ଅନୁରୋଧ ଚେଷ୍ଟା କରନ୍ତୁ

1 କାମ କରୁଥିବା ଏକ ଅନୁରୋଧ କରନ୍ତୁ

GET /v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio?format=json
curl "$MANTRILO_API_URL/v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio?format=json" \
  -H "Authorization: Bearer $MANTRILO_API_KEY"
ପ୍ଲେସହୋଲ୍ଡର୍ URL ସହ ଦୃଷ୍ଟାନ୍ତମୂଳକ ରେସପନ୍ସ200 OK
{
  "data": {
    "url": "https://storage.example.com/signed-recording",
    "expiresAt": "2026-11-12T17:51:28.392Z",
    "bytes": 123077,
    "contentType": "audio/x-m4a"
  }
}

2 ଆପଣଙ୍କ ସର୍ଭରରୁ ଏହାକୁ କଲ୍ କରନ୍ତୁ

key କୁ ଆପଣଙ୍କ ବ୍ୟାକଏଣ୍ଡରେ ରଖନ୍ତୁ ଏବଂ କେବଳ କଣ୍ଟେଣ୍ଟ ଆପଣଙ୍କ ଆପ୍‌କୁ ଫେରାନ୍ତୁ। ଏହି Node.js ସର୍ଭର ଗୋଟିଏ ରୁଟ୍ ଦିଏ ଯାହାକୁ ଆପଣଙ୍କ ଆପ୍ କଲ୍ କରିପାରିବ।

server.mjs
// server.mjs · Node.js 22+
import { createServer } from 'node:http';

const apiKey = process.env.MANTRILO_API_KEY;
if (!apiKey) throw new Error('Set MANTRILO_API_KEY on your server.');
const base = process.env.MANTRILO_API_URL ?? "https://api.mantrilo.com";

async function mantrilo(path, input) {
  const response = await fetch(base + path, {
    method: input ? 'POST' : 'GET',
    headers: {
      Authorization: 'Bearer ' + apiKey,
      ...(input ? { 'Content-Type': 'application/json' } : {}),
    },
    ...(input ? { body: JSON.stringify(input) } : {}),
    signal: AbortSignal.timeout(20000),
    redirect: 'error',
  });
  const result = await response.json();
  if (!response.ok) throw Object.assign(new Error('Mantrilo request failed'), {
    status: response.status, requestId: result.requestId,
  });
  return result;
}

async function load(incoming) {
  return mantrilo("/v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio?format=json");
}

createServer(async (req, res) => {
  const incoming = new URL(req.url, 'http://localhost');
  res.setHeader('Content-Type', 'application/json');
  if (req.method !== 'GET' || incoming.pathname !== '/api/mantrilo-guide') {
    res.writeHead(404).end(JSON.stringify({ error: 'Not found' }));
    return;
  }
  try {
    const result = await load(incoming);
    res.end(JSON.stringify(result));
  } catch (error) {
    res.writeHead(error.status ?? 502).end(JSON.stringify({
      error: 'Could not load this content',
      requestId: error.requestId,
    }));
  }
}).listen(3000, '127.0.0.1');
ଆପଣଙ୍କ ଭ୍ୟୁରେ
document.querySelector("audio").src = data.url; // Web player; on mobile use data.url as the audio source.

3 ଇନପୁଟ୍ ଓ ପେଜିନେସନ୍

ମନ୍ତ୍ର ରେକର୍ଡରୁ audio.href ନିଅନ୍ତୁ ଏବଂ ?format=json ଯୋଡ଼ନ୍ତୁ। audio null ହେଲେ ପ୍ଲେୟାର୍ ଲୁଚାନ୍ତୁ। ସାଧାରଣ endpoint ସିଧା ରେକର୍ଡିଂକୁ ରିଡାଇରେକ୍ଟ କରେ। JSON ମୋଡ୍ ଆପଣଙ୍କ ବ୍ୟାକଏଣ୍ଡକୁ ସାଇନ୍ ହୋଇଥିବା URL ଦିଏ।

data.url କୁ ଆପଣଙ୍କ ପ୍ଲେୟାର୍‌କୁ ପଠାନ୍ତୁ, ଏବଂ data.expiresAt ପରେ ନୂଆ ଲିଙ୍କ୍ ମାଗନ୍ତୁ। ଉଦାହରଣ ରେସପନ୍ସରେ ମିଆଦ ସରିଯାଇଥିବା ସାଇନ୍ ହୋଇଥିବା URL ବଦଳରେ ଏକ ପ୍ଲେସହୋଲ୍ଡର୍ ଦିଆଯାଇଛି।

4 କୋଟା

ପ୍ରତ୍ୟେକ ସଫଳ ଲିଙ୍କ୍ ଜାରିରେ ଗୋଟିଏ ଅନୁରୋଧ ଖର୍ଚ୍ଚ ହୁଏ ଏବଂ ଫାଇଲର ସମ୍ପୂର୍ଣ୍ଣ ଆକାର (ବାଇଟ୍‌ରେ) ଅଡିଓ କୋଟାରୁ କଟେ। ପ୍ଲେୟାର୍‌ରେ ପୂର୍ବରୁ ଜାରି ହୋଇଥିବା URL ପଢ଼ିବାରେ କୌଣସି ନୂଆ Mantrilo API ଅନୁରୋଧ ହୁଏ ନାହିଁ।

ଅନୁରୋଧଗୁଡ଼ିକ MANTRILO_API_URL ରୁ ବେସ୍ URL ପଢ଼େ। ସର୍ଭର ଉଦାହରଣଟି ଡିଫଲ୍ଟ ଭାବେ https://api.mantrilo.com ବ୍ୟବହାର କରେ।