Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 FIX: 自定义域名BUG #590

Merged
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
2 changes: 1 addition & 1 deletion apps/electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rao-pics/electron",
"version": "1.0.0-alpha.12",
"version": "1.0.0-alpha.13",
"description": "远程访问 Eagle 素材资源",
"homepage": "https://rao.pics",
"repository": {
Expand Down
18 changes: 0 additions & 18 deletions apps/electron/src/renderer/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,3 @@ export function useDebounce(value: string, delay = 500) {

return debouncedValue;
}

/**
* 获取站点地址
* @returns 站点地址
*/
export function useSite() {
const { data: config } = trpc.config.findUnique.useQuery();

if (config) {
if (config.clientSite) {
return config.clientSite;
}

return `http://${config.ip}:${config.clientPort}`;
}

return "";
}
15 changes: 12 additions & 3 deletions apps/electron/src/renderer/src/pages/basic/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import {
ClockIcon,
EyeIcon,
Expand All @@ -8,7 +8,6 @@ import {
import Content from "@renderer/components/Content";
import Row from "@renderer/components/Row";
import Title from "@renderer/components/Title";
import { useSite } from "@renderer/hooks";
import { QRCodeSVG } from "qrcode.react";

import { trpc } from "@rao-pics/trpc";
Expand Down Expand Up @@ -47,7 +46,17 @@ const BasicPage = () => {
setBtnState(library && library.pendingCount > 0 ? 2 : 1);
}, [library, config]);

const site = useSite();
const site = useMemo(() => {
if (config) {
if (config.clientSite) {
return config.clientSite;
}

return `http://${config.ip}:${config.clientPort}`;
}

return "";
}, [config]);

const onBeforeDeleteLibrary = () => {
window.dialog
Expand Down
18 changes: 12 additions & 6 deletions apps/electron/src/renderer/src/pages/setting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from "@heroicons/react/24/outline";
import Content from "@renderer/components/Content";
import Title from "@renderer/components/Title";
import { useSite } from "@renderer/hooks";

import { trpc } from "@rao-pics/trpc";

Expand All @@ -28,8 +27,6 @@ const SettingPage = () => {

const { data: config } = trpc.config.findUnique.useQuery();

const site = useSite();

return (
<Content title={<Title>通用</Title>}>
<div className="px-4 pb-4">
Expand Down Expand Up @@ -141,14 +138,23 @@ const SettingPage = () => {
}
right={
<input
defaultValue={site}
defaultValue={config?.clientSite ?? undefined}
onBlur={(e) => {
const value = e.target.value.trim();
// 校验域名
if (value && !/^((https|http)?:\/\/)[^\s]+/.test(value)) {
window.dialog.showErrorBox(
"自定义域名",
"请输入正确的域名",
);
return;
}
configUpsert.mutate({
clientSite: e.target.value,
});
}}
className="input-ghost input input-sm w-full !pr-0 text-right font-mono transition-all focus:!pr-4 focus:outline-none"
placeholder="eg: https://desktop.rao.pics"
className="input input-ghost input-sm w-full !pr-0 text-right font-mono transition-all focus:!pr-4 focus:outline-none"
placeholder="输入域名,清空则使用默认值"
/>
}
/>
Expand Down