From: Alec Armbruster Date: Fri, 16 Jun 2023 23:18:06 +0000 (-0400) Subject: more cleanup X-Git-Url: http://these/git/%7Bpost.community_actor_id%7D?a=commitdiff_plain;h=fbc13249ca2add7be9608402841b5a85f740065d;p=lemmy-ui.git more cleanup --- diff --git a/src/shared/utils.ts b/src/shared/utils.ts index c0caad8..6019e4d 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -40,7 +40,7 @@ import moment from "moment"; import tippy from "tippy.js"; import Toastify from "toastify-js"; import { getHttpBase } from "./env"; -import { i18n, languages } from "./i18next"; +import { i18n } from "./i18next"; import { CommentNodeI, DataType, IsoData, VoteType } from "./interfaces"; import { HttpService, UserService } from "./services"; import { isBrowser } from "./utils/browser/is-browser"; @@ -231,6 +231,7 @@ export function futureDaysToUnixTime(days?: number): number | undefined { const imageRegex = /(http)?s?:?(\/\/[^"']*\.(?:jpg|jpeg|gif|png|svg|webp))/; const videoRegex = /(http)?s?:?(\/\/[^"']*\.(?:mp4|webm))/; +const tldRegex = /([a-z0-9]+\.)*[a-z0-9]+\.[a-z]+/; export function isImage(url: string) { return imageRegex.test(url); @@ -244,6 +245,10 @@ export function validURL(str: string) { return !!new URL(str); } +export function validInstanceTLD(str: string) { + return tldRegex.test(str); +} + export function communityRSSUrl(actorId: string, sort: string): string { const url = new URL(actorId); return `${url.origin}/feeds${url.pathname}.xml?sort=${sort}`; @@ -269,31 +274,6 @@ export function getDataTypeString(dt: DataType) { return dt === DataType.Post ? "Post" : "Comment"; } -export function getLanguages( - override?: string, - myUserInfo = UserService.Instance.myUserInfo -): string[] { - const myLang = myUserInfo?.local_user_view.local_user.interface_language; - const lang = override || myLang || "browser"; - - if (lang == "browser" && isBrowser()) { - return getBrowserLanguages(); - } else { - return [lang]; - } -} - -function getBrowserLanguages(): string[] { - // Intersect lemmy's langs, with the browser langs - const langs = languages ? languages.map(l => l.code) : ["en"]; - - // NOTE, mobile browsers seem to be missing this list, so append en - const allowedLangs = navigator.languages - .concat("en") - .filter(v => langs.includes(v)); - return allowedLangs; -} - export async function fetchThemeList(): Promise { return fetch("/css/themelist").then(res => res.json()); }