Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/pages/install/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import { useSearchParams } from "react-router-dom";
import { CACHE_KEY_SCRIPT_INFO } from "@App/app/cache_key";
import { cacheInstance } from "@App/app/cache";
import { formatBytes } from "@App/pkg/utils/utils";
import { formatBytes, prettyUrl } from "@App/pkg/utils/utils";

type ScriptOrSubscribe = Script | Subscribe;

Expand Down Expand Up @@ -315,7 +315,7 @@

useEffect(() => {
!loaded && initAsync();
}, [searchParams, loaded]);

Check warning on line 318 in src/pages/install/App.tsx

View workflow job for this annotation

GitHub Actions / Run tests

React Hook useEffect has a missing dependency: 'initAsync'. Either include it or remove the dependency array

const [watchFile, setWatchFile] = useState(false);
const metadataLive = useMemo(() => (scriptInfo?.metadata || {}) as SCMetadata, [scriptInfo]);
Expand Down Expand Up @@ -605,7 +605,7 @@
return () => {
unmountFileTrack(handle);
};
}, [memoWatchFile]);

Check warning on line 608 in src/pages/install/App.tsx

View workflow job for this annotation

GitHub Actions / Run tests

React Hook useEffect has missing dependencies: 'localFileHandle', 'scriptInfo?.uuid', 'setupWatchFile', and 'watchFile'. Either include them or remove the dependency array

// 检查是否有 uuid 或 file
const hasUUIDorFile = useMemo(() => {
Expand Down Expand Up @@ -672,7 +672,7 @@
useEffect(() => {
if (!urlHref) return;
loadURLAsync(urlHref);
}, [urlHref]);

Check warning on line 675 in src/pages/install/App.tsx

View workflow job for this annotation

GitHub Actions / Run tests

React Hook useEffect has a missing dependency: 'loadURLAsync'. Either include it or remove the dependency array

if (!hasUUIDorFile) {
return urlHref ? (
Expand Down Expand Up @@ -779,13 +779,13 @@
bold
style={{
overflowWrap: "break-word",
wordBreak: "break-all",
wordBreak: "break-word",
maxHeight: "70px",
display: "block",
overflowY: "auto",
}}
>
{`${t("source")}: ${scriptInfo?.url}`}
{`${t("source")}: ${prettyUrl(scriptInfo?.url)}`}
</Typography.Text>
</div>
</div>
Expand Down
34 changes: 34 additions & 0 deletions src/pkg/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,37 @@ export const formatBytes = (bytes: number, decimals: number = 2): string => {

return `${value.toFixed(decimals)} ${units[i]}`;
};

// 把编码URL变成使用者可以阅读的格式
export const prettyUrl = (s: string | undefined | null, baseUrl?: string) => {
if (s?.includes("://")) {
let u;
try {
u = baseUrl ? new URL(s, baseUrl) : new URL(s);
} catch {
// ignored
}
if (!u) return s;
const pathname = u.pathname;
if (pathname && pathname.includes("%")) {
try {
const raw = decodeURI(pathname);
if (
raw &&
raw.length < pathname.length &&
!raw.includes("?") &&
!raw.includes("#") &&
!raw.includes("&") &&
!raw.includes("=") &&
!raw.includes("%") &&
!raw.includes(":")
) {
s = s.replace(pathname, raw);
}
} catch {
// ignored
}
}
}
return s;
};
Loading