This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Original Reference: https://guseyn.com/posts/simple-jwt | |
| function payloadWithExpirationTime (payload, minutesFromNow) { | |
| let date = new Date() | |
| date.setMinutes(date.getMinutes() + minutesFromNow) | |
| payload.exp = date.getTime() | |
| return payload | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function validURL(string) { | |
| const pattern = new RegExp( | |
| "^(https?:\\/\\/)?" + // protocol | |
| "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name | |
| "((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address | |
| "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path | |
| "(\\?[;&a-z\\d%_.~+=-]*)?" + // query string | |
| "(\\#[-a-z\\d_]*)?$", | |
| "i" | |
| ); // fragment locator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const getThumbnail = (id, size = 300) => | |
| `https://drive.google.com/thumbnail?id=${id}&sz=${size}`; | |
| export const getIcon = (mimeType) => | |
| `https://drive-thirdparty.googleusercontent.com/256/type/${mimeType}`; | |
| export const getFile = (id) => `https://drive.google.com/uc?id=${id}`; | |
| const downloadFile = (id) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import objectHash from "object-hash"; | |
| const cacheTimeout = 60 * 60 * 1000 | |
| let store: Record<string, unknown> = {}; | |
| export function cache<A extends unknown[], B = unknown>( | |
| fn: (...args: A) => Promise<B>, | |
| key?: string // optional key for guaranteed uniqueness | |
| ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function useBoundingClientRect<T extends HTMLElement>() { | |
| const [rect, setRect] = useState<DOMRect | null>(null); | |
| const ref = useRef<T>(null); | |
| const update = useCallback(() => { | |
| if (ref.current) setRect(ref.current.getBoundingClientRect()); | |
| else setRect(null); | |
| }, []); | |
| useEffectOnce(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| "Adult", | |
| "Arts & Entertainment", | |
| "Autos & Vehicles", | |
| "Beauty & Fitness", | |
| "Books & Literature", | |
| "Business & Industrial", | |
| "Computers & Electronics", | |
| "Finance", | |
| "Food & Drink", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| "/Adult", | |
| "/Arts & Entertainment/Celebrities & Entertainment News", | |
| "/Arts & Entertainment/Other", | |
| "/Arts & Entertainment/Comics & Animation/Anime & Manga", | |
| "/Arts & Entertainment/Comics & Animation/Cartoons", | |
| "/Arts & Entertainment/Comics & Animation/Comics", | |
| "/Arts & Entertainment/Comics & Animation/Other", | |
| "/Arts & Entertainment/Entertainment Industry/Film & TV Industry", | |
| "/Arts & Entertainment/Entertainment Industry/Recording Industry", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { openai } from "@ai-sdk/openai"; | |
| import { streamText } from "ai"; | |
| export function OPTIONS() { | |
| return new Response("OK", { | |
| status: 200, | |
| headers: { | |
| "Access-Control-Allow-Credentials": "true", | |
| "Access-Control-Allow-Origin": "*", | |
| "Access-Control-Allow-Methods": "GET,OPTIONS,PATCH,DELETE,POST,PUT", |