refactor: extract all env from shared

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-03-04 19:20:21 +08:00
parent d0bd89b106
commit d20a06dad3
47 changed files with 192 additions and 103 deletions
@@ -92,5 +92,6 @@ export const viteRenderBaseConfig = {
I18N_COMPLETENESS_MAP: JSON.stringify({ ...i18nCompleteness, en: 100 }),
CHANGELOG_CONTENT: JSON.stringify(changelogFile),
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
},
} satisfies UserConfig
+9 -2
View File
@@ -1,8 +1,9 @@
import { electronApp, optimizer } from "@electron-toolkit/utils"
import { callWindowExpose } from "@follow/shared/bridge"
import { APP_PROTOCOL } from "@follow/shared/constants"
import { env } from "@follow/shared/env"
import { buildSafeHeaders } from "@follow/utils/headers"
import { env } from "@follow/shared/env.desktop"
import { createBuildSafeHeaders } from "@follow/utils/headers"
import { IMAGE_PROXY_URL } from "@follow/utils/img-proxy"
import { parse } from "cookie-es"
import { app, BrowserWindow, session } from "electron"
import squirrelStartup from "electron-squirrel-startup"
@@ -108,6 +109,12 @@ function bootstrap() {
registerUpdater()
registerAppTray()
const buildSafeHeaders = createBuildSafeHeaders(env.VITE_WEB_URL, [
env.VITE_OPENPANEL_API_URL || "",
IMAGE_PROXY_URL,
env.VITE_API_URL,
])
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
details.requestHeaders = buildSafeHeaders({
url: details.url,
+1 -1
View File
@@ -3,7 +3,7 @@ import path from "node:path"
import { getRendererHandlers, registerIpcMain } from "@egoist/tipc/main"
import { PushReceiver } from "@eneris/push-receiver"
import { APP_PROTOCOL } from "@follow/shared/constants"
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import type { MessagingData } from "@follow/shared/hono"
import { app, nativeTheme, Notification, shell } from "electron"
import contextMenu from "electron-context-menu"
+1 -1
View File
@@ -1,5 +1,5 @@
import type { AppType } from "@follow/shared"
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import PKG from "@pkg"
import { hc } from "hono/client"
import { ofetch } from "ofetch"
+1 -1
View File
@@ -1,4 +1,4 @@
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { OpenPanel } from "@openpanel/web"
import { app } from "electron"
+1 -1
View File
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url"
import { getRendererHandlers } from "@egoist/tipc/main"
import { callWindowExpose } from "@follow/shared/bridge"
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { app, BrowserWindow, clipboard, dialog, shell } from "electron"
import { BETTER_AUTH_COOKIE_NAME_SESSION_TOKEN } from "~/constants/app"
@@ -0,0 +1,3 @@
import { env } from "@follow/shared/env.desktop"
export const WEB_URL = env.VITE_WEB_URL
@@ -1,8 +1,7 @@
import { Button } from "@follow/components/ui/button/index.js"
import type { FeedViewType } from "@follow/constants"
import { IN_ELECTRON } from "@follow/shared/constants"
import { env } from "@follow/shared/env"
import { UrlBuilder } from "@follow/utils/url-builder"
import { env } from "@follow/shared/env.desktop"
import { isBizId } from "@follow/utils/utils"
import { useMutation } from "@tanstack/react-query"
import { useMemo } from "react"
@@ -13,6 +12,7 @@ import type { FollowMenuItem, MenuItemInput } from "~/atoms/context-menu"
import { whoami } from "~/atoms/user"
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
import { apiClient } from "~/lib/api-fetch"
import { UrlBuilder } from "~/lib/url-builder"
import { useBoostModal } from "~/modules/boost/hooks"
import { useFeedClaimModal } from "~/modules/claim"
import { FeedForm } from "~/modules/discover/feed-form"
@@ -1,4 +1,4 @@
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import type { TrackProperties } from "@openpanel/web"
import { getGeneralSettings } from "~/atoms/settings/general"
@@ -1,4 +1,4 @@
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { OpenPanel } from "@openpanel/web"
export const op = new OpenPanel({
@@ -1,4 +1,4 @@
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import type { BrowserOptions } from "@sentry/react"
import { FetchError } from "ofetch"
@@ -1,4 +1,4 @@
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { appSessionTraceId } from "@follow/utils/environment"
import { version } from "@pkg"
import { nanoid } from "nanoid"
@@ -1,4 +1,4 @@
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import type { AppType } from "@follow/shared/hono"
import PKG from "@pkg"
import { hc } from "hono/client"
@@ -1,10 +1,11 @@
import { env } from "@follow/shared/env"
import { IN_ELECTRON } from "@follow/shared"
import { env } from "@follow/shared/env.desktop"
import type { authPlugins } from "@follow/shared/hono"
import type { BetterAuthClientPlugin } from "better-auth/client"
import { inferAdditionalFields, twoFactorClient } from "better-auth/client/plugins"
import { createAuthClient } from "better-auth/react"
import { IN_ELECTRON, WEB_URL } from "./constants"
import { WEB_URL } from "~/constants/env"
type AuthPlugin = (typeof authPlugins)[number]
const serverPlugins = [
@@ -0,0 +1,4 @@
import { WEB_URL } from "~/constants/env"
import { UrlBuilder as UrlBuilderClass } from "~/lib/url-builder"
export const UrlBuilder = new UrlBuilderClass(WEB_URL)
@@ -1,10 +1,10 @@
import { sendVerificationEmail } from "@follow/shared/auth"
import { WEB_URL } from "@follow/shared/constants"
import { cn } from "@follow/utils/utils"
import { lazy, Suspense, useEffect, useState } from "react"
import { toast } from "sonner"
import { useWhoami } from "~/atoms/user"
import { WEB_URL } from "~/constants/env"
import { useAuthQuery } from "~/hooks/common/useBizQuery"
import { settings } from "~/queries/settings"
@@ -5,7 +5,7 @@ import {
TooltipPortal,
TooltipTrigger,
} from "@follow/components/ui/tooltip/index.jsx"
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { useUserRole } from "~/atoms/user"
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
@@ -8,9 +8,7 @@ import {
FormMessage,
} from "@follow/components/ui/form/index.js"
import { Input } from "@follow/components/ui/input/Input.js"
import type { LoginRuntime } from "@follow/shared/auth"
import { loginHandler, signUp, twoFactor } from "@follow/shared/auth"
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { useTranslation } from "react-i18next"
@@ -18,6 +16,8 @@ import { toast } from "sonner"
import { z } from "zod"
import { useCurrentModal, useModalStack } from "~/components/ui/modal/stacked/hooks"
import type { LoginRuntime } from "~/lib/auth"
import { loginHandler, signUp, twoFactor } from "~/lib/auth"
import { TOTPForm } from "../profile/two-factor"
@@ -8,13 +8,13 @@ import {
TooltipPortal,
TooltipTrigger,
} from "@follow/components/ui/tooltip/index.js"
import type { LoginRuntime } from "@follow/shared/auth"
import { loginHandler } from "@follow/shared/auth"
import clsx from "clsx"
import { m } from "framer-motion"
import { useTranslation } from "react-i18next"
import { useCurrentModal } from "~/components/ui/modal/stacked/hooks"
import type { LoginRuntime } from "~/lib/auth"
import { loginHandler } from "~/lib/auth"
import { isInMAS } from "~/lib/utils"
import { useAuthProviders } from "~/queries/users"
@@ -1,5 +1,4 @@
import { IN_ELECTRON } from "@follow/shared/constants"
import { UrlBuilder } from "@follow/utils/url-builder"
import { useTranslation } from "react-i18next"
import { toast } from "sonner"
@@ -7,6 +6,7 @@ import { useModalStack } from "~/components/ui/modal/stacked/hooks"
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { getRouteParams } from "~/hooks/biz/useRouteParams"
import { useDeleteSubscription } from "~/hooks/biz/useSubscriptionActions"
import { UrlBuilder } from "~/lib/url-builder"
import { ListForm } from "~/modules/discover/list-form"
import { useRegisterCommandEffect } from "../hooks/use-register-command"
@@ -12,7 +12,7 @@ import {
import { Input } from "@follow/components/ui/input/index.js"
import { FeedViewType } from "@follow/constants"
import type { InboxModel } from "@follow/models/types"
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { cn } from "@follow/utils/utils"
import { zodResolver } from "@hookform/resolvers/zod"
import { useMutation } from "@tanstack/react-query"
@@ -1,6 +1,6 @@
import { ActionButton, Button } from "@follow/components/ui/button/index.js"
import { FeedViewType } from "@follow/constants"
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { useMutation } from "@tanstack/react-query"
import { useTranslation } from "react-i18next"
import { toast } from "sonner"
@@ -1,9 +1,9 @@
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/EllipsisWithTooltip.js"
import type { FeedOrListRespModel } from "@follow/models/types"
import { env } from "@follow/shared/env"
import { UrlBuilder } from "@follow/utils/url-builder"
import { env } from "@follow/shared/env.desktop"
import { cn } from "@follow/utils/utils"
import { UrlBuilder } from "~/lib/url-builder"
import { FeedIcon } from "~/modules/feed/feed-icon"
import { FeedTitle } from "~/modules/feed/feed-title"
@@ -9,7 +9,7 @@ import {
import { Input } from "@follow/components/ui/input/index.js"
import { Label } from "@follow/components/ui/label/index.js"
import { changePassword } from "@follow/shared/auth"
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { zodResolver } from "@hookform/resolvers/zod"
import { useMutation } from "@tanstack/react-query"
import { useForm } from "react-hook-form"
@@ -5,7 +5,6 @@ import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
import { nextFrame, stopPropagation } from "@follow/utils/dom"
import { getStorageNS } from "@follow/utils/ns"
import { UrlBuilder } from "@follow/utils/url-builder"
import { clsx, cn } from "@follow/utils/utils"
import { throttle } from "es-toolkit/compat"
import { useAnimationControls } from "framer-motion"
@@ -22,6 +21,7 @@ import { useAuthQuery } from "~/hooks/common"
import { apiClient } from "~/lib/api-fetch"
import { defineQuery } from "~/lib/defineQuery"
import { replaceImgUrlIfNeed } from "~/lib/img-proxy"
import { UrlBuilder } from "~/lib/url-builder"
import { useUserSubscriptionsQuery } from "~/modules/profile/hooks"
import { useUserById } from "~/store/user"
@@ -13,7 +13,7 @@ import { Input } from "@follow/components/ui/input/Input.js"
import { Label } from "@follow/components/ui/label/index.jsx"
import { Radio, RadioGroup } from "@follow/components/ui/radio-group/index.js"
import { Slider } from "@follow/components/ui/slider/index.js"
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { zodResolver } from "@hookform/resolvers/zod"
import { useQuery } from "@tanstack/react-query"
import { useForm } from "react-hook-form"
@@ -10,10 +10,10 @@ import {
TableRow,
} from "@follow/components/ui/table/index.jsx"
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
import { UrlBuilder } from "@follow/utils/url-builder"
import { useTranslation } from "react-i18next"
import { useAuthQuery } from "~/hooks/common"
import { UrlBuilder } from "~/lib/url-builder"
import { FeedIcon } from "~/modules/feed/feed-icon"
import { Balance } from "~/modules/wallet/balance"
import { Queries } from "~/queries"
@@ -18,7 +18,6 @@ import {
TooltipTrigger,
} from "@follow/components/ui/tooltip/index.jsx"
import { views } from "@follow/constants"
import { UrlBuilder } from "@follow/utils/url-builder"
import { cn } from "@follow/utils/utils"
import { useMutation } from "@tanstack/react-query"
import { useMemo } from "react"
@@ -26,6 +25,7 @@ import { toast } from "sonner"
import { useCurrentModal, useModalStack } from "~/components/ui/modal/stacked/hooks"
import { useAuthQuery, useI18n } from "~/hooks/common"
import { UrlBuilder } from "~/lib/url-builder"
import { Balance } from "~/modules/wallet/balance"
import { Queries } from "~/queries"
import { listActions, useOwnedLists } from "~/store/list"
@@ -22,7 +22,6 @@ import {
} from "@follow/components/ui/table/index.jsx"
import { views } from "@follow/constants"
import type { FeedModel } from "@follow/models/types"
import { UrlBuilder } from "@follow/utils/url-builder"
import { isBizId } from "@follow/utils/utils"
import { zodResolver } from "@hookform/resolvers/zod"
import { useMutation } from "@tanstack/react-query"
@@ -38,6 +37,7 @@ import { useCurrentModal } from "~/components/ui/modal/stacked/hooks"
import { useAddFeedToFeedList, useRemoveFeedFromFeedList } from "~/hooks/biz/useFeedActions"
import { apiClient } from "~/lib/api-fetch"
import { createErrorToaster } from "~/lib/error-parser"
import { UrlBuilder } from "~/lib/url-builder"
import { FeedCertification } from "~/modules/feed/feed-certification"
import { FeedIcon } from "~/modules/feed/feed-icon"
import { ViewSelectorRadioGroup } from "~/modules/shared/ViewSelectorRadioGroup"
@@ -9,7 +9,6 @@ import {
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
import type { FeedViewType } from "@follow/constants"
import { nextFrame } from "@follow/utils/dom"
import { UrlBuilder } from "@follow/utils/url-builder"
import { cn, isKeyForMultiSelectPressed } from "@follow/utils/utils"
import dayjs from "dayjs"
import { memo, useCallback, useContext, useState } from "react"
@@ -22,6 +21,7 @@ import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
import { useContextMenu } from "~/hooks/common/useContextMenu"
import { getNewIssueUrl } from "~/lib/issues"
import { UrlBuilder } from "~/lib/url-builder"
import { FeedIcon } from "~/modules/feed/feed-icon"
import { FeedTitle } from "~/modules/feed/feed-title"
import { getPreferredTitle, useFeedById } from "~/store/feed"
@@ -8,7 +8,6 @@ import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
import type { FeedModel, Models } from "@follow/models"
import { stopPropagation } from "@follow/utils/dom"
import { UrlBuilder } from "@follow/utils/url-builder"
import { cn } from "@follow/utils/utils"
import { useQuery } from "@tanstack/react-query"
import type { FC } from "react"
@@ -18,6 +17,7 @@ import { getTrendingAggregates } from "~/api/trending"
import { DrawerModalLayout } from "~/components/ui/modal/stacked/custom-modal"
import { useCurrentModal, useModalStack } from "~/components/ui/modal/stacked/hooks"
import { useFollow } from "~/hooks/biz/useFollow"
import { UrlBuilder } from "~/lib/url-builder"
import { FeedIcon } from "~/modules/feed/feed-icon"
import { usePresentUserProfileModal } from "../profile/hooks"
@@ -4,7 +4,6 @@ import { RootPortal } from "@follow/components/ui/portal/index.js"
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/EllipsisWithTooltip.js"
import { UserRole } from "@follow/constants"
import { useMeasure } from "@follow/hooks"
import { UrlBuilder } from "@follow/utils/url-builder"
import { cn } from "@follow/utils/utils"
import { repository } from "@pkg"
import type { FC } from "react"
@@ -24,6 +23,7 @@ import {
DropdownMenuTrigger,
} from "~/components/ui/dropdown-menu/dropdown-menu"
import { useSignOut } from "~/hooks/biz/useSignOut"
import { UrlBuilder } from "~/lib/url-builder"
import { useAchievementModal } from "~/modules/achievement/hooks"
import { usePresentUserProfileModal } from "~/modules/profile/hooks"
import { useSettingModal } from "~/modules/settings/modal/use-setting-modal-hack"
@@ -2,7 +2,6 @@ import { Divider } from "@follow/components/ui/divider/Divider.js"
import { PresentSheet } from "@follow/components/ui/sheet/Sheet.js"
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/EllipsisWithTooltip.js"
import { UserRole } from "@follow/constants"
import { UrlBuilder } from "@follow/utils/url-builder"
import clsx from "clsx"
import type { FC } from "react"
import { useTranslation } from "react-i18next"
@@ -11,6 +10,7 @@ import { Link } from "react-router"
import rsshubLogoUrl from "~/assets/rsshub-icon.png?url"
import { useUserRole, useWhoami } from "~/atoms/user"
import { useSignOut } from "~/hooks/biz/useSignOut"
import { UrlBuilder } from "~/lib/url-builder"
import { useWallet } from "~/queries/wallet"
import { useAchievementModal } from "../achievement/hooks"
@@ -1,5 +1,5 @@
import { registerGlobalContext } from "@follow/shared/bridge"
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { useEffect, useLayoutEffect } from "react"
import { useTranslation } from "react-i18next"
import { toast } from "sonner"
@@ -1,4 +1,4 @@
import { env } from "@follow/shared/env"
import { env } from "@follow/shared/env.desktop"
import { initializeApp } from "firebase/app"
import { getMessaging, getToken } from "firebase/messaging"
@@ -1,9 +1,14 @@
import { buildSafeHeaders } from "@follow/utils/src/headers"
import { getImageProxyUrl } from "@follow/utils/src/img-proxy"
import { env } from "@follow/shared/src/env.rn"
import { createBuildSafeHeaders } from "@follow/utils/src/headers"
import { getImageProxyUrl, IMAGE_PROXY_URL } from "@follow/utils/src/img-proxy"
import type { ImageProps } from "expo-image"
import { Image } from "expo-image"
import { forwardRef, useCallback, useMemo, useState } from "react"
const buildSafeHeaders = createBuildSafeHeaders(env.VITE_WEB_URL, [
IMAGE_PROXY_URL,
env.VITE_API_URL,
])
export const ProxiedImage = forwardRef<
Image,
ImageProps & {
+1 -1
View File
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import type { AppType } from "@follow/shared"
import { env } from "@follow/shared/src/env"
import { env } from "@follow/shared/src/env.rn"
import { FetchError, ofetch } from "ofetch"
import { userActions } from "../store/user/store"
+1 -1
View File
@@ -1,5 +1,5 @@
import { expoClient } from "@better-auth/expo/client"
import { env } from "@follow/shared/src/env"
import { env } from "@follow/shared/src/env.rn"
import { useQuery } from "@tanstack/react-query"
import { twoFactorClient } from "better-auth/client/plugins"
import { createAuthClient } from "better-auth/react"
@@ -1,5 +1,7 @@
import { FeedViewType } from "@follow/constants"
import { buildSafeHeaders } from "@follow/utils/src/headers"
import { env } from "@follow/shared/src/env.rn"
import { createBuildSafeHeaders } from "@follow/utils/src/headers"
import { IMAGE_PROXY_URL } from "@follow/utils/src/img-proxy"
import { useQuery } from "@tanstack/react-query"
import { Image } from "expo-image"
import { router } from "expo-router"
@@ -19,6 +21,11 @@ import { useSearchPageContext } from "../ctx"
import { BaseSearchPageFlatList, ItemSeparator, RenderScrollComponent } from "./__base"
import { useDataSkeleton } from "./hooks"
const buildSafeHeaders = createBuildSafeHeaders(env.VITE_WEB_URL, [
IMAGE_PROXY_URL,
env.VITE_API_URL,
])
type SearchResultItem = Awaited<ReturnType<typeof apiClient.discover.$post>>["data"][number]
export const SearchFeed = () => {
+81
View File
@@ -0,0 +1,81 @@
import { env } from "@follow/shared/env"
import type { authPlugins } from "@follow/shared/hono"
import type { BetterAuthClientPlugin } from "better-auth/client"
import { inferAdditionalFields, twoFactorClient } from "better-auth/client/plugins"
import { createAuthClient } from "better-auth/react"
const WEB_URL = env.VITE_WEB_URL
type AuthPlugin = (typeof authPlugins)[number]
const serverPlugins = [
{
id: "customGetProviders",
$InferServerPlugin: {} as Extract<AuthPlugin, { id: "customGetProviders" }>,
},
{
id: "customCreateSession",
$InferServerPlugin: {} as Extract<AuthPlugin, { id: "customCreateSession" }>,
},
{
id: "getAccountInfo",
$InferServerPlugin: {} as Extract<AuthPlugin, { id: "getAccountInfo" }>,
},
inferAdditionalFields({
user: {
handle: {
type: "string",
required: false,
},
},
}),
] satisfies BetterAuthClientPlugin[]
const authClient = createAuthClient({
baseURL: `${env.VITE_API_URL}/better-auth`,
plugins: [...serverPlugins, twoFactorClient()],
})
// @keep-sorted
export const {
changeEmail,
changePassword,
createSession,
forgetPassword,
getAccountInfo,
getProviders,
getSession,
linkSocial,
listAccounts,
resetPassword,
sendVerificationEmail,
signIn,
signOut,
signUp,
twoFactor,
unlinkAccount,
updateUser,
} = authClient
export type LoginRuntime = "browser" | "app"
export const loginHandler = async (
provider: string,
runtime?: LoginRuntime,
args?: {
email?: string
password?: string
},
) => {
const { email, password } = args ?? {}
if (provider === "credential") {
if (!email || !password) {
window.location.href = "/login"
return
}
return signIn.email({ email, password })
}
signIn.social({
provider: provider as "google" | "github" | "apple",
callbackURL: runtime === "app" ? `${WEB_URL}/login` : WEB_URL,
})
}
+2 -1
View File
@@ -16,7 +16,6 @@ import {
import { Input } from "@follow/components/ui/input/index.js"
import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
import { authProvidersConfig } from "@follow/constants"
import { createSession, loginHandler, signOut, twoFactor } from "@follow/shared/auth"
import { DEEPLINK_SCHEME } from "@follow/shared/constants"
import { cn } from "@follow/utils/utils"
import { zodResolver } from "@hookform/resolvers/zod"
@@ -27,6 +26,8 @@ import { Link, useLocation, useNavigate } from "react-router"
import { toast } from "sonner"
import { z } from "zod"
import { createSession, loginHandler, signOut, twoFactor } from "~/lib/auth"
export function Login() {
const { status, refetch } = useSession()
@@ -8,12 +8,13 @@ import { Button } from "@follow/components/ui/button/index.jsx"
import { FeedIcon } from "@follow/components/ui/feed-icon/index.jsx"
import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
import { useTitle } from "@follow/hooks"
import { UrlBuilder } from "@follow/utils/url-builder"
import { cn } from "@follow/utils/utils"
import { Fragment } from "react"
import { useTranslation } from "react-i18next"
import { useParams } from "react-router"
import { UrlBuilder } from "~/lib/url-builder"
export const Component = () => {
const params = useParams()
+1 -3
View File
@@ -1,6 +1,6 @@
import type { ElectronAPI } from "@electron-toolkit/preload"
import { env, isDev } from "./env"
const isDev = process.env.NODE_ENV !== "production"
declare const globalThis: {
window: Window & {
@@ -13,8 +13,6 @@ declare const globalThis: {
export const APP_PROTOCOL = isDev ? "follow-dev" : "follow"
export const DEEPLINK_SCHEME = `${APP_PROTOCOL}://` as const
export const WEB_URL = env.VITE_WEB_URL
export const SYSTEM_CAN_UNDER_BLUR_WINDOW = globalThis?.window?.electron
? globalThis?.window.api?.canWindowBlur
: false
-7
View File
@@ -18,13 +18,6 @@ export const env = createEnv({
VITE_OPENPANEL_CLIENT_ID: z.string().optional(),
VITE_OPENPANEL_API_URL: z.string().url().optional(),
// For external, use api_url if you don't want to fill it in.
VITE_EXTERNAL_PROD_API_URL: z.string().optional(),
VITE_EXTERNAL_DEV_API_URL: z.string().optional(),
VITE_EXTERNAL_API_URL: z.string().optional(),
VITE_WEB_PROD_URL: z.string().optional(),
VITE_WEB_DEV_URL: z.string().optional(),
},
emptyStringAsUndefined: true,
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* This env for apps/ssr
* This is universal env
*/
import { z } from "zod"
+30 -40
View File
@@ -1,45 +1,35 @@
import { env } from "@follow/shared"
import { imageRefererMatches } from "./img-proxy"
import { IMAGE_PROXY_URL, imageRefererMatches } from "./img-proxy"
const selfRefererMatches = [env.VITE_OPENPANEL_API_URL, IMAGE_PROXY_URL, env.VITE_API_URL].filter(
Boolean,
) as string[]
export const buildSafeHeaders = ({
url,
headers = {},
}: {
url: string
headers?: Record<string, string>
}) => {
// user agent
if (headers["User-Agent"]) {
headers["User-Agent"] = headers["User-Agent"]
.replace(/\s?Electron\/[\d.]+/, "")
.replace(/\s?Follow\/[\d.a-zA-Z-]+/, "")
} else {
headers["User-Agent"] =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"
}
// referer and origin
if (selfRefererMatches.some((item) => url.startsWith(item))) {
headers.Referer = env.VITE_WEB_URL
} else {
const refererMatch = imageRefererMatches.find((item) => item.url.test(url))
const referer = refererMatch?.referer
if (referer) {
headers.Referer = referer
export const createBuildSafeHeaders =
(webUrl: string, selfRefererMatches: string[]) =>
({ url, headers = {} }: { url: string; headers?: Record<string, string> }) => {
// user agent
if (headers["User-Agent"]) {
headers["User-Agent"] = headers["User-Agent"]
.replace(/\s?Electron\/[\d.]+/, "")
.replace(/\s?Follow\/[\d.a-zA-Z-]+/, "")
} else {
try {
const urlObj = new URL(url)
headers.Referer = urlObj.origin
} catch (error) {
console.error(error)
headers["User-Agent"] =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"
}
// referer and origin
if (selfRefererMatches.some((item) => url.startsWith(item))) {
headers.Referer = webUrl
} else {
const refererMatch = imageRefererMatches.find((item) => item.url.test(url))
const referer = refererMatch?.referer
if (referer) {
headers.Referer = referer
} else {
try {
const urlObj = new URL(url)
headers.Referer = urlObj.origin
} catch (error) {
console.error(error)
}
}
}
}
return headers
}
return headers
}
+3 -6
View File
@@ -1,8 +1,7 @@
import { WEB_URL } from "@follow/shared/constants"
class UrlBuilderStatic {
export class UrlBuilder {
constructor(private readonly webUrl: string) {}
private join(path: string, query?: Record<string, string>) {
const nextUrl = new URL(WEB_URL)
const nextUrl = new URL(this.webUrl)
nextUrl.pathname = path
if (query) {
for (const [key, value] of Object.entries(query)) {
@@ -22,5 +21,3 @@ class UrlBuilderStatic {
return this.join(`share/users/${id}`)
}
}
export const UrlBuilder = new UrlBuilderStatic()