Skip to content

Commit

Permalink
Merge pull request #590 from meetqy/589-bug-修改了自定义域名无法修改回去无法访问
Browse files Browse the repository at this point in the history
🐛 FIX: 自定义域名BUG
  • Loading branch information
meetqy authored Jan 2, 2024
2 parents 06f0762 + b9b4404 commit 7408f42
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
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

0 comments on commit 7408f42

Please sign in to comment.