Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

monograph: add /api/og endpoint redirection for old og links

Abdullah Attaac92f3685f88
diff --git a/apps/monograph/app/routes/api.og.ts b/apps/monograph/app/routes/api.og.ts
new file mode 100644
index 000000000..dc80c5ad6
--- /dev/null
+++ b/apps/monograph/app/routes/api.og.ts
@@ -0,0 +1,26 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import { LoaderFunctionArgs } from "@remix-run/node";
+
+export async function loader({ request }: LoaderFunctionArgs) {
+ const url = new URL(request.url);
+ url.pathname += ".png";
+ return Response.redirect(url, 308);
+}
diff --git a/apps/monograph/app/utils/storage/kv.ts b/apps/monograph/app/utils/storage/kv.ts
index 7bcefe72c..946f2f050 100644
--- a/apps/monograph/app/utils/storage/kv.ts
+++ b/apps/monograph/app/utils/storage/kv.ts
@@ -36,10 +36,17 @@ const WorkersKV = new WorkersKVREST({
export async function read<T>(key: string, fallback: T): Promise<T> {
try {
- const response = (await WorkersKV.readKey({
+ const response = await WorkersKV.readKey({
key
- })) as unknown as string;
- return response ? JSON.parse(response) || fallback : fallback;
+ });
+ if (!response.success) {
+ console.error("failed:", response.errors);
+ return fallback;
+ }
+ return (
+ JSON.parse(typeof response === "string" ? response : response.result) ||
+ fallback
+ );
} catch (e) {
console.error(e);
return fallback;
@@ -52,3 +59,5 @@ export async function write<T>(key: string, data: T) {
value: JSON.stringify(data)
});
}
+
+read("spam-cache", "default").then(console.log);