Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
}
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')
}
}
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)
}
},
// -----------------------------------------------
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
},
/**
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)
})
import Mastodon, { Instance } from 'megalodon'
const BASE_URL: string = 'http://mastodon.social'
Mastodon.get('/api/v1/instance', {}, BASE_URL).then(res => {
console.log(res)
})