How to use the megalodon.get function in megalodon

To help you get started, we’ve selected a few megalodon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github h3poteto / whalebird-desktop / src / renderer / store / Login.ts View on Github external
confirmInstance: async ({ commit, rootState }, domain: string): Promise => {
    commit(MUTATION_TYPES.CHANGE_SEARCHING, true)
    const cleanDomain = domain.trim()
    try {
      await Mastodon.get('/api/v1/instance', {}, `https://${cleanDomain}`, rootState.App.proxyConfiguration)
      commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
    } catch (err) {
      // https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8
      // Check /.well-known/host-meta to confirm mastodon instance.
      const res = await Mastodon.get('/.well-known/host-meta', {}, `https://${cleanDomain}`, rootState.App.proxyConfiguration).finally(
        () => {
          commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
        }
      )
      const parser = new DOMParser()
      const dom = parser.parseFromString(res.data, 'text/xml')
      const link = dom.getElementsByTagName('Link')[0].outerHTML
      if (!link.includes(`https://${cleanDomain}/.well-known/webfinger`)) {
        throw new Error('domain is not activity pub')
      }
    }
    commit(MUTATION_TYPES.CHANGE_INSTANCE, cleanDomain)
    return true
  }
}
github h3poteto / whalebird-desktop / src / renderer / store / Login.ts View on Github external
confirmInstance: async ({ commit, rootState }, domain: string): Promise => {
    commit(MUTATION_TYPES.CHANGE_SEARCHING, true)
    const cleanDomain = domain.trim()
    try {
      await Mastodon.get('/api/v1/instance', {}, `https://${cleanDomain}`, rootState.App.proxyConfiguration)
      commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
    } catch (err) {
      // https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8
      // Check /.well-known/host-meta to confirm mastodon instance.
      const res = await Mastodon.get('/.well-known/host-meta', {}, `https://${cleanDomain}`, rootState.App.proxyConfiguration).finally(
        () => {
          commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
        }
      )
      const parser = new DOMParser()
      const dom = parser.parseFromString(res.data, 'text/xml')
      const link = dom.getElementsByTagName('Link')[0].outerHTML
      if (!link.includes(`https://${cleanDomain}/.well-known/webfinger`)) {
        throw new Error('domain is not activity pub')
      }
    }
github h3poteto / whalebird-desktop / src / renderer / store / TimelineSpace.ts View on Github external
detectPleroma: async ({ commit, state, rootState }) => {
    const res = await Mastodon.get('/instance', {}, state.account.baseURL + '/api/v1', rootState.App.proxyConfiguration)
    if (res.data.version.includes('Pleroma')) {
      commit(MUTATION_TYPES.CHANGE_PLEROMA, true)
    } else {
      commit(MUTATION_TYPES.CHANGE_PLEROMA, false)
    }
  },
  // -----------------------------------------------
github h3poteto / whalebird-desktop / src / renderer / store / TimelineSpace.ts View on Github external
fetchEmojis: async ({ commit, rootState }, account: LocalAccount): Promise> => {
    const res = await Mastodon.get>('/custom_emojis', {}, account.baseURL + '/api/v1', rootState.App.proxyConfiguration)
    commit(MUTATION_TYPES.UPDATE_EMOJIS, res.data)
    return res.data
  },
  /**
github h3poteto / megalodon / example / typescript / proxy_instance.ts View on Github external
env: {
    PROXY_HOST: string
    PROXY_PORT: number
    PROXY_PROTOCOL: 'http' | 'https' | 'socks4' | 'socks4a' | 'socks5' | 'socks5h' | 'socks'
  }
}

const BASE_URL: string = 'http://mastodon.social'

const proxy: ProxyConfig = {
  host: process.env.PROXY_HOST,
  port: process.env.PROXY_PORT,
  protocol: process.env.PROXY_PROTOCOL
}

Mastodon.get('/api/v1/instance', {}, BASE_URL, proxy).then(res => {
  console.log(res)
})
github h3poteto / megalodon / example / typescript / instance.ts View on Github external
import Mastodon, { Instance } from 'megalodon'

const BASE_URL: string = 'http://mastodon.social'

Mastodon.get('/api/v1/instance', {}, BASE_URL).then(res => {
  console.log(res)
})

megalodon

Fediverse API client for node.js and browser

MIT
Latest version published 17 days ago

Package Health Score

75 / 100
Full package analysis