Skip to content

Commit d9e15de

Browse files
committed
feat: add mobile specific resolver functionality
1 parent 0427362 commit d9e15de

File tree

5 files changed

+89
-25
lines changed

5 files changed

+89
-25
lines changed

apps/mobile/metro.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ config.resolver.nodeModulesPaths = [
1818
path.resolve(__dirname, "../../node_modules"),
1919
]
2020

21+
config.resolver.resolveRequest = (context, moduleName, platform) => {
22+
const result = context.resolveRequest(context, moduleName, platform)
23+
if (result.type === "sourceFile") {
24+
const lastDotIndex = result.filePath.lastIndexOf(".")
25+
const mobilePath = `${result.filePath.slice(0, lastDotIndex)}.mobile${result.filePath.slice(lastDotIndex)}`
26+
const file = context.fileSystemLookup(mobilePath)
27+
if (file.exists) {
28+
return {
29+
...result,
30+
filePath: mobilePath,
31+
}
32+
} else {
33+
return result
34+
}
35+
}
36+
return result
37+
}
38+
2139
module.exports = wrapWithReanimatedMetroConfig(
2240
withNativeWind(config, { input: "./src/global.css" }),
2341
)

apps/mobile/src/lib/image.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
1-
const imageRefererMatches = [
2-
{
3-
url: /^https:\/\/\w+\.sinaimg.cn/,
4-
referer: "https://weibo.com",
5-
},
6-
{
7-
url: /^https:\/\/i\.pximg\.net/,
8-
referer: "https://www.pixiv.net",
9-
},
10-
{
11-
url: /^https:\/\/cdnfile\.sspai\.com/,
12-
referer: "https://sspai.com",
13-
},
14-
{
15-
url: /^https:\/\/(?:\w|-)+\.cdninstagram\.com/,
16-
referer: "https://www.instagram.com",
17-
},
18-
{
19-
url: /^https:\/\/sp1\.piokok\.com/,
20-
referer: "https://www.piokok.com",
21-
force: true,
22-
},
23-
]
1+
import { imageRefererMatches } from "@follow/shared/src/image"
242

253
const isValidUrl = (url: string) => {
264
try {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const env = {}

packages/shared/src/constants/env.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { createEnv } from "@t3-oss/env-core"
2+
import { z } from "zod"
3+
4+
export const isDev =
5+
"process" in globalThis ? process.env.NODE_ENV === "development" : import.meta.env.DEV
6+
export const env = createEnv({
7+
clientPrefix: "VITE_",
8+
client: {
9+
VITE_WEB_URL: z.string().url().default("https://app.follow.is"),
10+
VITE_API_URL: z.string(),
11+
VITE_DEV_PROXY: z.string().optional(),
12+
VITE_SENTRY_DSN: z.string().optional(),
13+
VITE_INBOXES_EMAIL: z.string().default("@follow.re"),
14+
VITE_FIREBASE_CONFIG: z.string().optional(),
15+
16+
VITE_OPENPANEL_CLIENT_ID: z.string().optional(),
17+
VITE_OPENPANEL_API_URL: z.string().url().optional(),
18+
19+
// For external, use api_url if you don't want to fill it in.
20+
VITE_EXTERNAL_PROD_API_URL: z.string().optional(),
21+
VITE_EXTERNAL_DEV_API_URL: z.string().optional(),
22+
VITE_EXTERNAL_API_URL: z.string().optional(),
23+
VITE_WEB_PROD_URL: z.string().optional(),
24+
VITE_WEB_DEV_URL: z.string().optional(),
25+
},
26+
27+
emptyStringAsUndefined: true,
28+
runtimeEnv: getRuntimeEnv() as any,
29+
30+
skipValidation: "process" in globalThis ? process.env.VITEST === "true" : false,
31+
})
32+
33+
function metaEnvIsEmpty() {
34+
try {
35+
return Object.keys(import.meta.env || {}).length === 0
36+
} catch {
37+
return true
38+
}
39+
}
40+
41+
function getRuntimeEnv() {
42+
try {
43+
if (metaEnvIsEmpty()) {
44+
return process.env
45+
}
46+
return injectExternalEnv(import.meta.env)
47+
} catch {
48+
return process.env
49+
}
50+
}
51+
52+
declare const globalThis: any
53+
function injectExternalEnv<T>(originEnv: T): T {
54+
if (!("document" in globalThis)) {
55+
return originEnv
56+
}
57+
const prefix = "__followEnv"
58+
const env = globalThis[prefix]
59+
if (!env) {
60+
return originEnv
61+
}
62+
63+
for (const key in env) {
64+
originEnv[key as keyof T] = env[key]
65+
}
66+
return originEnv
67+
}

packages/shared/src/image.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { env } from "@follow/shared/env"
1+
import { env } from "./constants/env"
22

33
export const IMAGE_PROXY_URL = "https://webp.follow.is"
44

@@ -8,7 +8,7 @@ export const selfRefererMatches = [env.VITE_OPENPANEL_API_URL, IMAGE_PROXY_URL].
88

99
export const imageRefererMatches = [
1010
{
11-
url: /^https:\/\/\w+\.sinaimg.cn/,
11+
url: /^https:\/\/\w+\.sinaimg\.cn/,
1212
referer: "https://weibo.com",
1313
},
1414
{

0 commit comments

Comments
 (0)