kopia lustrzana https://github.com/cheeaun/phanpy
Porównaj commity
2 Commity
9ad60db82d
...
3adfcd7ac5
Autor | SHA1 | Data |
---|---|---|
![]() |
3adfcd7ac5 | |
![]() |
99e5c1036d |
|
@ -12,7 +12,7 @@ import { getAuthorizationURL, registerApplication } from '../utils/auth';
|
||||||
import store from '../utils/store';
|
import store from '../utils/store';
|
||||||
import useTitle from '../utils/useTitle';
|
import useTitle from '../utils/useTitle';
|
||||||
|
|
||||||
const { PHANPY_DEFAULT_INSTANCE: DEFAULT_INSTANCE } = import.meta.env;
|
const { PHANPY_DEFAULT_INSTANCE: DEFAULT_INSTANCE, PHANPY_SCHEME: SCHEME = 'https' } = import.meta.env;
|
||||||
|
|
||||||
function Login() {
|
function Login() {
|
||||||
useTitle('Log in');
|
useTitle('Log in');
|
||||||
|
@ -85,9 +85,11 @@ function Login() {
|
||||||
.replace(/^@?[^@]+@/, '') // Remove @?acct@
|
.replace(/^@?[^@]+@/, '') // Remove @?acct@
|
||||||
.trim()
|
.trim()
|
||||||
: null;
|
: null;
|
||||||
const instanceTextLooksLikeDomain =
|
const instanceTextLooksLikeDomain =
|
||||||
/[^\s\r\n\t\/\\]+\.[^\s\r\n\t\/\\]+/.test(cleanInstanceText) &&
|
(/[^\s\r\n\t\/\\]+\.[^\s\r\n\t\/\\]+/.test(cleanInstanceText) &&
|
||||||
!/[\s\/\\@]/.test(cleanInstanceText);
|
!/[\s\/\\@]/.test(cleanInstanceText)) || SCHEME === "http";
|
||||||
|
|
||||||
|
console.log(SCHEME)
|
||||||
|
|
||||||
const instancesSuggestions = cleanInstanceText
|
const instancesSuggestions = cleanInstanceText
|
||||||
? instancesList
|
? instancesList
|
||||||
|
|
|
@ -9,6 +9,8 @@ import {
|
||||||
saveAccount,
|
saveAccount,
|
||||||
} from './store-utils';
|
} from './store-utils';
|
||||||
|
|
||||||
|
const { PHANPY_SCHEME: SCHEME = 'https' } = import.meta.env;
|
||||||
|
|
||||||
// Default *fallback* instance
|
// Default *fallback* instance
|
||||||
const DEFAULT_INSTANCE = 'mastodon.social';
|
const DEFAULT_INSTANCE = 'mastodon.social';
|
||||||
|
|
||||||
|
@ -36,7 +38,9 @@ export function initClient({ instance, accessToken }) {
|
||||||
.replace(/\/+$/, '')
|
.replace(/\/+$/, '')
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
}
|
}
|
||||||
const url = instance ? `https://${instance}` : `https://${DEFAULT_INSTANCE}`;
|
const url = instance
|
||||||
|
? `${SCHEME}://${instance}`
|
||||||
|
: `${SCHEME}://${DEFAULT_INSTANCE}`;
|
||||||
|
|
||||||
const masto = createRestAPIClient({
|
const masto = createRestAPIClient({
|
||||||
url,
|
url,
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
const { PHANPY_CLIENT_NAME: CLIENT_NAME, PHANPY_WEBSITE: WEBSITE } = import.meta
|
const {
|
||||||
.env;
|
PHANPY_CLIENT_NAME: CLIENT_NAME,
|
||||||
|
PHANPY_WEBSITE: WEBSITE,
|
||||||
|
PHANPY_SCHEME: SCHEME = 'https',
|
||||||
|
} = import.meta.env;
|
||||||
|
|
||||||
const SCOPES = 'read write follow push';
|
const SCOPES = 'read write follow push';
|
||||||
|
|
||||||
|
@ -11,7 +14,7 @@ export async function registerApplication({ instanceURL }) {
|
||||||
website: WEBSITE,
|
website: WEBSITE,
|
||||||
});
|
});
|
||||||
const registrationResponse = await fetch(
|
const registrationResponse = await fetch(
|
||||||
`https://${instanceURL}/api/v1/apps`,
|
`${SCHEME}://${instanceURL}/api/v1/apps`,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -33,7 +36,7 @@ export async function getAuthorizationURL({ instanceURL, client_id }) {
|
||||||
// redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
|
// redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
|
||||||
response_type: 'code',
|
response_type: 'code',
|
||||||
});
|
});
|
||||||
const authorizationURL = `https://${instanceURL}/oauth/authorize?${authorizationParams.toString()}`;
|
const authorizationURL = `${SCHEME}://${instanceURL}/oauth/authorize?${authorizationParams.toString()}`;
|
||||||
return authorizationURL;
|
return authorizationURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +54,7 @@ export async function getAccessToken({
|
||||||
code,
|
code,
|
||||||
scope: SCOPES,
|
scope: SCOPES,
|
||||||
});
|
});
|
||||||
const tokenResponse = await fetch(`https://${instanceURL}/oauth/token`, {
|
const tokenResponse = await fetch(`${SCHEME}://${instanceURL}/oauth/token`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
|
Ładowanie…
Reference in New Issue