2019-09-18 19:52:39 +02:00
|
|
|
import Mastodon from "megalodon";
|
2019-04-07 23:25:39 +02:00
|
|
|
|
2019-10-19 22:14:43 +02:00
|
|
|
export const instancesBearerKey =
|
|
|
|
"QBEULaOyF04OKjHsHktx5reOqDUklWMSWfUiKRdcen7iLDjta8kL2ZEgozAlBScizR0LKSMcxg2su9f3VLdJt5dZyfWkSXEPlxHBUlPzBF4Ju9lAiOhklh0TLNpFZBqA";
|
|
|
|
|
2019-04-07 23:25:39 +02:00
|
|
|
/**
|
|
|
|
* Creates the Hyperspace app with the appropriate Redirect URI
|
2019-04-28 21:50:18 +02:00
|
|
|
* @param name The name of the app (if not Hyperspace, will use `name (Hyperspace-like)`)
|
2019-04-07 23:25:39 +02:00
|
|
|
* @param scopes The scopes that the app needs
|
|
|
|
* @param baseurl The base URL of the instance
|
|
|
|
* @param redirect_uri The URL to redirect to when authorizing
|
|
|
|
*/
|
2019-09-18 19:52:39 +02:00
|
|
|
export function createHyperspaceApp(
|
|
|
|
name: string,
|
|
|
|
scopes: string,
|
|
|
|
baseurl: string,
|
|
|
|
redirect_uri: string
|
|
|
|
) {
|
|
|
|
let appName =
|
|
|
|
name === "Hyperspace" ? "Hyperspace" : `${name} (Hyperspace-like)`;
|
|
|
|
return Mastodon.createApp(
|
|
|
|
appName,
|
|
|
|
{
|
|
|
|
scopes: scopes,
|
|
|
|
redirect_uris: redirect_uri,
|
|
|
|
website: "https://hyperspace.marquiskurt.net"
|
|
|
|
},
|
|
|
|
baseurl
|
|
|
|
).then(appData => {
|
|
|
|
return Mastodon.generateAuthUrl(
|
|
|
|
appData.clientId,
|
|
|
|
appData.clientSecret,
|
|
|
|
{
|
|
|
|
redirect_uri: redirect_uri,
|
|
|
|
scope: scopes
|
|
|
|
},
|
|
|
|
baseurl
|
|
|
|
).then(url => {
|
2019-04-07 23:25:39 +02:00
|
|
|
appData.url = url;
|
|
|
|
return appData;
|
2019-09-18 19:52:39 +02:00
|
|
|
});
|
|
|
|
});
|
2019-05-02 22:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the appropriate redirect address.
|
2020-02-07 16:09:47 +01:00
|
|
|
* @param url The address or configuration to use
|
2019-05-02 22:49:09 +02:00
|
|
|
*/
|
2019-09-18 19:52:39 +02:00
|
|
|
export function getRedirectAddress(
|
2020-02-07 16:09:47 +01:00
|
|
|
url: "desktop" | "dynamic" | string
|
2019-09-18 19:52:39 +02:00
|
|
|
): string {
|
2020-02-07 16:09:47 +01:00
|
|
|
switch (url) {
|
2019-05-02 22:49:09 +02:00
|
|
|
case "desktop":
|
2019-05-11 22:03:40 +02:00
|
|
|
return "hyperspace://hyperspace/app/";
|
2019-05-02 22:49:09 +02:00
|
|
|
case "dynamic":
|
|
|
|
return `https://${window.location.host}`;
|
|
|
|
default:
|
2020-02-07 16:09:47 +01:00
|
|
|
return url;
|
2019-05-02 22:49:09 +02:00
|
|
|
}
|
2019-09-18 19:52:39 +02:00
|
|
|
}
|
2019-09-23 23:28:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether a base URL is in the 'disallowed' domains section.
|
|
|
|
* @param domain The URL to test
|
|
|
|
* @returns Boolean dictating the URL's presence in disallowed domains
|
|
|
|
*/
|
|
|
|
export function inDisallowedDomains(domain: string): boolean {
|
|
|
|
let disallowed = ["gab.com"];
|
|
|
|
return disallowed.includes(domain);
|
2019-10-05 19:05:50 +02:00
|
|
|
}
|