chore: middleware
This commit is contained in:
parent
45b6e113b5
commit
3ab6f77a69
18 changed files with 180 additions and 36 deletions
26
src/utils/data/bookByUrl.js
Normal file
26
src/utils/data/bookByUrl.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { createClient } from "@supabase/supabase-js";
|
||||
|
||||
const SUPABASE_URL = import.meta.env.SUPABASE_URL;
|
||||
const SUPABASE_KEY = import.meta.env.SUPABASE_KEY;
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);
|
||||
|
||||
const bookCache = {};
|
||||
|
||||
export async function fetchBookByUrl(url) {
|
||||
if (bookCache[url]) return bookCache[url];
|
||||
|
||||
const { data: book, error } = await supabase
|
||||
.from("optimized_books")
|
||||
.select("*")
|
||||
.eq("url", url)
|
||||
.limit(1);
|
||||
|
||||
if (error || !book) {
|
||||
console.error(`Error fetching book with URL ${url}:`, error);
|
||||
return null;
|
||||
}
|
||||
|
||||
bookCache[url] = book[0];
|
||||
|
||||
return book[0];
|
||||
}
|
Reference in a new issue