将安装包链接改为从apollo获取;增加cookies时效

This commit is contained in:
yezian 2024-11-18 16:13:54 +08:00
parent 39c4fba3df
commit 51e054cd29
3 changed files with 49 additions and 13 deletions

View File

@ -10,6 +10,8 @@ import IosInstallStepModal from "@/components/IosInstallStepModal/page";
export default function Download({ params }) {
const [deviceType, setDeviceType] = useState("");
const [installInfo, setInstallInfo] = useState({});
useEffect(() => {
const userAgent = navigator.userAgent;
//
@ -20,6 +22,37 @@ export default function Download({ params }) {
} else {
setDeviceType("pc");
}
const handleIosInstallButtonVisibility = async () => {
try {
const base = baseRequest();
const body = {
...base,
};
const signature = generateSignature(body);
const _response = await fetch(
`/api/app/install_info?signature=${signature}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
}
);
const _data = await _response.json();
if (_data.ret === -1) {
Toast.show({
content: _data.msg,
});
return;
}
setInstallInfo(_data.data);
} catch (error) {
console.error(error);
}
};
handleIosInstallButtonVisibility();
}, []);
//
@ -172,16 +205,18 @@ export default function Download({ params }) {
)}
</div>
<div className="flex flex-col items-center">
{deviceType !== "pc" && (
{(deviceType === "Android" ||
(deviceType === "ios" &&
installInfo?.is_ios_install_button_visible === 1)) && (
<div
className="btn bg-gradient-to-r from-[#FF668B] to-[#FF66F0] rounded-full text-white text-lg font-medium w-64 h-14"
className={`btn bg-gradient-to-r from-[#FF668B] to-[#FF66F0] rounded-full text-white text-lg font-medium w-64 h-14`}
onClick={() => {
copyInviter();
if (deviceType === "ios") setIsIosInstallStepModalVisible(true);
const url =
deviceType === "ios"
? "itms-services://?action=download-manifest&url=https://filecdntx01.tiefen.fun/appdownload/ironfans.plist"
: "https://filecdntx01.tiefen.fun/appdownload/ironfans1.5.2.apk";
? `itms-services://?action=download-manifest&url=${installInfo?.ios_url}`
: installInfo?.android_url;
window.location.href = url;
if (deviceType === "ios") {
setIsIosInstallStepModalVisible(true);

View File

@ -10,8 +10,8 @@ import { generateSignature } from "@/utils/crypto";
export default function Home() {
const [deviceType, setDeviceType] = useState("");
const [isIosInstallButtonVisible, setIsIosInstallButtonVisible] =
useState(true);
const [installInfo, setInstallInfo] = useState({});
useEffect(() => {
const userAgent = navigator.userAgent;
//
@ -31,7 +31,7 @@ export default function Home() {
};
const signature = generateSignature(body);
const _response = await fetch(
`/api/app/is_ios_install_button_visible?signature=${signature}`,
`/api/app/install_info?signature=${signature}`,
{
method: "POST",
headers: {
@ -47,7 +47,7 @@ export default function Home() {
});
return;
}
if (_data.data === 0) setIsIosInstallButtonVisible(false);
setInstallInfo(_data.data);
} catch (error) {
console.error(error);
}
@ -203,7 +203,8 @@ export default function Home() {
</div>
)}
{(deviceType === "Android" ||
(deviceType === "ios" && isIosInstallButtonVisible)) && (
(deviceType === "ios" &&
installInfo?.is_ios_install_button_visible === 1)) && (
<div
className={`btn ${
deviceType === "ios"
@ -214,8 +215,8 @@ export default function Home() {
if (deviceType === "ios") setIsIosInstallStepModalVisible(true);
const url =
deviceType === "ios"
? "itms-services://?action=download-manifest&url=https://filecdntx01.tiefen.fun/appdownload/ironfans.plist"
: "https://filecdntx01.tiefen.fun/appdownload/ironfans1.5.2.apk";
? `itms-services://?action=download-manifest&url=${installInfo?.ios_url}`
: installInfo?.android_url;
window.location.href = url;
if (deviceType === "ios") {
setIsIosInstallStepModalVisible(true);

View File

@ -37,8 +37,8 @@ export async function checkAuth() {
}
export function signIn(data) {
setCookie("token", data.data.token);
setCookie("account", data.data.account);
setCookie("token", data.data.token, { maxAge: 60 * 60 * 24 * 365 * 10 });
setCookie("account", data.data.account, { maxAge: 60 * 60 * 24 * 365 * 10 });
}
export function signOut() {