diff --git a/package-lock.json b/package-lock.json
index 4c09196..919101d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -10,7 +10,7 @@
"license": "MIT",
"dependencies": {
"@hono/sentry": "^1.0.1",
- "hono": "^3.12.12"
+ "hono": "^4.2.9"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240423.0",
@@ -4991,9 +4991,9 @@
}
},
"node_modules/hono": {
- "version": "3.12.12",
- "resolved": "https://registry.npmjs.org/hono/-/hono-3.12.12.tgz",
- "integrity": "sha512-5IAMJOXfpA5nT+K0MNjClchzz0IhBHs2Szl7WFAhrFOsbtQsYmNynFyJRg/a3IPsmCfxcrf8txUGiNShXpK5Rg==",
+ "version": "4.2.9",
+ "resolved": "https://registry.npmjs.org/hono/-/hono-4.2.9.tgz",
+ "integrity": "sha512-59FAv52UxDWUt/NlC0NzrRCjeVCThUnVlqlrKYm+k80XujBu6uJwBIa5gACKKZWobjA0MJ6Vds0I3URKf383Cw==",
"engines": {
"node": ">=16.0.0"
}
diff --git a/package.json b/package.json
index 59ccb3b..3b0df53 100644
--- a/package.json
+++ b/package.json
@@ -39,6 +39,6 @@
},
"dependencies": {
"@hono/sentry": "^1.0.1",
- "hono": "^3.12.12"
+ "hono": "^4.2.9"
}
}
diff --git a/src/caches.ts b/src/caches.ts
index a9c1229..2321e9a 100644
--- a/src/caches.ts
+++ b/src/caches.ts
@@ -90,11 +90,11 @@ export const cacheMiddleware = (): MiddlewareHandler => async (c, next) => {
/* We properly state our OPTIONS when asked */
case 'OPTIONS':
c.header('allow', Constants.RESPONSE_HEADERS.allow);
+ c.body(null);
c.status(204);
return;
default:
- c.status(405);
if (returnAsJson) return c.json('');
- return c.html('');
+ return c.html('', 405);
}
};
diff --git a/src/embed/status.ts b/src/embed/status.ts
index 4205a92..99492f8 100644
--- a/src/embed/status.ts
+++ b/src/embed/status.ts
@@ -9,6 +9,7 @@ import { renderVideo } from '../render/video';
import { renderInstantView } from '../render/instantview';
import { constructTwitterThread } from '../providers/twitter/conversation';
import { Experiment, experimentCheck } from '../experiments';
+import { StatusCode } from 'hono/utils/http-status';
export const returnError = (c: Context, error: string): Response => {
return c.html(
@@ -78,7 +79,7 @@ export const handleStatus = async (
/* Catch this request if it's an API response */
if (flags?.api) {
- c.status(api.code);
+ c.status(api.code as StatusCode);
// Add every header from Constants.API_RESPONSE_HEADERS
for (const [header, value] of Object.entries(Constants.API_RESPONSE_HEADERS)) {
c.header(header, value);
diff --git a/src/experiments.ts b/src/experiments.ts
index 12a442c..50d6285 100644
--- a/src/experiments.ts
+++ b/src/experiments.ts
@@ -42,7 +42,7 @@ const Experiments: { [key in Experiment]: ExperimentConfig } = {
[Experiment.IV_FORCE_THREAD_UNROLL]: {
name: 'IV force thread unroll',
description: 'Force thread unroll for Telegram Instant View',
- percentage: 0.25
+ percentage: 1
}
};
diff --git a/src/providers/twitter/conversation.ts b/src/providers/twitter/conversation.ts
index c61cc60..5aff2b6 100644
--- a/src/providers/twitter/conversation.ts
+++ b/src/providers/twitter/conversation.ts
@@ -4,6 +4,7 @@ import { buildAPITwitterStatus } from './processor';
import { Experiment, experimentCheck } from '../../experiments';
import { isGraphQLTwitterStatus } from '../../helpers/graphql';
import { Context } from 'hono';
+import { StatusCode } from 'hono/utils/http-status';
const writeDataPoint = (
c: Context,
@@ -579,10 +580,9 @@ export const threadAPIProvider = async (c: Context) => {
const processedResponse = await constructTwitterThread(id, true, c, undefined);
- c.status(processedResponse.code);
// Add every header from Constants.API_RESPONSE_HEADERS
for (const [header, value] of Object.entries(Constants.API_RESPONSE_HEADERS)) {
c.header(header, value);
}
- return c.json(processedResponse);
+ return c.json(processedResponse, processedResponse.code as StatusCode);
};
diff --git a/src/realms/api/hit.ts b/src/realms/api/hit.ts
index 4d8db8e..99822c2 100644
--- a/src/realms/api/hit.ts
+++ b/src/realms/api/hit.ts
@@ -5,7 +5,7 @@ export const linkHitRequest = async (c: Context) => {
const userAgent = c.req.header('User-Agent') || '';
if (userAgent.includes('Telegram')) {
- c.status(403);
+ return c.text('', 403);
}
// If param `url` exists, 302 redirect to it
if (typeof c.req.query('url') === 'string') {
diff --git a/src/realms/api/router.ts b/src/realms/api/router.ts
index da08d56..d0d067e 100644
--- a/src/realms/api/router.ts
+++ b/src/realms/api/router.ts
@@ -9,11 +9,13 @@ export const api = new Hono();
api.use('*', async (c, next) => {
if (!c.req.header('user-agent')) {
- c.status(401);
- return c.json({
- error:
- "You must identify yourself with a User-Agent header in order to use the FixTweet API. We recommend using a descriptive User-Agent header to identify your app, such as 'MyAwesomeBot/1.0 (+http://example.com/myawesomebot)'. We don't track or save what kinds of data you are pulling, but you may be blocked if you send too many requests from an unidentifiable user agent."
- });
+ return c.json(
+ {
+ error:
+ "You must identify yourself with a User-Agent header in order to use the FixTweet API. We recommend using a descriptive User-Agent header to identify your app, such as 'MyAwesomeBot/1.0 (+http://example.com/myawesomebot)'. We don't track or save what kinds of data you are pulling, but you may be blocked if you send too many requests from an unidentifiable user agent."
+ },
+ 401
+ );
}
await next();
});
diff --git a/src/realms/twitter/routes/oembed.ts b/src/realms/twitter/routes/oembed.ts
index c822b81..7cdb7af 100644
--- a/src/realms/twitter/routes/oembed.ts
+++ b/src/realms/twitter/routes/oembed.ts
@@ -28,7 +28,6 @@ export const oembed = async (c: Context) => {
};
c.header('content-type', 'application/json');
- c.status(200);
/* Stringify and send it on its way! */
- return c.text(JSON.stringify(data));
+ return c.text(JSON.stringify(data), 200);
};
diff --git a/src/realms/twitter/routes/redirects.ts b/src/realms/twitter/routes/redirects.ts
index cfff1f2..fc711b8 100644
--- a/src/realms/twitter/routes/redirects.ts
+++ b/src/realms/twitter/routes/redirects.ts
@@ -25,12 +25,11 @@ export const setRedirectRequest = async (c: Context) => {
/* Check that origin either does not exist or is in our domain list */
const origin = c.req.header('origin');
if (origin && !Constants.STANDARD_DOMAIN_LIST.includes(new URL(origin).hostname)) {
- c.status(403);
-
return c.html(
Strings.MESSAGE_HTML.format({
message: `Failed to set base redirect: Your request seems to be originating from another domain, please open this up in a new tab if you are trying to set your base redirect.`
- })
+ }),
+ 403
);
}
@@ -46,11 +45,11 @@ export const setRedirectRequest = async (c: Context) => {
'content-security-policy',
`frame-ancestors ${Constants.STANDARD_DOMAIN_LIST.join(' ')};`
);
- c.status(200);
return c.html(
Strings.MESSAGE_HTML.format({
message: `Your base redirect has been cleared. To set one, please pass along the url
parameter.`
- })
+ }),
+ 200
);
}
@@ -71,11 +70,11 @@ export const setRedirectRequest = async (c: Context) => {
'content-security-policy',
`frame-ancestors ${Constants.STANDARD_DOMAIN_LIST.join(' ')};`
);
- c.status(200);
return c.html(
Strings.MESSAGE_HTML.format({
message: `Your URL does not appear to be well-formed. Example: ?url=https://nitter.net`
- })
+ }),
+ 200
);
}
diff --git a/src/realms/twitter/routes/status.ts b/src/realms/twitter/routes/status.ts
index dea9c21..1337e0c 100644
--- a/src/realms/twitter/routes/status.ts
+++ b/src/realms/twitter/routes/status.ts
@@ -131,8 +131,7 @@ export const statusRequest = async (c: Context) => {
return statusResponse;
} else {
/* Somehow handleStatus sent us nothing. This should *never* happen, but we have a case for it. */
- c.status(500);
- return c.text(Strings.ERROR_UNKNOWN);
+ return c.text(Strings.ERROR_UNKNOWN, 500);
}
} else {
/* A human has clicked a fxtwitter.com/:screen_name/status/:id link!
diff --git a/src/render/instantview.ts b/src/render/instantview.ts
index c42dda4..280925b 100644
--- a/src/render/instantview.ts
+++ b/src/render/instantview.ts
@@ -302,8 +302,8 @@ export const renderInstantView = (properties: RenderProperties): ResponseInstruc
let previousThreadPieceAuthor: string | null = null;
let originalAuthor: string | null = null;
-
- const useThread = thread?.thread ?? [ thread?.status ]
+
+ const useThread = thread?.thread ?? [thread?.status];
if (!status) {
throw new Error('Status is undefined');
@@ -339,7 +339,8 @@ export const renderInstantView = (properties: RenderProperties): ResponseInstruc
View full thread