Skip to content
Open
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
15 changes: 14 additions & 1 deletion app/api/cors/[...path]/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { NextRequest, NextResponse } from "next/server";
import { DEFAULT_CORS_HOST } from "@/app/constant";

async function handle(
req: NextRequest,
{ params }: { params: { path: string[] } },
) {
if (req.method === "OPTIONS") {
return NextResponse.json({ body: "OK" }, { status: 200 });
// Set CORS headers for preflight requests
return NextResponse.json(
{ body: "OK" },
{
status: 200,
headers: {
"Access-Control-Allow-Origin": `${DEFAULT_CORS_HOST}`, // Replace * with the appropriate origin(s)
"Access-Control-Allow-Methods": "GET, POST, OPTIONS", // Add other allowed methods if needed
"Access-Control-Allow-Headers": "*", // Replace * with the appropriate headers
"Access-Control-Max-Age": "86400", // Adjust the max age value if needed
},
},
);
}

const [protocol, ...subpath] = params.path;
Expand Down
10 changes: 8 additions & 2 deletions app/components/exporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,12 @@ export function MarkdownPreviewer(props: {
copyToClipboard(mdText);
};
const download = () => {
downloadAs(mdText, `${props.topic}.md`);
const blob = new Blob([mdText], { type: "text/markdown" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `${props.topic}.md`;
link.click();
};
return (
<>
Expand Down Expand Up @@ -599,7 +604,8 @@ export function JsonPreviewer(props: {
copyToClipboard(minifiedJson);
};
const download = () => {
downloadAs(JSON.stringify(msgs), `${props.topic}.json`);
//This will automatically generate JSON files without the need to include the ".json" extension.
downloadAs(msgs, `${props.topic}`);
};

return (
Expand Down
12 changes: 5 additions & 7 deletions app/components/mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ export function MaskPage() {
const closeMaskModal = () => setEditingMaskId(undefined);

const downloadAll = () => {
downloadAs(JSON.stringify(masks.filter((v) => !v.builtin)), FileName.Masks);
downloadAs(
masks.filter((v) => !v.builtin),
FileName.Masks,
);
};

const importFromFile = () => {
Expand Down Expand Up @@ -583,12 +586,7 @@ export function MaskPage() {
text={Locale.Mask.EditModal.Download}
key="export"
bordered
onClick={() =>
downloadAs(
JSON.stringify(editingMask),
`${editingMask.name}.json`,
)
}
onClick={() => downloadAs(editingMask, `${editingMask.name}`)}
/>,
<IconButton
key="copy"
Expand Down
107 changes: 99 additions & 8 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ function CheckButton() {
const syncStore = useSyncStore();

const couldCheck = useMemo(() => {
return syncStore.coundSync();
return syncStore.countSync();
}, [syncStore]);

const [checkState, setCheckState] = useState<
Expand All @@ -285,10 +285,8 @@ function CheckButton() {
<LoadingIcon />
) : checkState === "success" ? (
<CloudSuccessIcon />
) : checkState === "failed" ? (
<CloudFailIcon />
) : (
<ConnectionIcon />
<CloudFailIcon />
)
}
></IconButton>
Expand Down Expand Up @@ -366,12 +364,29 @@ function SyncConfigModal(props: { onClose?: () => void }) {
></input>
</ListItem>
) : null}
<ListItem
title={Locale.Settings.Sync.Config.AccessControl.Title}
subTitle={Locale.Settings.Sync.Config.AccessControl.SubTitle}
>
<input
type="checkbox"
checked={syncStore.enableAccessControl}
onChange={(e) => {
syncStore.update(
(config) =>
(config.enableAccessControl = e.currentTarget.checked),
);
}}
></input>
</ListItem>
</List>

{syncStore.provider === ProviderType.WebDAV && (
<>
<List>
<ListItem title={Locale.Settings.Sync.Config.WebDav.Endpoint}>
<ListItem
title={Locale.Settings.Sync.Config.WebDav.Endpoint.Name}
>
<input
type="text"
value={syncStore.webdav.endpoint}
Expand All @@ -384,7 +399,9 @@ function SyncConfigModal(props: { onClose?: () => void }) {
></input>
</ListItem>

<ListItem title={Locale.Settings.Sync.Config.WebDav.UserName}>
<ListItem
title={Locale.Settings.Sync.Config.WebDav.UserName.Name}
>
<input
type="text"
value={syncStore.webdav.username}
Expand All @@ -396,7 +413,9 @@ function SyncConfigModal(props: { onClose?: () => void }) {
}}
></input>
</ListItem>
<ListItem title={Locale.Settings.Sync.Config.WebDav.Password}>
<ListItem
title={Locale.Settings.Sync.Config.WebDav.Password.Name}
>
<PasswordInput
value={syncStore.webdav.password}
onChange={(e) => {
Expand All @@ -407,6 +426,21 @@ function SyncConfigModal(props: { onClose?: () => void }) {
}}
></PasswordInput>
</ListItem>
<ListItem
title={Locale.Settings.Sync.Config.WebDav.FileName.Name}
subTitle={Locale.Settings.Sync.Config.WebDav.FileName.SubTitle}
>
<input
type="text"
value={syncStore.webdav.filename}
onChange={(e) => {
syncStore.update(
(config) =>
(config.webdav.filename = e.currentTarget.value),
);
}}
></input>
</ListItem>
</List>
</>
)}
Expand All @@ -416,6 +450,63 @@ function SyncConfigModal(props: { onClose?: () => void }) {
<ListItem title={Locale.WIP}></ListItem>
</List>
)}
{syncStore.provider === ProviderType.GitHubGist && (
<>
<List>
<ListItem
title={Locale.Settings.Sync.Config.GithubGist.GistID.Name}
subTitle={
Locale.Settings.Sync.Config.GithubGist.GistID.SubTitle
}
>
<input
type="text"
value={syncStore.githubGist.gistId}
onChange={(e) => {
syncStore.update(
(config) =>
(config.githubGist.gistId = e.currentTarget.value),
);
}}
></input>
</ListItem>

<ListItem
title={Locale.Settings.Sync.Config.GithubGist.FileName.Name}
subTitle={
Locale.Settings.Sync.Config.GithubGist.FileName.SubTitle
}
>
<input
type="text"
value={syncStore.githubGist.filename}
onChange={(e) => {
syncStore.update(
(config) =>
(config.githubGist.filename = e.currentTarget.value),
);
}}
></input>
</ListItem>
<ListItem
title={Locale.Settings.Sync.Config.GithubGist.AccessToken.Name}
subTitle={
Locale.Settings.Sync.Config.GithubGist.AccessToken.SubTitle
}
>
<PasswordInput
value={syncStore.githubGist.token}
onChange={(e) => {
syncStore.update(
(config) =>
(config.githubGist.token = e.currentTarget.value),
);
}}
></PasswordInput>
</ListItem>
</List>
</>
)}
</Modal>
</div>
);
Expand All @@ -427,7 +518,7 @@ function SyncItems() {
const promptStore = usePromptStore();
const maskStore = useMaskStore();
const couldSync = useMemo(() => {
return syncStore.coundSync();
return syncStore.countSync();
}, [syncStore]);

const [showSyncConfigModal, setShowSyncConfigModal] = useState(false);
Expand Down
6 changes: 3 additions & 3 deletions app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export enum ApiPath {
export enum SlotID {
AppBody = "app-body",
}

// This will automatically generate JSON files without the need to include the ".json" extension.
export enum FileName {
Masks = "masks.json",
Prompts = "prompts.json",
Masks = "masks",
Prompts = "prompts",
}

export enum StoreKey {
Expand Down
39 changes: 36 additions & 3 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,43 @@ const cn = {
SubTitle: "仅适用于本项目自带的跨域代理",
},

AccessControl: {
Title: "启用覆盖访问控制",
SubTitle: "仅适用于覆盖访问控制设置,例如访问代码",
},

WebDav: {
Endpoint: "WebDAV 地址",
UserName: "用户名",
Password: "密码",
Endpoint: {
Name: "WebDav 终端点",
SubTitle: "配置 WebDav 终端点",
},
UserName: {
Name: "用户名",
SubTitle: "配置用户名",
},
Password: {
Name: "密码",
SubTitle: "配置密码",
},
FileName: {
Name: "文件名",
SubTitle: "文件名,例如:backtrackz.json(必须是 JSON 文件)",
},
},
GithubGist: {
GistID: {
Name: "Github Gist ID",
SubTitle:
"您的 Gist ID 位置,例如:gist.github.com/H0llyW00dzZ/<gistid>/等。复制 <gistid> 并粘贴到这里。",
},
FileName: {
Name: "文件名",
SubTitle: "文件名,例如:backtrackz.json(必须是 JSON 文件)",
},
AccessToken: {
Name: "访问令牌",
SubTitle: "确保您具有同步的权限。在那里启用私有和公开。",
},
},
},

Expand Down
43 changes: 39 additions & 4 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,46 @@ const en: LocaleType = {
SubTitle:
"Only applicable to the built-in CORS proxy for this project",
},

AccessControl: {
Title: "Enable Overwrite Access Control",
SubTitle:
"Only applicable to the overwrite access control setting such as an access code",
},
WebDav: {
Endpoint: "WebDAV Endpoint",
UserName: "User Name",
Password: "Password",
Endpoint: {
Name: "WebDav Endpoint",
SubTitle: "Configure the WebDav Endpoint",
},
UserName: {
Name: "User Name",
SubTitle: "Configure the User Name",
},
Password: {
Name: "Password",
SubTitle: "Configure the Password",
},
FileName: {
Name: "File Name",
SubTitle:
"File Name, for example: backtrackz.json (must be a JSON file)",
},
},
GithubGist: {
GistID: {
Name: "Github Gist ID",
SubTitle:
"Your Gist ID location, for example: gist.github.com/H0llyW00dzZ/<gistid>/etc. copy then paste the <gistid> here.",
},
FileName: {
Name: "File Name",
SubTitle:
"File Name, for example: backtrackz.json (must be a JSON file)",
},
AccessToken: {
Name: "Access Token",
SubTitle:
"Make sure you have permission for syncing. Enable Private & Public there.",
},
},
},

Expand Down
Loading