mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-28 06:55:00 +02:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a95e543d8 | |||
| ed0d6fb6b9 | |||
| 5bdb12dafe | |||
| f3474dac98 | |||
| 7319bf84f7 | |||
| 9ec9908ed7 | |||
| fd0a0818c1 | |||
| 929acc5b1c | |||
| 71348f45b2 | |||
| 21eb4d2876 | |||
| 18270381c1 | |||
| 8e938a2723 | |||
| 197f8f7ba5 | |||
| 10b528642d | |||
| 60d6fff085 | |||
| c664b3da91 | |||
| 492282e758 | |||
| 47f4aefc25 | |||
| 7c0ff9ede7 | |||
| 44e81ea979 | |||
| 56dc10330a | |||
| eb8ad6a181 | |||
| 4edd2e4d32 | |||
| 813c3abe54 | |||
| 048e4fc73c | |||
| 923371e5b4 | |||
| 81430ba3d3 | |||
| e4aaadc9f9 | |||
| d04740fede | |||
| 4677a0d501 | |||
| b4463f0e1a | |||
| b7c0669c38 | |||
| 152d2fb1d6 | |||
| d374b4f66e | |||
| cb3f0b49a8 | |||
| 192542629f | |||
| 84d5a4b86c |
@@ -77,7 +77,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
|
||||||
with:
|
with:
|
||||||
registry: docker.io
|
registry: docker.io
|
||||||
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
@@ -149,7 +149,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
|
||||||
with:
|
with:
|
||||||
registry: docker.io
|
registry: docker.io
|
||||||
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
@@ -204,7 +204,7 @@ jobs:
|
|||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
|
||||||
with:
|
with:
|
||||||
registry: docker.io
|
registry: docker.io
|
||||||
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
@@ -407,7 +407,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry (for cosign)
|
- name: Login to GitHub Container Registry (for cosign)
|
||||||
uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ jobs:
|
|||||||
stale:
|
stale:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@1e223db275d687790206a7acac4d1a11bd6fe629 # v10.4.0
|
- uses: actions/stale@4391f3da665fdf50b6810c1a66712fb9ba21aa93 # v11.0.0
|
||||||
with:
|
with:
|
||||||
days-before-stale: 14
|
days-before-stale: 14
|
||||||
days-before-close: 14
|
days-before-close: 14
|
||||||
|
|||||||
+2213
-788
File diff suppressed because it is too large
Load Diff
Generated
+324
-281
File diff suppressed because it is too large
Load Diff
+5
-5
@@ -94,12 +94,12 @@
|
|||||||
"input-otp": "1.4.2",
|
"input-otp": "1.4.2",
|
||||||
"ioredis": "5.11.0",
|
"ioredis": "5.11.0",
|
||||||
"jmespath": "0.16.0",
|
"jmespath": "0.16.0",
|
||||||
"js-yaml": "4.3.0",
|
"js-yaml": "4.3.1",
|
||||||
"jsonwebtoken": "9.0.3",
|
"jsonwebtoken": "9.0.3",
|
||||||
"lucide-react": "1.17.0",
|
"lucide-react": "1.17.0",
|
||||||
"maxmind": "5.0.6",
|
"maxmind": "5.0.6",
|
||||||
"moment": "2.30.1",
|
"moment": "2.30.1",
|
||||||
"next": "16.2.11",
|
"next": "16.3.1",
|
||||||
"next-intl": "4.13.0",
|
"next-intl": "4.13.0",
|
||||||
"next-themes": "0.4.6",
|
"next-themes": "0.4.6",
|
||||||
"nextjs-toploader": "3.9.17",
|
"nextjs-toploader": "3.9.17",
|
||||||
@@ -139,7 +139,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@dotenvx/dotenvx": "1.69.1",
|
"@dotenvx/dotenvx": "1.69.1",
|
||||||
"@esbuild-plugins/tsconfig-paths": "0.1.2",
|
"@esbuild-plugins/tsconfig-paths": "0.1.2",
|
||||||
"@react-email/ui": "^6.5.0",
|
"@react-email/ui": "^6.9.2",
|
||||||
"@tailwindcss/postcss": "4.3.0",
|
"@tailwindcss/postcss": "4.3.0",
|
||||||
"@tanstack/react-query-devtools": "5.100.14",
|
"@tanstack/react-query-devtools": "5.100.14",
|
||||||
"@types/better-sqlite3": "7.6.13",
|
"@types/better-sqlite3": "7.6.13",
|
||||||
@@ -170,7 +170,7 @@
|
|||||||
"esbuild-node-externals": "1.22.0",
|
"esbuild-node-externals": "1.22.0",
|
||||||
"eslint": "10.4.0",
|
"eslint": "10.4.0",
|
||||||
"eslint-config-next": "16.2.6",
|
"eslint-config-next": "16.2.6",
|
||||||
"postcss": "8.5.15",
|
"postcss": "8.5.23",
|
||||||
"prettier": "3.8.3",
|
"prettier": "3.8.3",
|
||||||
"react-email": "6.5.0",
|
"react-email": "6.5.0",
|
||||||
"tailwindcss": "4.3.0",
|
"tailwindcss": "4.3.0",
|
||||||
@@ -182,6 +182,6 @@
|
|||||||
"overrides": {
|
"overrides": {
|
||||||
"esbuild": "0.28.0",
|
"esbuild": "0.28.0",
|
||||||
"dompurify": "3.4.0",
|
"dompurify": "3.4.0",
|
||||||
"postcss": "8.5.15"
|
"postcss": "8.5.23"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-50
@@ -3,8 +3,6 @@ import config from "./config";
|
|||||||
import { getHostMeta } from "./hostMeta";
|
import { getHostMeta } from "./hostMeta";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import {
|
import {
|
||||||
aiProviders,
|
|
||||||
aiUsageRecords,
|
|
||||||
alertRules,
|
alertRules,
|
||||||
apiKeys,
|
apiKeys,
|
||||||
blueprints,
|
blueprints,
|
||||||
@@ -13,16 +11,7 @@ import {
|
|||||||
siteResources
|
siteResources
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import { sites, users, orgs, resources, clients, idp } from "@server/db";
|
import { sites, users, orgs, resources, clients, idp } from "@server/db";
|
||||||
import {
|
import { eq, count, notInArray, and, isNotNull, isNull } from "drizzle-orm";
|
||||||
eq,
|
|
||||||
count,
|
|
||||||
countDistinct,
|
|
||||||
notInArray,
|
|
||||||
and,
|
|
||||||
isNotNull,
|
|
||||||
isNull,
|
|
||||||
gte
|
|
||||||
} from "drizzle-orm";
|
|
||||||
import { APP_VERSION } from "./consts";
|
import { APP_VERSION } from "./consts";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { UserType } from "@server/types/UserTypes";
|
import { UserType } from "@server/types/UserTypes";
|
||||||
@@ -183,25 +172,6 @@ class TelemetryClient {
|
|||||||
.select({ count: count() })
|
.select({ count: count() })
|
||||||
.from(blueprints);
|
.from(blueprints);
|
||||||
|
|
||||||
const [aiProvidersCount] = await db
|
|
||||||
.select({ count: count() })
|
|
||||||
.from(aiProviders);
|
|
||||||
const [orgsWithAiProviders] = await db
|
|
||||||
.select({ count: countDistinct(aiProviders.orgId) })
|
|
||||||
.from(aiProviders);
|
|
||||||
|
|
||||||
const usageWindowStart =
|
|
||||||
Math.floor(Date.now() / 1000) -
|
|
||||||
this.collectionIntervalDays * 24 * 60 * 60;
|
|
||||||
const [aiUsageRecordsRecent] = await db
|
|
||||||
.select({ count: count() })
|
|
||||||
.from(aiUsageRecords)
|
|
||||||
.where(gte(aiUsageRecords.createdAt, usageWindowStart));
|
|
||||||
const [orgsWithRecentAiUsage] = await db
|
|
||||||
.select({ count: countDistinct(aiUsageRecords.orgId) })
|
|
||||||
.from(aiUsageRecords)
|
|
||||||
.where(gte(aiUsageRecords.createdAt, usageWindowStart));
|
|
||||||
|
|
||||||
const supporterKey = config.getSupporterData();
|
const supporterKey = config.getSupporterData();
|
||||||
|
|
||||||
const allPrivateResources = await db.select().from(siteResources);
|
const allPrivateResources = await db.select().from(siteResources);
|
||||||
@@ -212,7 +182,6 @@ class TelemetryClient {
|
|||||||
let numPrivResourceCidr = 0;
|
let numPrivResourceCidr = 0;
|
||||||
let numPrivResourceHttp = 0;
|
let numPrivResourceHttp = 0;
|
||||||
let numPrivResourceSsh = 0;
|
let numPrivResourceSsh = 0;
|
||||||
let numPrivResourceInference = 0;
|
|
||||||
for (const res of allPrivateResources) {
|
for (const res of allPrivateResources) {
|
||||||
if (res.mode === "host") {
|
if (res.mode === "host") {
|
||||||
numPrivResourceHosts += 1;
|
numPrivResourceHosts += 1;
|
||||||
@@ -222,8 +191,6 @@ class TelemetryClient {
|
|||||||
numPrivResourceHttp += 1;
|
numPrivResourceHttp += 1;
|
||||||
} else if (res.mode === "ssh") {
|
} else if (res.mode === "ssh") {
|
||||||
numPrivResourceSsh += 1;
|
numPrivResourceSsh += 1;
|
||||||
} else if (res.mode === "inference") {
|
|
||||||
numPrivResourceInference += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.alias) {
|
if (res.alias) {
|
||||||
@@ -244,11 +211,6 @@ class TelemetryClient {
|
|||||||
numPrivateResourceCidr: numPrivResourceCidr,
|
numPrivateResourceCidr: numPrivResourceCidr,
|
||||||
numPrivateResourceHttp: numPrivResourceHttp,
|
numPrivateResourceHttp: numPrivResourceHttp,
|
||||||
numPrivateResourceSsh: numPrivResourceSsh,
|
numPrivateResourceSsh: numPrivResourceSsh,
|
||||||
numPrivateResourceInference: numPrivResourceInference,
|
|
||||||
numAiProviders: aiProvidersCount.count,
|
|
||||||
numOrgsWithAiProviders: orgsWithAiProviders.count,
|
|
||||||
numAiUsageRecordsRecent: aiUsageRecordsRecent.count,
|
|
||||||
numOrgsWithRecentAiUsage: orgsWithRecentAiUsage.count,
|
|
||||||
numAlertRules: numAlertRules.count,
|
numAlertRules: numAlertRules.count,
|
||||||
numUserDevices: userDevicesCount.count,
|
numUserDevices: userDevicesCount.count,
|
||||||
numMachineClients: machineClients.count,
|
numMachineClients: machineClients.count,
|
||||||
@@ -361,17 +323,6 @@ class TelemetryClient {
|
|||||||
num_resources_non_http: stats.resources.filter(
|
num_resources_non_http: stats.resources.filter(
|
||||||
(r) => r.mode !== "http"
|
(r) => r.mode !== "http"
|
||||||
).length,
|
).length,
|
||||||
num_resources_ai_gateway: stats.resources.filter(
|
|
||||||
(r) => r.mode === "inference"
|
|
||||||
).length,
|
|
||||||
num_private_resources_ai_gateway:
|
|
||||||
stats.numPrivateResourceInference,
|
|
||||||
num_ai_providers: stats.numAiProviders,
|
|
||||||
num_orgs_with_ai_providers: stats.numOrgsWithAiProviders,
|
|
||||||
num_ai_usage_records_recent:
|
|
||||||
stats.numAiUsageRecordsRecent,
|
|
||||||
num_orgs_with_recent_ai_usage:
|
|
||||||
stats.numOrgsWithRecentAiUsage,
|
|
||||||
num_newt_sites: stats.sites.filter((s) => s.type === "newt")
|
num_newt_sites: stats.sites.filter((s) => s.type === "newt")
|
||||||
.length,
|
.length,
|
||||||
num_local_sites: stats.sites.filter(
|
num_local_sites: stats.sites.filter(
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import HttpCode from "@server/types/HttpCode";
|
|||||||
import { response } from "@server/lib/response";
|
import { response } from "@server/lib/response";
|
||||||
import { db } from "@server/db";
|
import { db } from "@server/db";
|
||||||
import { passwordResetTokens, users } from "@server/db";
|
import { passwordResetTokens, users } from "@server/db";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq, and } from "drizzle-orm";
|
||||||
import { alphabet, generateRandomString, sha256 } from "oslo/crypto";
|
import { alphabet, generateRandomString, sha256 } from "oslo/crypto";
|
||||||
import { createDate } from "oslo";
|
import { createDate } from "oslo";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
@@ -49,7 +49,12 @@ export async function requestPasswordReset(
|
|||||||
const existingUser = await db
|
const existingUser = await db
|
||||||
.select()
|
.select()
|
||||||
.from(users)
|
.from(users)
|
||||||
.where(eq(users.email, email));
|
.where(
|
||||||
|
and(
|
||||||
|
eq(users.email, email),
|
||||||
|
eq(users.type, UserType.Internal)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if (!existingUser || !existingUser.length) {
|
if (!existingUser || !existingUser.length) {
|
||||||
await randomDelay(2000);
|
await randomDelay(2000);
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ import {
|
|||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
||||||
import { toast } from "@app/hooks/useToast";
|
import { toast } from "@app/hooks/useToast";
|
||||||
|
import { PaidFeaturesAlert } from "@app/components/PaidFeaturesAlert";
|
||||||
|
import { tierMatrix, TierFeature } from "@server/lib/billing/tierMatrix";
|
||||||
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
import {
|
import {
|
||||||
createBrowserGatewayTargetFormSchema,
|
createBrowserGatewayTargetFormSchema,
|
||||||
@@ -57,6 +59,7 @@ import {
|
|||||||
selectedSiteSchema,
|
selectedSiteSchema,
|
||||||
type SshSettingsFormValues
|
type SshSettingsFormValues
|
||||||
} from "@app/lib/browserGatewayTargetFormSchema";
|
} from "@app/lib/browserGatewayTargetFormSchema";
|
||||||
|
import { DockerManager, DockerState } from "@app/lib/docker";
|
||||||
import { orgQueries } from "@app/lib/queries";
|
import { orgQueries } from "@app/lib/queries";
|
||||||
import { finalizeSubdomainSanitize } from "@app/lib/subdomain-utils";
|
import { finalizeSubdomainSanitize } from "@app/lib/subdomain-utils";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
@@ -325,20 +328,19 @@ export default function Page() {
|
|||||||
const rawResourcesAllowed =
|
const rawResourcesAllowed =
|
||||||
env.flags.allowRawResources &&
|
env.flags.allowRawResources &&
|
||||||
(build !== "saas" || remoteExitNodes.length > 0);
|
(build !== "saas" || remoteExitNodes.length > 0);
|
||||||
|
const enterpriseModesAllowed =
|
||||||
|
!env.flags.disableEnterpriseFeatures;
|
||||||
|
|
||||||
const availableTypes = useMemo((): NewResourceType[] => {
|
const availableTypes = useMemo((): NewResourceType[] => {
|
||||||
const base: NewResourceType[] = [
|
const base: NewResourceType[] = ["http", "inference"];
|
||||||
"http",
|
if (enterpriseModesAllowed) {
|
||||||
"inference",
|
base.push("ssh", "rdp", "vnc");
|
||||||
"ssh",
|
}
|
||||||
"rdp",
|
|
||||||
"vnc"
|
|
||||||
];
|
|
||||||
if (rawResourcesAllowed) {
|
if (rawResourcesAllowed) {
|
||||||
base.push("tcp", "udp");
|
base.push("tcp", "udp");
|
||||||
}
|
}
|
||||||
return base;
|
return base;
|
||||||
}, [rawResourcesAllowed]);
|
}, [enterpriseModesAllowed, rawResourcesAllowed]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!availableTypes.includes(resourceType)) {
|
if (!availableTypes.includes(resourceType)) {
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import { assertEquals } from "@test/assert";
|
||||||
|
import { detectLocale } from "./detectLocale";
|
||||||
|
|
||||||
|
function runTests() {
|
||||||
|
assertEquals(
|
||||||
|
detectLocale("zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja;q=0.6"),
|
||||||
|
"zh-TW",
|
||||||
|
"An exact regional match should take precedence over a language fallback"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale("ZH-tw"),
|
||||||
|
"zh-TW",
|
||||||
|
"Locale matching should be case-insensitive"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale(" zh-TW ; q=1 , zh-CN;q=0.8 "),
|
||||||
|
"zh-TW",
|
||||||
|
"Whitespace and quality parameters should not prevent an exact match"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale("zh-CN,zh-TW;q=0.9"),
|
||||||
|
"zh-CN",
|
||||||
|
"Simplified Chinese should still match exactly"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale("zh"),
|
||||||
|
"zh-CN",
|
||||||
|
"A generic Chinese preference should retain the existing fallback"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale("en-GB,en;q=0.9"),
|
||||||
|
"en-US",
|
||||||
|
"An unsupported region should fall back to a supported locale for the language"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale("ja-JP,zh-TW;q=0.9"),
|
||||||
|
"zh-TW",
|
||||||
|
"The next preference should be used when a language is unsupported"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale("zh-CN;q=0.5,zh-TW;q=0.9"),
|
||||||
|
"zh-TW",
|
||||||
|
"Preferences should be evaluated by quality"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale("zh-TW;q=0,fr-FR;q=0.8"),
|
||||||
|
"fr-FR",
|
||||||
|
"Locales with zero quality should be excluded"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale("*,de-DE;q=0.8"),
|
||||||
|
"de-DE",
|
||||||
|
"A wildcard should not obscure a supported preference"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale("ja-JP"),
|
||||||
|
undefined,
|
||||||
|
"An unsupported language should not match"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
detectLocale(""),
|
||||||
|
undefined,
|
||||||
|
"An empty Accept-Language header should not match"
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("All locale detection tests passed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
runTests();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Locale detection test failed:", error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { Locale, locales } from "./config";
|
||||||
|
|
||||||
|
export function detectLocale(acceptLanguage: string): Locale | undefined {
|
||||||
|
const browserLocales = acceptLanguage
|
||||||
|
.split(",")
|
||||||
|
.map((entry, index) => {
|
||||||
|
const [locale, ...parameters] = entry.trim().split(";");
|
||||||
|
const qualityParameter = parameters.find((parameter) =>
|
||||||
|
parameter.trim().toLowerCase().startsWith("q=")
|
||||||
|
);
|
||||||
|
const quality = qualityParameter
|
||||||
|
? Number(qualityParameter.trim().slice(2))
|
||||||
|
: 1;
|
||||||
|
|
||||||
|
return {
|
||||||
|
locale: locale.trim().toLowerCase(),
|
||||||
|
quality,
|
||||||
|
index
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter(
|
||||||
|
({ locale, quality }) =>
|
||||||
|
locale && locale !== "*" && quality > 0 && quality <= 1
|
||||||
|
)
|
||||||
|
.sort(
|
||||||
|
(left, right) =>
|
||||||
|
right.quality - left.quality || left.index - right.index
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const { locale: browserLocale } of browserLocales) {
|
||||||
|
const exactMatch = locales.find(
|
||||||
|
(locale) => locale.toLowerCase() === browserLocale
|
||||||
|
);
|
||||||
|
if (exactMatch) {
|
||||||
|
return exactMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
const browserLanguage = browserLocale.split("-")[0];
|
||||||
|
const languageMatch = locales.find(
|
||||||
|
(locale) => locale.split("-")[0].toLowerCase() === browserLanguage
|
||||||
|
);
|
||||||
|
if (languageMatch) {
|
||||||
|
return languageMatch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { cookies, headers } from "next/headers";
|
import { cookies, headers } from "next/headers";
|
||||||
import { Locale, defaultLocale, locales } from "@/i18n/config";
|
import { Locale, defaultLocale, locales } from "@/i18n/config";
|
||||||
|
import { detectLocale } from "@/i18n/detectLocale";
|
||||||
import { internal } from "@app/lib/api";
|
import { internal } from "@app/lib/api";
|
||||||
import { authCookieHeader } from "@app/lib/api/cookies";
|
import { authCookieHeader } from "@app/lib/api/cookies";
|
||||||
|
|
||||||
@@ -47,12 +48,7 @@ export async function getUserLocale(): Promise<Locale> {
|
|||||||
const acceptLang = headerList.get("accept-language");
|
const acceptLang = headerList.get("accept-language");
|
||||||
|
|
||||||
if (acceptLang) {
|
if (acceptLang) {
|
||||||
const browserLang = acceptLang.split(",")[0];
|
const matched = detectLocale(acceptLang);
|
||||||
const matched = locales.find((locale) =>
|
|
||||||
browserLang
|
|
||||||
.toLowerCase()
|
|
||||||
.startsWith(locale.split("-")[0].toLowerCase())
|
|
||||||
);
|
|
||||||
if (matched) {
|
if (matched) {
|
||||||
return matched;
|
return matched;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user