Skip to content

Commit e5eb224

Browse files
authored
Merge pull request #3 from timelessco/retry-screenshot
Retry screenshot
2 parents 21e87e6 + a77cac5 commit e5eb224

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

src/app/page.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ export default function Home() {
2525
const intervalTimer = startDuration();
2626
try {
2727
setLoading(true);
28-
const res = await fetch(`/try?url=${url}`, {
29-
next: { revalidate: 10 },
30-
});
28+
const res = await fetch(`/try?url=${url}`);
3129
const data = await res.blob();
3230
setImgUrl(URL.createObjectURL(data));
3331
} catch (error) {
@@ -43,8 +41,15 @@ export default function Home() {
4341

4442
function startDuration() {
4543
return setInterval(() => {
46-
setDuration((prev) => Number((prev + 0.2).toFixed(1)));
47-
}, 200);
44+
setDuration((prev) => {
45+
const newDuration = Number((prev + 1).toFixed(1));
46+
if (newDuration >= 300) {
47+
clearInterval(intervalTimer);
48+
return 300;
49+
}
50+
return newDuration;
51+
});
52+
}, 1000);
4853
}
4954

5055
return (
@@ -59,14 +64,8 @@ export default function Home() {
5964
Try screenshot
6065
</h3>
6166
<p className="text-md mt-3">
62-
Thursday, May 9th 2024 Vercel Functions for Hobby can now run up to
63-
60 seconds{" "}
64-
<a
65-
href="https://vercel.com/changelog/vercel-functions-for-hobby-can-now-run-up-to-60-seconds"
66-
className="text-blue-500 underline"
67-
>
68-
detail
69-
</a>
67+
can now run up to
68+
300 seconds{" "}
7069
</p>
7170
</div>
7271
<form onSubmit={handleSubmit}>

src/app/try/route.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
remoteExecutablePath,
1010
} from "@/utils/utils.js";
1111

12-
export const maxDuration = 60;
12+
export const maxDuration = 300;//sec
1313
export const dynamic = "force-dynamic";
1414

1515
const chromium = require("@sparticuz/chromium-min");
@@ -81,7 +81,7 @@ export async function GET(request) {
8181
try {
8282
const response = await page.goto(urlStr, {
8383
waitUntil: "networkidle2",
84-
timeout: 60000,
84+
timeout: 300_000,
8585
});
8686

8787
if (!response || !response.ok()) {
@@ -104,7 +104,7 @@ export async function GET(request) {
104104
);
105105
});
106106

107-
await new Promise((res) => setTimeout(res, 6000));
107+
// await new Promise((res) => setTimeout(res, 6000));
108108
await cfCheck(page);
109109

110110
for (let shotTry = 1; shotTry <= 2; shotTry++) {

src/utils/cfCheck.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async function cfCheck(page) {
3232
const input = document.getElementById(`cf-chl-widget-${widgetId}_response`);
3333
return input && input.value && input.value !== "";
3434
},
35-
{ timeout: 15000 },
35+
{ timeout: 300_000 },
3636
id
3737
);
3838

vercel.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"functions": {
3+
"app/try/route.js": {
4+
"maxDuration": 300
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)