mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-04-29 01:56:58 +00:00
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/849 Closes #866 Approved-by: Hazelnoot <acomputerdog@gmail.com> Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
commit
5faa26b08f
1 changed files with 15 additions and 7 deletions
|
@ -8,13 +8,21 @@ import { defaultStore } from '@/store.js';
|
||||||
import * as os from '@/os.js';
|
import * as os from '@/os.js';
|
||||||
import MkUrlWarningDialog from '@/components/MkUrlWarningDialog.vue';
|
import MkUrlWarningDialog from '@/components/MkUrlWarningDialog.vue';
|
||||||
|
|
||||||
const extractDomain = /^(https?:\/\/|\/\/)?([^@/\s]+@)?(www\.)?([^:/\s]+)/i;
|
|
||||||
const isRegExp = /^\/(.+)\/(.*)$/;
|
const isRegExp = /^\/(.+)\/(.*)$/;
|
||||||
|
|
||||||
export async function warningExternalWebsite(url: string) {
|
function extractHostname(maybeUrl: string): URL | null {
|
||||||
const domain = extractDomain.exec(url)?.[4];
|
try {
|
||||||
|
const url = new URL(maybeUrl);
|
||||||
|
return url.host;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!domain) return false;
|
export async function warningExternalWebsite(url: string) {
|
||||||
|
const hostname = extractHostname(url);
|
||||||
|
|
||||||
|
if (!hostname) return false;
|
||||||
|
|
||||||
const isTrustedByInstance = instance.trustedLinkUrlPatterns.some(expression => {
|
const isTrustedByInstance = instance.trustedLinkUrlPatterns.some(expression => {
|
||||||
const r = isRegExp.exec(expression);
|
const r = isRegExp.exec(expression);
|
||||||
|
@ -24,11 +32,11 @@ export async function warningExternalWebsite(url: string) {
|
||||||
} else if (expression.includes(' ')) {
|
} else if (expression.includes(' ')) {
|
||||||
return expression.split(' ').every(keyword => url.includes(keyword));
|
return expression.split(' ').every(keyword => url.includes(keyword));
|
||||||
} else {
|
} else {
|
||||||
return domain.endsWith(expression);
|
return `.${hostname}`.endsWith(`.${expression}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const isTrustedByUser = defaultStore.reactiveState.trustedDomains.value.includes(domain);
|
const isTrustedByUser = defaultStore.reactiveState.trustedDomains.value.includes(hostname);
|
||||||
const isDisabledByUser = !defaultStore.reactiveState.warnExternalUrl.value;
|
const isDisabledByUser = !defaultStore.reactiveState.warnExternalUrl.value;
|
||||||
|
|
||||||
if (!isTrustedByInstance && !isTrustedByUser && !isDisabledByUser) {
|
if (!isTrustedByInstance && !isTrustedByUser && !isDisabledByUser) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue