Compare commits
23 Commits
696082250d
...
feat/deno-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47d32d68c7
|
||
|
|
c74a19b527
|
||
|
|
8d712322c0
|
||
|
|
694feb083d
|
||
|
|
e55f787a29
|
||
|
e65938ecc2
|
|||
|
|
7dda2dd60d
|
||
|
|
7ad08daf80
|
||
|
|
92126882b6
|
||
|
|
655fc648e6
|
||
|
|
6c6b69a46a
|
||
|
|
97c5b7f93c
|
||
|
|
bf3483019c
|
||
|
|
5502c17c28
|
||
|
|
581f1c1926
|
||
|
|
7664abe089
|
||
|
|
bed7d1a11b
|
||
|
|
56a104c8b9
|
||
|
|
3103ed19fb
|
||
|
|
fea9b69d4d
|
||
|
|
bb4e895770
|
||
|
|
28e9de4dc8
|
||
|
|
ebb897dca4
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,3 @@
|
|||||||
# dotenv environment variable files
|
|
||||||
.env
|
.env
|
||||||
.env.development.local
|
.env.development.local
|
||||||
.env.test.local
|
.env.test.local
|
||||||
@@ -10,3 +9,4 @@ data-dev/
|
|||||||
_fresh/
|
_fresh/
|
||||||
node_modules/
|
node_modules/
|
||||||
mise.toml
|
mise.toml
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM denoland/deno:2.5.4 AS build
|
FROM denoland/deno:2.6.4 AS build
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
curl ffmpeg && \
|
curl ffmpeg && \
|
||||||
@@ -15,11 +15,11 @@ COPY . .
|
|||||||
ENV DATA_DIR=/app/data
|
ENV DATA_DIR=/app/data
|
||||||
|
|
||||||
RUN mkdir -p $DATA_DIR && \
|
RUN mkdir -p $DATA_DIR && \
|
||||||
deno install --allow-import --allow-ffi --allow-scripts=npm:sharp -e main.ts &&\
|
deno install --allow-import --allow-ffi -e main.ts &&\
|
||||||
sed -i -e 's/"deno"/"no-deno"/' node_modules/@libsql/client/package.json &&\
|
sed -i -e 's/"deno"/"no-deno"/' node_modules/@libsql/client/package.json &&\
|
||||||
|
deno install npm:@libsql/linux-x64-gnu &&\
|
||||||
deno task build
|
deno task build
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
CMD ["run", "-A", "main.ts"]
|
CMD ["task", "start"]
|
||||||
|
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -5,18 +5,13 @@ Started" guide here: https://fresh.deno.dev/docs/getting-started
|
|||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Make sure to install Deno: https://deno.land/manual/getting_started/installation
|
Make sure to install Deno:
|
||||||
|
https://docs.deno.com/runtime/getting_started/installation
|
||||||
|
|
||||||
Then start the project:
|
Then start the project in development mode:
|
||||||
|
|
||||||
```
|
```
|
||||||
deno task start
|
deno task dev
|
||||||
```
|
```
|
||||||
|
|
||||||
This will watch the project directory and restart as necessary.
|
This will watch the project directory and restart as necessary.
|
||||||
|
|
||||||
## FIX
|
|
||||||
|
|
||||||
```
|
|
||||||
sed -i -e 's/"deno"/"no-deno"/' node_modules/@libsql/client/package.json
|
|
||||||
```
|
|
||||||
|
|||||||
1
assets/styles.css
Normal file
1
assets/styles.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
2
client.ts
Normal file
2
client.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// Import CSS files here for hot module reloading to work.
|
||||||
|
import "./assets/styles.css";
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
import { JSX } from "preact";
|
import { ButtonHTMLAttributes } from "preact";
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
|
||||||
|
|
||||||
export function Button(props: JSX.HTMLAttributes<HTMLButtonElement>) {
|
export function Button(props: ButtonHTMLAttributes<HTMLButtonElement>) {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
{...props}
|
{...props}
|
||||||
disabled={!IS_BROWSER || props.disabled}
|
class={`cursor-pointer px-2 py-1 ${props.class ? props.class : ""}`}
|
||||||
class={`px-2 py-1 ${props.class ? props.class : " "}`}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { isYoutubeLink } from "@lib/string.ts";
|
import { isYoutubeLink } from "@lib/string.ts";
|
||||||
import { IconBrandYoutube } from "@components/icons.tsx";
|
import { IconBrandYoutube } from "@components/icons.tsx";
|
||||||
import { SmallRating } from "@components/Rating.tsx";
|
import { SmallRating } from "@components/Rating.tsx";
|
||||||
import { Link } from "@islands/Link.tsx";
|
|
||||||
import { parseRating } from "@lib/helpers.ts";
|
import { parseRating } from "@lib/helpers.ts";
|
||||||
import { GenericResource, getNameOfResource } from "@lib/marka/schema.ts";
|
import { GenericResource, getNameOfResource } from "@lib/marka/schema.ts";
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ export function Card(
|
|||||||
rating?: number;
|
rating?: number;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const backgroundStyle: preact.JSX.CSSProperties = {
|
const backgroundStyle: preact.CSSProperties = {
|
||||||
backgroundSize: "cover",
|
backgroundSize: "cover",
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
};
|
};
|
||||||
@@ -36,7 +35,7 @@ export function Card(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<a
|
||||||
href={link}
|
href={link}
|
||||||
style={backgroundStyle}
|
style={backgroundStyle}
|
||||||
data-thumb={thumbhash}
|
data-thumb={thumbhash}
|
||||||
@@ -88,7 +87,7 @@ export function Card(
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div class="absolute inset-x-0 bottom-0 h-3/4" />
|
<div class="absolute inset-x-0 bottom-0 h-3/4" />
|
||||||
</Link>
|
</a>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,67 +1,5 @@
|
|||||||
import { Signal, useSignal } from "@preact/signals";
|
import { Signal, useSignal } from "@preact/signals";
|
||||||
import { useId, useState } from "preact/hooks";
|
import { useId } from "preact/hooks";
|
||||||
|
|
||||||
interface CheckboxProps {
|
|
||||||
label: string;
|
|
||||||
isChecked?: boolean;
|
|
||||||
onChange: (isChecked: boolean) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Checkbox2: preact.FunctionalComponent<CheckboxProps> = (
|
|
||||||
{ label, isChecked = false, onChange },
|
|
||||||
) => {
|
|
||||||
const [checked, setChecked] = useState(isChecked);
|
|
||||||
|
|
||||||
const toggleCheckbox = () => {
|
|
||||||
const newChecked = !checked;
|
|
||||||
setChecked(newChecked);
|
|
||||||
onChange(newChecked);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
class="flex items-center rounded-xl p-1 pl-4"
|
|
||||||
style={{ background: "var(--background)", color: "var(--foreground)" }}
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
<label
|
|
||||||
class="relative flex cursor-pointer items-center rounded-full p-3"
|
|
||||||
for="checkbox"
|
|
||||||
data-ripple-dark="true"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
class="before:content[''] peer relative h-5 w-5 cursor-pointer appearance-none rounded-md border border-blue-gray-200 transition-all before:absolute before:top-2/4 before:left-2/4 before:block before:h-12 before:w-12 before:-translate-y-2/4 before:-translate-x-2/4 before:rounded-full before:bg-blue-gray-500 before:opacity-0 before:transition-opacity hover:before:opacity-10"
|
|
||||||
id="checkbox"
|
|
||||||
checked
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
class={`pointer-events-none absolute top-2/4 left-2/4 -translate-y-2/4 -translate-x-2/4 text-white opacity-${
|
|
||||||
checked ? 100 : 0
|
|
||||||
} transition-opacity`}
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
class="h-3.5 w-3.5"
|
|
||||||
viewBox="0 0 20 20"
|
|
||||||
fill="white"
|
|
||||||
stroke="currentColor"
|
|
||||||
stroke-width="1"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
fill-rule="evenodd"
|
|
||||||
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
|
|
||||||
clip-rule="evenodd"
|
|
||||||
>
|
|
||||||
</path>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const Checkbox = (
|
const Checkbox = (
|
||||||
{ label, checked = useSignal(false) }: {
|
{ label, checked = useSignal(false) }: {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { asset } from "$fresh/runtime.ts";
|
import { asset } from "fresh/runtime";
|
||||||
|
|
||||||
export const Emoji = (props: { class?: string; name: string }) => {
|
export const Emoji = (props: { class?: string; name: string }) => {
|
||||||
return props.name
|
return props.name
|
||||||
@@ -10,5 +10,5 @@ export const Emoji = (props: { class?: string; name: string }) => {
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
: <span>{props.name}</span>
|
: <span>{props.name}</span>
|
||||||
: <></>;
|
: null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { asset } from "$fresh/runtime.ts";
|
import { asset } from "fresh/runtime";
|
||||||
import * as CSS from "csstype";
|
|
||||||
|
|
||||||
interface ResponsiveAttributes {
|
interface ResponsiveAttributes {
|
||||||
srcset: string;
|
srcset: string;
|
||||||
@@ -38,7 +37,7 @@ const Image = (
|
|||||||
fill?: boolean;
|
fill?: boolean;
|
||||||
width?: number | string;
|
width?: number | string;
|
||||||
height?: number | string;
|
height?: number | string;
|
||||||
style?: CSS.HtmlAttributes;
|
style?: preact.CSSProperties;
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
const responsiveAttributes = generateResponsiveAttributes(
|
const responsiveAttributes = generateResponsiveAttributes(
|
||||||
@@ -47,6 +46,11 @@ const Image = (
|
|||||||
"/api/images",
|
"/api/images",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const hasDimensions = typeof props.width === "number" &&
|
||||||
|
typeof props.height === "number";
|
||||||
|
const sizes = hasDimensions ? "" : responsiveAttributes.sizes;
|
||||||
|
const srcset = hasDimensions ? "" : responsiveAttributes.srcset;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
@@ -62,8 +66,8 @@ const Image = (
|
|||||||
loading="lazy"
|
loading="lazy"
|
||||||
alt={props.alt}
|
alt={props.alt}
|
||||||
style={props.style}
|
style={props.style}
|
||||||
srcset={responsiveAttributes.srcset}
|
sizes={sizes}
|
||||||
sizes={responsiveAttributes.sizes}
|
srcset={srcset}
|
||||||
src={`/api/images?image=${asset(props.src)}${
|
src={`/api/images?image=${asset(props.src)}${
|
||||||
props.width ? `&width=${props.width}` : ""
|
props.width ? `&width=${props.width}` : ""
|
||||||
}${props.height ? `&height=${props.height}` : ""}`}
|
}${props.height ? `&height=${props.height}` : ""}`}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Head } from "$fresh/runtime.ts";
|
import { Head } from "fresh/runtime";
|
||||||
import { GenericResource, getNameOfResource } from "@lib/marka/schema.ts";
|
import { GenericResource, getNameOfResource } from "@lib/marka/schema.ts";
|
||||||
import { formatDate } from "@lib/string.ts";
|
import { formatDate } from "@lib/string.ts";
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ function generateJsonLd(resource: GenericResource): string {
|
|||||||
if (resource.content?.datePublished) {
|
if (resource.content?.datePublished) {
|
||||||
try {
|
try {
|
||||||
baseSchema.datePublished = formatDate(
|
baseSchema.datePublished = formatDate(
|
||||||
new Date(resource.content.datePublished),
|
resource.content.datePublished,
|
||||||
);
|
);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// Ignore invalid date
|
// Ignore invalid date
|
||||||
@@ -60,6 +60,7 @@ export function MetaTags({ resource }: { resource: GenericResource }) {
|
|||||||
/>
|
/>
|
||||||
<script
|
<script
|
||||||
type="application/ld+json"
|
type="application/ld+json"
|
||||||
|
// deno-lint-ignore react-no-danger
|
||||||
dangerouslySetInnerHTML={{ __html: jsonLd }}
|
dangerouslySetInnerHTML={{ __html: jsonLd }}
|
||||||
/>
|
/>
|
||||||
</Head>
|
</Head>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function Wrapper(
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={`flex justify-between flex-col relative w-full ${
|
class={`flex justify-between flex-col relative w-full ${
|
||||||
image ? "min-h-[400px]" : "min-h-[200px]"
|
image ? "min-h-100" : "min-h-50"
|
||||||
} rounded-3xl overflow-hidden`}
|
} rounded-3xl overflow-hidden`}
|
||||||
>
|
>
|
||||||
<HeroContext.Provider value={{ image }}>
|
<HeroContext.Provider value={{ image }}>
|
||||||
@@ -62,7 +62,7 @@ function Title(
|
|||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
{link &&
|
{link &&
|
||||||
<IconExternalLink />}
|
<IconExternalLink class="h-6 w-6" />}
|
||||||
</h2>
|
</h2>
|
||||||
</OuterTag>
|
</OuterTag>
|
||||||
);
|
);
|
||||||
@@ -110,7 +110,7 @@ function Subline(
|
|||||||
const ctx = useContext(HeroContext);
|
const ctx = useContext(HeroContext);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={`relative flex items-center z-10 flex gap-5 font-sm text-light mt-3`}
|
class={`relative items-center z-10 flex gap-5 font-sm text-light mt-3`}
|
||||||
style={{ color: ctx.image ? "#1F1F1F" : "white" }}
|
style={{ color: ctx.image ? "#1F1F1F" : "white" }}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { IconStar, IconStarFilled } from "@components/icons.tsx";
|
import { IconStar, IconStarFilled } from "@components/icons.tsx";
|
||||||
import { useSignal } from "@preact/signals";
|
import { Signal, useSignal } from "@preact/signals";
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
|
|
||||||
export const SmallRating = (
|
export const SmallRating = (
|
||||||
@@ -24,27 +24,30 @@ export const SmallRating = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const Rating = (
|
export const Rating = (
|
||||||
props: { max?: number; rating: number },
|
{ max, rating = useSignal(0) }: {
|
||||||
|
max?: number;
|
||||||
|
rating: Signal<number | undefined>;
|
||||||
|
},
|
||||||
) => {
|
) => {
|
||||||
const [rating, setRating] = useState(props.rating);
|
|
||||||
const [hover, setHover] = useState(0);
|
const [hover, setHover] = useState(0);
|
||||||
const max = useSignal(props.max || 5);
|
|
||||||
|
const ratingValue = rating.value || 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class="flex items-center gap-2 px-5 rounded-2xl bg-gray-200 z-10"
|
class="flex items-center gap-2 px-5 rounded-2xl bg-gray-200 z-10 h-full"
|
||||||
style={{ color: "var(--foreground)", background: "var(--background)" }}
|
style={{ color: "var(--foreground)", background: "var(--background)" }}
|
||||||
>
|
>
|
||||||
{Array.from({ length: max.value }).map((_, i) => {
|
{Array.from({ length: max || 5 }).map((_, i) => {
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
class={`cursor-pointer opacity-${
|
class={`cursor-pointer opacity-${
|
||||||
(i + 1) <= rating ? 100 : (i + 1) <= hover ? 20 : 100
|
(i + 1) <= ratingValue ? 100 : (i + 1) <= hover ? 20 : 100
|
||||||
}`}
|
}`}
|
||||||
onMouseOver={() => setHover(i + 1)}
|
onMouseOver={() => setHover(i + 1)}
|
||||||
onClick={() => setRating(i + 1)}
|
onClick={() => (rating.value = i + 1)}
|
||||||
>
|
>
|
||||||
{(i + 1) <= rating || (i + 1) <= hover
|
{(i + 1) <= ratingValue || (i + 1) <= hover
|
||||||
? <IconStarFilled class="w-4 h-4" />
|
? <IconStarFilled class="w-4 h-4" />
|
||||||
: <IconStar class="w-4 h-4" />}
|
: <IconStar class="w-4 h-4" />}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ export const Star = (
|
|||||||
>
|
>
|
||||||
{Array.from({ length: max }).map((_, i) => {
|
{Array.from({ length: max }).map((_, i) => {
|
||||||
if ((i + 1) <= rating) {
|
if ((i + 1) <= rating) {
|
||||||
return <IconStarFilled class="w-4 h-4" />;
|
return <IconStarFilled key={i} class="w-4 h-4" />;
|
||||||
}
|
}
|
||||||
return <IconStar class="w-4 h-4" />;
|
return <IconStar key={i} class="w-4 h-4" />;
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
export { default as IconStar } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/star.tsx";
|
export {
|
||||||
export { default as IconStarFilled } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/star-filled.tsx";
|
TbAlertCircle as IconAlertCircle,
|
||||||
export { default as IconExternalLink } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/external-link.tsx";
|
TbArrowLeft as IconArrowLeft,
|
||||||
export { default as IconArrowNarrowLeft } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/arrow-narrow-left.tsx";
|
TbArrowNarrowLeft as IconArrowNarrowLeft,
|
||||||
export { default as IconEdit } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/edit.tsx";
|
TbBrandYoutube as IconBrandYoutube,
|
||||||
export { default as IconArrowLeft } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/arrow-left.tsx";
|
TbCircleMinus as IconCircleMinus,
|
||||||
export { default as IconError404 } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/error-404.tsx";
|
TbCirclePlus as IconCirclePlus,
|
||||||
export { default as IconSquareRoundedPlus } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/square-rounded-plus.tsx";
|
TbEdit as IconEdit,
|
||||||
export { default as IconReportSearch } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/report-search.tsx";
|
TbError404 as IconError404,
|
||||||
export { default as IconRefresh } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/refresh.tsx";
|
TbExternalLink as IconExternalLink,
|
||||||
export { default as IconCirclePlus } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/circle-plus.tsx";
|
TbGhost as IconGhost,
|
||||||
export { default as IconCircleMinus } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/circle-minus.tsx";
|
TbLoader2 as IconLoader2,
|
||||||
export { default as IconLoader2 } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/loader-2.tsx";
|
TbLogin as IconLogin,
|
||||||
export { default as IconLogin } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/login.tsx";
|
TbLogout as IconLogout,
|
||||||
export { default as IconLogout } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/logout.tsx";
|
TbMenu2 as IconMenu2,
|
||||||
export { default as IconSearch } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/search.tsx";
|
TbRefresh as IconRefresh,
|
||||||
export { default as IconGhost } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/ghost.tsx";
|
TbReportSearch as IconReportSearch,
|
||||||
export { default as IconBrandYoutube } from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/brand-youtube.tsx";
|
TbSearch as IconSearch,
|
||||||
export { default as IconWand } from "https://deno.land/x/tabler_icons_tsx@0.0.5/tsx/wand.tsx";
|
TbSquareRoundedPlus as IconSquareRoundedPlus,
|
||||||
|
TbStar as IconStar,
|
||||||
|
TbStarFilled as IconStarFilled,
|
||||||
|
TbWand as IconWand,
|
||||||
|
} from "@preact-icons/tb";
|
||||||
|
|||||||
@@ -12,17 +12,25 @@ export type Props = {
|
|||||||
searchResults?: GenericResource[];
|
searchResults?: GenericResource[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getQFromUrl(u: string | URL): string | null {
|
||||||
|
try {
|
||||||
|
const _u = typeof u === "string" ? new URL(u) : u;
|
||||||
|
return _u?.searchParams.get("q");
|
||||||
|
} catch (_e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const MainLayout = (
|
export const MainLayout = (
|
||||||
{ children, url, context, searchResults }: Props,
|
{ children, url, context, searchResults }: Props,
|
||||||
) => {
|
) => {
|
||||||
const _url = typeof url === "string" ? new URL(url) : url;
|
const q = getQFromUrl(url);
|
||||||
const hasSearch = _url?.search?.includes("q=");
|
|
||||||
|
|
||||||
if (hasSearch) {
|
if (typeof q === "string") {
|
||||||
return (
|
return (
|
||||||
<Search
|
<Search
|
||||||
q={_url.searchParams.get("q") || ""}
|
|
||||||
{...context}
|
{...context}
|
||||||
|
q={q}
|
||||||
results={searchResults}
|
results={searchResults}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
10
compose.yml
10
compose.yml
@@ -4,10 +4,10 @@ services:
|
|||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app # Mount the local directory to /app in the container
|
- .:/app
|
||||||
working_dir: /app # Set the working directory inside the container to /app
|
working_dir: /app
|
||||||
command: run --env-file -A --watch=static/,routes/ dev.ts # Custom start command
|
command: deno task dev --host 0.0.0.0
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000" # Expose the container port
|
- "8000:8000"
|
||||||
environment:
|
environment:
|
||||||
- DATA_DIR=/app/data # Set the environment variable inside the container
|
- DATA_DIR=/app/data
|
||||||
|
|||||||
116
deno.json
116
deno.json
@@ -1,57 +1,99 @@
|
|||||||
{
|
{
|
||||||
"lock": false,
|
"nodeModulesDir": "manual",
|
||||||
"nodeModulesDir": "auto",
|
|
||||||
"unstable": ["cron"],
|
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
|
"check": "deno fmt --check . && deno lint . && deno check",
|
||||||
"dev": "deno run --env-file -A --watch=static/,routes/ dev.ts",
|
"dev": "vite",
|
||||||
"start": "deno run --env-file -A main.ts",
|
|
||||||
"db": "deno run --env-file -A npm:drizzle-kit",
|
"db": "deno run --env-file -A npm:drizzle-kit",
|
||||||
"build": "deno run -A dev.ts build",
|
"build": "vite build",
|
||||||
"preview": "deno run -A main.ts",
|
"start": "deno serve -A _fresh/server.js",
|
||||||
"update": "deno run -A -r https://fresh.deno.dev/update ."
|
"update": "deno run -A -r jsr:@fresh/update ."
|
||||||
},
|
},
|
||||||
"lint": { "rules": { "tags": ["fresh", "recommended"] } },
|
"lint": {
|
||||||
|
"rules": {
|
||||||
|
"tags": [
|
||||||
|
"fresh",
|
||||||
|
"recommended"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"**/_fresh/*"
|
||||||
|
],
|
||||||
"imports": {
|
"imports": {
|
||||||
"$fresh/": "https://deno.land/x/fresh@1.7.3/",
|
"@cmd-johnson/oauth2-client": "jsr:@cmd-johnson/oauth2-client@^2.0.0",
|
||||||
"@components": "./components",
|
"@components": "./components",
|
||||||
"@components/": "./components/",
|
"@components/": "./components/",
|
||||||
"@denosaurs/emoji": "jsr:@denosaurs/emoji@^0.3.1",
|
"@deno/gfm": "jsr:@deno/gfm@^0.11.0",
|
||||||
"@islands": "./islands",
|
"@islands": "./islands",
|
||||||
"@islands/": "./islands/",
|
"@islands/": "./islands/",
|
||||||
"@lib": "./lib",
|
"@lib": "./lib",
|
||||||
"@lib/": "./lib/",
|
"@lib/": "./lib/",
|
||||||
"@libsql/client": "npm:@libsql/client@^0.14.0",
|
"@/": "./",
|
||||||
"@openai/openai": "jsr:@openai/openai@^6.7.0",
|
"@libsql/client": "npm:@libsql/client@^0.17.0",
|
||||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
|
"@libsql/linux-x64-gnu": "npm:@libsql/linux-x64-gnu@^0.5.22",
|
||||||
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
|
"@openai/openai": "jsr:@openai/openai@^6.16.0",
|
||||||
"@std/http": "jsr:@std/http@^1.0.12",
|
"@preact-icons/tb": "jsr:@preact-icons/tb@^1.0.14",
|
||||||
"@std/yaml": "jsr:@std/yaml@^1.0.5",
|
"@std/http": "jsr:@std/http@^1.0.23",
|
||||||
"csstype": "npm:csstype@^3.1.3",
|
"@std/media-types": "jsr:@std/media-types@^1.1.0",
|
||||||
|
"@zaubrik/djwt": "jsr:@zaubrik/djwt@^3.0.2",
|
||||||
"defuddle": "npm:defuddle@^0.6.6",
|
"defuddle": "npm:defuddle@^0.6.6",
|
||||||
"drizzle-kit": "npm:drizzle-kit@^0.30.1",
|
"drizzle-kit": "npm:drizzle-kit@^0.31.8",
|
||||||
"drizzle-orm": "npm:drizzle-orm@^0.38.3",
|
"drizzle-orm": "npm:drizzle-orm@^0.45.1",
|
||||||
|
"fresh": "jsr:@fresh/core@^2.2.0",
|
||||||
"fuzzysort": "npm:fuzzysort@^3.1.0",
|
"fuzzysort": "npm:fuzzysort@^3.1.0",
|
||||||
"jsdom": "npm:jsdom@^24.1.3",
|
"gfm": "jsr:@deno/gfm@0.11.0",
|
||||||
|
"jsdom": "npm:jsdom@^27.4.0",
|
||||||
"moviedb-promise": "npm:moviedb-promise@^4.0.7",
|
"moviedb-promise": "npm:moviedb-promise@^4.0.7",
|
||||||
"parse-ingredient": "npm:parse-ingredient@^1.3.1",
|
"parse-ingredient": "npm:parse-ingredient@^1.3.1",
|
||||||
"playwright": "npm:playwright@^1.49.1",
|
|
||||||
"playwright-extra": "npm:playwright-extra@^4.3.6",
|
"playwright-extra": "npm:playwright-extra@^4.3.6",
|
||||||
"preact": "https://esm.sh/preact@10.22.0",
|
"preact": "npm:preact@^10.27.2",
|
||||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.2",
|
"@preact/signals": "npm:@preact/signals@^2.5.0",
|
||||||
"preact/": "https://esm.sh/preact@10.22.0/",
|
"@fresh/plugin-vite": "jsr:@fresh/plugin-vite@^1.0.8",
|
||||||
"gfm": "jsr:@deno/gfm",
|
|
||||||
"puppeteer-extra-plugin-stealth": "npm:puppeteer-extra-plugin-stealth@^2.11.2",
|
"puppeteer-extra-plugin-stealth": "npm:puppeteer-extra-plugin-stealth@^2.11.2",
|
||||||
"tailwindcss": "npm:tailwindcss@^3.4.17",
|
"sharp": "npm:sharp@^0.34.5",
|
||||||
"tailwindcss/": "npm:/tailwindcss@^3.4.17/",
|
|
||||||
"tailwindcss/plugin": "npm:/tailwindcss@^3.4.17/plugin.js",
|
|
||||||
"camelcase-css": "npm:camelcase-css",
|
|
||||||
"thumbhash": "npm:thumbhash@^0.1.1",
|
"thumbhash": "npm:thumbhash@^0.1.1",
|
||||||
"tsx": "npm:tsx@^4.19.2",
|
"turndown": "npm:turndown@^7.2.2",
|
||||||
"yaml": "https://deno.land/std@0.197.0/yaml/mod.ts",
|
"vite": "npm:vite@^7.1.3",
|
||||||
"zod": "npm:zod@^3.24.1",
|
"tailwindcss": "npm:tailwindcss@^4.1.10",
|
||||||
"fs": "https://deno.land/std/fs/mod.ts"
|
"@tailwindcss/vite": "npm:@tailwindcss/vite@^4.1.12",
|
||||||
|
"zod": "npm:zod@^4.3.5"
|
||||||
},
|
},
|
||||||
"compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" },
|
"compilerOptions": {
|
||||||
"exclude": ["**/_fresh/*"]
|
"lib": [
|
||||||
|
"dom",
|
||||||
|
"dom.asynciterable",
|
||||||
|
"dom.iterable",
|
||||||
|
"deno.ns"
|
||||||
|
],
|
||||||
|
"jsx": "precompile",
|
||||||
|
"jsxImportSource": "preact",
|
||||||
|
"jsxPrecompileSkipElements": [
|
||||||
|
"a",
|
||||||
|
"img",
|
||||||
|
"source",
|
||||||
|
"body",
|
||||||
|
"html",
|
||||||
|
"head",
|
||||||
|
"title",
|
||||||
|
"meta",
|
||||||
|
"script",
|
||||||
|
"link",
|
||||||
|
"style",
|
||||||
|
"base",
|
||||||
|
"noscript",
|
||||||
|
"template"
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
"vite/client"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"allowScripts": {
|
||||||
|
"allow": [
|
||||||
|
"npm:sharp@0.34.5",
|
||||||
|
"npm:esbuild@0.27.2",
|
||||||
|
"npm:esbuild@0.18.20",
|
||||||
|
"npm:esbuild@0.25.12",
|
||||||
|
"npm:esbuild@0.25.7"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
dev.ts
8
dev.ts
@@ -1,8 +0,0 @@
|
|||||||
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
|
||||||
|
|
||||||
import dev from "$fresh/dev.ts";
|
|
||||||
import config from "./fresh.config.ts";
|
|
||||||
|
|
||||||
await dev(import.meta.url, "./main.ts", config);
|
|
||||||
|
|
||||||
Deno.exit(0);
|
|
||||||
@@ -2,19 +2,21 @@ CREATE TABLE `performance` (
|
|||||||
`path` text NOT NULL,
|
`path` text NOT NULL,
|
||||||
`search` text,
|
`search` text,
|
||||||
`time` integer NOT NULL,
|
`time` integer NOT NULL,
|
||||||
`created_at` integer DEFAULT (current_timestamp)
|
`created_at` integer DEFAULT (CURRENT_TIMESTAMP)
|
||||||
);
|
);
|
||||||
|
|
||||||
--> statement-breakpoint
|
--> statement-breakpoint
|
||||||
CREATE TABLE `session` (
|
CREATE TABLE `session` (
|
||||||
`id` text PRIMARY KEY NOT NULL,
|
`id` text PRIMARY KEY NOT NULL,
|
||||||
`created_at` integer DEFAULT (current_timestamp),
|
`created_at` integer DEFAULT (CURRENT_TIMESTAMP),
|
||||||
`expires_at` integer NOT NULL,
|
`expires_at` integer NOT NULL,
|
||||||
`user_id` text NOT NULL
|
`user_id` text NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
--> statement-breakpoint
|
--> statement-breakpoint
|
||||||
CREATE TABLE `user` (
|
CREATE TABLE `user` (
|
||||||
`id` text PRIMARY KEY NOT NULL,
|
`id` text PRIMARY KEY NOT NULL,
|
||||||
`created_at` integer DEFAULT (current_timestamp) NOT NULL,
|
`created_at` integer DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
|
||||||
`email` text NOT NULL,
|
`email` text NOT NULL,
|
||||||
`name` text NOT NULL
|
`name` text NOT NULL
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
ALTER TABLE `performance` ALTER COLUMN "created_at" TO "created_at" integer DEFAULT (STRFTIME('%s', 'now') * 1000);
|
ALTER TABLE
|
||||||
|
`performance`
|
||||||
|
ALTER COLUMN
|
||||||
|
"created_at" TO "created_at" integer DEFAULT (STRFTIME('%s', 'now') * 1000);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
CREATE TABLE `image` (
|
CREATE TABLE `image` (
|
||||||
`created_at` integer DEFAULT (current_timestamp),
|
`created_at` integer DEFAULT (CURRENT_TIMESTAMP),
|
||||||
`url` text NOT NULL,
|
`url` text NOT NULL,
|
||||||
`average` text NOT NULL,
|
`average` text NOT NULL,
|
||||||
`blurhash` text NOT NULL,
|
`blurhash` text NOT NULL,
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
PRAGMA foreign_keys = OFF;
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
CREATE TABLE `__new_document` (
|
CREATE TABLE `__new_document` (
|
||||||
`name` text PRIMARY KEY NOT NULL,
|
`name` text PRIMARY KEY NOT NULL,
|
||||||
`last_modified` integer NOT NULL,
|
`last_modified` integer NOT NULL,
|
||||||
@@ -6,8 +8,31 @@ CREATE TABLE `__new_document` (
|
|||||||
`size` integer NOT NULL,
|
`size` integer NOT NULL,
|
||||||
`perm` text NOT NULL
|
`perm` text NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
--> statement-breakpoint
|
--> statement-breakpoint
|
||||||
INSERT INTO `__new_document`("name", "last_modified", "contentType", "size", "perm") SELECT "name", "last_modified", "contentType", "size", "perm" FROM `document`;--> statement-breakpoint
|
INSERT INTO
|
||||||
DROP TABLE `document`;--> statement-breakpoint
|
`__new_document`(
|
||||||
ALTER TABLE `__new_document` RENAME TO `document`;--> statement-breakpoint
|
"name",
|
||||||
PRAGMA foreign_keys=ON;
|
"last_modified",
|
||||||
|
"contentType",
|
||||||
|
"size",
|
||||||
|
"perm"
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
"name",
|
||||||
|
"last_modified",
|
||||||
|
"contentType",
|
||||||
|
"size",
|
||||||
|
"perm"
|
||||||
|
FROM
|
||||||
|
`document`;
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP TABLE `document`;
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE
|
||||||
|
`__new_document` RENAME TO `document`;
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
PRAGMA foreign_keys = ON;
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
ALTER TABLE `document` RENAME COLUMN "contentType" TO "content_type";
|
ALTER TABLE
|
||||||
|
`document` RENAME COLUMN "contentType" TO "content_type";
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
ALTER TABLE `document` ADD `content` text;
|
ALTER TABLE
|
||||||
|
`document`
|
||||||
|
ADD
|
||||||
|
`content` text;
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
ALTER TABLE `document` ALTER COLUMN "content" TO "content" text NOT NULL;
|
ALTER TABLE
|
||||||
|
`document`
|
||||||
|
ALTER COLUMN
|
||||||
|
"content" TO "content" text NOT NULL;
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
ALTER TABLE `document` ALTER COLUMN "content" TO "content" text;
|
ALTER TABLE
|
||||||
|
`document`
|
||||||
|
ALTER COLUMN
|
||||||
|
"content" TO "content" text;
|
||||||
|
|||||||
@@ -3,10 +3,15 @@ CREATE TABLE `cache` (
|
|||||||
`key` text PRIMARY KEY NOT NULL,
|
`key` text PRIMARY KEY NOT NULL,
|
||||||
`json` text,
|
`json` text,
|
||||||
`binary` blob,
|
`binary` blob,
|
||||||
`created_at` integer DEFAULT (current_timestamp),
|
`created_at` integer DEFAULT (CURRENT_TIMESTAMP),
|
||||||
`expires_at` integer
|
`expires_at` integer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX `key_idx` ON `cache` (`key`);
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX `scope_idx` ON `cache` (`scope`);
|
||||||
|
|
||||||
--> statement-breakpoint
|
--> statement-breakpoint
|
||||||
CREATE INDEX `key_idx` ON `cache` (`key`);--> statement-breakpoint
|
|
||||||
CREATE INDEX `scope_idx` ON `cache` (`scope`);--> statement-breakpoint
|
|
||||||
CREATE INDEX `name_idx` ON `document` (`name`);
|
CREATE INDEX `name_idx` ON `document` (`name`);
|
||||||
@@ -1 +1,2 @@
|
|||||||
ALTER TABLE `image` RENAME COLUMN "blurhash" TO "thumbhash";
|
ALTER TABLE
|
||||||
|
`image` RENAME COLUMN "blurhash" TO "thumbhash";
|
||||||
|
|||||||
22
drizzle/0011_reflective_frank_castle.sql
Normal file
22
drizzle/0011_reflective_frank_castle.sql
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
DROP INDEX "key_idx";
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP INDEX "scope_idx";
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP INDEX "name_idx";
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE
|
||||||
|
`image`
|
||||||
|
ALTER COLUMN
|
||||||
|
"created_at" TO "created_at" integer DEFAULT (unixepoch());
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX `key_idx` ON `cache` (`key`);
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX `scope_idx` ON `cache` (`scope`);
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX `name_idx` ON `document` (`name`);
|
||||||
309
drizzle/meta/0011_snapshot.json
Normal file
309
drizzle/meta/0011_snapshot.json
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
{
|
||||||
|
"version": "6",
|
||||||
|
"dialect": "sqlite",
|
||||||
|
"id": "11bbbc9d-3c0c-4fb9-893f-c87d5b8660d0",
|
||||||
|
"prevId": "685b57ca-45e0-4373-baee-fc3abb4f2d74",
|
||||||
|
"tables": {
|
||||||
|
"cache": {
|
||||||
|
"name": "cache",
|
||||||
|
"columns": {
|
||||||
|
"scope": {
|
||||||
|
"name": "scope",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"key": {
|
||||||
|
"name": "key",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"json": {
|
||||||
|
"name": "json",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"binary": {
|
||||||
|
"name": "binary",
|
||||||
|
"type": "blob",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"name": "created_at",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"default": "(current_timestamp)"
|
||||||
|
},
|
||||||
|
"expires_at": {
|
||||||
|
"name": "expires_at",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {
|
||||||
|
"key_idx": {
|
||||||
|
"name": "key_idx",
|
||||||
|
"columns": [
|
||||||
|
"key"
|
||||||
|
],
|
||||||
|
"isUnique": false
|
||||||
|
},
|
||||||
|
"scope_idx": {
|
||||||
|
"name": "scope_idx",
|
||||||
|
"columns": [
|
||||||
|
"scope"
|
||||||
|
],
|
||||||
|
"isUnique": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {},
|
||||||
|
"checkConstraints": {}
|
||||||
|
},
|
||||||
|
"document": {
|
||||||
|
"name": "document",
|
||||||
|
"columns": {
|
||||||
|
"name": {
|
||||||
|
"name": "name",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"last_modified": {
|
||||||
|
"name": "last_modified",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"name": "content",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"content_type": {
|
||||||
|
"name": "content_type",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"size": {
|
||||||
|
"name": "size",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"perm": {
|
||||||
|
"name": "perm",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {
|
||||||
|
"name_idx": {
|
||||||
|
"name": "name_idx",
|
||||||
|
"columns": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"isUnique": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {},
|
||||||
|
"checkConstraints": {}
|
||||||
|
},
|
||||||
|
"image": {
|
||||||
|
"name": "image",
|
||||||
|
"columns": {
|
||||||
|
"created_at": {
|
||||||
|
"name": "created_at",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"default": "(unixepoch())"
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"name": "url",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"average": {
|
||||||
|
"name": "average",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"thumbhash": {
|
||||||
|
"name": "thumbhash",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"mime": {
|
||||||
|
"name": "mime",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {},
|
||||||
|
"checkConstraints": {}
|
||||||
|
},
|
||||||
|
"performance": {
|
||||||
|
"name": "performance",
|
||||||
|
"columns": {
|
||||||
|
"path": {
|
||||||
|
"name": "path",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"search": {
|
||||||
|
"name": "search",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"time": {
|
||||||
|
"name": "time",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"name": "created_at",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"default": "(STRFTIME('%s', 'now') * 1000)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {},
|
||||||
|
"checkConstraints": {}
|
||||||
|
},
|
||||||
|
"session": {
|
||||||
|
"name": "session",
|
||||||
|
"columns": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"name": "created_at",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"default": "(current_timestamp)"
|
||||||
|
},
|
||||||
|
"expires_at": {
|
||||||
|
"name": "expires_at",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"user_id": {
|
||||||
|
"name": "user_id",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {},
|
||||||
|
"checkConstraints": {}
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"name": "user",
|
||||||
|
"columns": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"name": "created_at",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false,
|
||||||
|
"default": "(current_timestamp)"
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"name": "email",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"name": "name",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {},
|
||||||
|
"checkConstraints": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"views": {},
|
||||||
|
"enums": {},
|
||||||
|
"_meta": {
|
||||||
|
"schemas": {},
|
||||||
|
"tables": {},
|
||||||
|
"columns": {}
|
||||||
|
},
|
||||||
|
"internal": {
|
||||||
|
"indexes": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,6 +78,13 @@
|
|||||||
"when": 1762099260474,
|
"when": 1762099260474,
|
||||||
"tag": "0010_youthful_tyrannus",
|
"tag": "0010_youthful_tyrannus",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 11,
|
||||||
|
"version": "6",
|
||||||
|
"when": 1768058169808,
|
||||||
|
"tag": "0011_reflective_frank_castle",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
import { defineConfig } from "$fresh/server.ts";
|
|
||||||
import tailwind from "$fresh/plugins/tailwind.ts";
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [tailwind()],
|
|
||||||
});
|
|
||||||
138
fresh.gen.ts
138
fresh.gen.ts
@@ -1,138 +0,0 @@
|
|||||||
// DO NOT EDIT. This file is generated by Fresh.
|
|
||||||
// This file SHOULD be checked into source version control.
|
|
||||||
// This file is automatically updated during development when running `dev.ts`.
|
|
||||||
|
|
||||||
import * as $_404 from "./routes/_404.tsx";
|
|
||||||
import * as $_app from "./routes/_app.tsx";
|
|
||||||
import * as $_layout from "./routes/_layout.tsx";
|
|
||||||
import * as $_middleware from "./routes/_middleware.ts";
|
|
||||||
import * as $admin_cache_index from "./routes/admin/cache/index.tsx";
|
|
||||||
import * as $admin_log_index from "./routes/admin/log/index.tsx";
|
|
||||||
import * as $admin_performance_index from "./routes/admin/performance/index.tsx";
|
|
||||||
import * as $api_articles_name_ from "./routes/api/articles/[name].ts";
|
|
||||||
import * as $api_articles_create_index from "./routes/api/articles/create/index.ts";
|
|
||||||
import * as $api_articles_index from "./routes/api/articles/index.ts";
|
|
||||||
import * as $api_auth_callback from "./routes/api/auth/callback.ts";
|
|
||||||
import * as $api_auth_login from "./routes/api/auth/login.ts";
|
|
||||||
import * as $api_auth_logout from "./routes/api/auth/logout.ts";
|
|
||||||
import * as $api_cache from "./routes/api/cache.ts";
|
|
||||||
import * as $api_images_index from "./routes/api/images/index.ts";
|
|
||||||
import * as $api_index from "./routes/api/index.ts";
|
|
||||||
import * as $api_logs from "./routes/api/logs.ts";
|
|
||||||
import * as $api_movies_name_ from "./routes/api/movies/[name].ts";
|
|
||||||
import * as $api_movies_enhance_name_ from "./routes/api/movies/enhance/[name].ts";
|
|
||||||
import * as $api_movies_index from "./routes/api/movies/index.ts";
|
|
||||||
import * as $api_query_index from "./routes/api/query/index.ts";
|
|
||||||
import * as $api_recipes_name_ from "./routes/api/recipes/[name].ts";
|
|
||||||
import * as $api_recipes_create_index from "./routes/api/recipes/create/index.ts";
|
|
||||||
import * as $api_recipes_create_parseJsonLd from "./routes/api/recipes/create/parseJsonLd.ts";
|
|
||||||
import * as $api_recipes_index from "./routes/api/recipes/index.ts";
|
|
||||||
import * as $api_recommendation_all from "./routes/api/recommendation/all.ts";
|
|
||||||
import * as $api_recommendation_data from "./routes/api/recommendation/data.ts";
|
|
||||||
import * as $api_recommendation_index from "./routes/api/recommendation/index.ts";
|
|
||||||
import * as $api_recommendation_movie_id_ from "./routes/api/recommendation/movie/[id].ts";
|
|
||||||
import * as $api_series_name_ from "./routes/api/series/[name].ts";
|
|
||||||
import * as $api_series_enhance_name_ from "./routes/api/series/enhance/[name].ts";
|
|
||||||
import * as $api_series_index from "./routes/api/series/index.ts";
|
|
||||||
import * as $api_tmdb_id_ from "./routes/api/tmdb/[id].ts";
|
|
||||||
import * as $api_tmdb_credits_id_ from "./routes/api/tmdb/credits/[id].ts";
|
|
||||||
import * as $api_tmdb_query from "./routes/api/tmdb/query.ts";
|
|
||||||
import * as $articles_name_ from "./routes/articles/[name].tsx";
|
|
||||||
import * as $articles_index from "./routes/articles/index.tsx";
|
|
||||||
import * as $index from "./routes/index.tsx";
|
|
||||||
import * as $movies_name_ from "./routes/movies/[name].tsx";
|
|
||||||
import * as $movies_index from "./routes/movies/index.tsx";
|
|
||||||
import * as $recipes_name_ from "./routes/recipes/[name].tsx";
|
|
||||||
import * as $recipes_index from "./routes/recipes/index.tsx";
|
|
||||||
import * as $series_name_ from "./routes/series/[name].tsx";
|
|
||||||
import * as $series_index from "./routes/series/index.tsx";
|
|
||||||
import * as $Counter from "./islands/Counter.tsx";
|
|
||||||
import * as $IngredientsList from "./islands/IngredientsList.tsx";
|
|
||||||
import * as $KMenu from "./islands/KMenu.tsx";
|
|
||||||
import * as $KMenu_commands from "./islands/KMenu/commands.ts";
|
|
||||||
import * as $KMenu_commands_add_movie_infos from "./islands/KMenu/commands/add_movie_infos.ts";
|
|
||||||
import * as $KMenu_commands_add_series_infos from "./islands/KMenu/commands/add_series_infos.ts";
|
|
||||||
import * as $KMenu_commands_create_article from "./islands/KMenu/commands/create_article.ts";
|
|
||||||
import * as $KMenu_commands_create_movie from "./islands/KMenu/commands/create_movie.ts";
|
|
||||||
import * as $KMenu_commands_create_recipe from "./islands/KMenu/commands/create_recipe.ts";
|
|
||||||
import * as $KMenu_commands_create_recommendations from "./islands/KMenu/commands/create_recommendations.ts";
|
|
||||||
import * as $KMenu_commands_create_series from "./islands/KMenu/commands/create_series.ts";
|
|
||||||
import * as $KMenu_types from "./islands/KMenu/types.ts";
|
|
||||||
import * as $Link from "./islands/Link.tsx";
|
|
||||||
import * as $Recommendations from "./islands/Recommendations.tsx";
|
|
||||||
import * as $Search from "./islands/Search.tsx";
|
|
||||||
import type { Manifest } from "$fresh/server.ts";
|
|
||||||
|
|
||||||
const manifest = {
|
|
||||||
routes: {
|
|
||||||
"./routes/_404.tsx": $_404,
|
|
||||||
"./routes/_app.tsx": $_app,
|
|
||||||
"./routes/_layout.tsx": $_layout,
|
|
||||||
"./routes/_middleware.ts": $_middleware,
|
|
||||||
"./routes/admin/cache/index.tsx": $admin_cache_index,
|
|
||||||
"./routes/admin/log/index.tsx": $admin_log_index,
|
|
||||||
"./routes/admin/performance/index.tsx": $admin_performance_index,
|
|
||||||
"./routes/api/articles/[name].ts": $api_articles_name_,
|
|
||||||
"./routes/api/articles/create/index.ts": $api_articles_create_index,
|
|
||||||
"./routes/api/articles/index.ts": $api_articles_index,
|
|
||||||
"./routes/api/auth/callback.ts": $api_auth_callback,
|
|
||||||
"./routes/api/auth/login.ts": $api_auth_login,
|
|
||||||
"./routes/api/auth/logout.ts": $api_auth_logout,
|
|
||||||
"./routes/api/cache.ts": $api_cache,
|
|
||||||
"./routes/api/images/index.ts": $api_images_index,
|
|
||||||
"./routes/api/index.ts": $api_index,
|
|
||||||
"./routes/api/logs.ts": $api_logs,
|
|
||||||
"./routes/api/movies/[name].ts": $api_movies_name_,
|
|
||||||
"./routes/api/movies/enhance/[name].ts": $api_movies_enhance_name_,
|
|
||||||
"./routes/api/movies/index.ts": $api_movies_index,
|
|
||||||
"./routes/api/query/index.ts": $api_query_index,
|
|
||||||
"./routes/api/recipes/[name].ts": $api_recipes_name_,
|
|
||||||
"./routes/api/recipes/create/index.ts": $api_recipes_create_index,
|
|
||||||
"./routes/api/recipes/create/parseJsonLd.ts":
|
|
||||||
$api_recipes_create_parseJsonLd,
|
|
||||||
"./routes/api/recipes/index.ts": $api_recipes_index,
|
|
||||||
"./routes/api/recommendation/all.ts": $api_recommendation_all,
|
|
||||||
"./routes/api/recommendation/data.ts": $api_recommendation_data,
|
|
||||||
"./routes/api/recommendation/index.ts": $api_recommendation_index,
|
|
||||||
"./routes/api/recommendation/movie/[id].ts": $api_recommendation_movie_id_,
|
|
||||||
"./routes/api/series/[name].ts": $api_series_name_,
|
|
||||||
"./routes/api/series/enhance/[name].ts": $api_series_enhance_name_,
|
|
||||||
"./routes/api/series/index.ts": $api_series_index,
|
|
||||||
"./routes/api/tmdb/[id].ts": $api_tmdb_id_,
|
|
||||||
"./routes/api/tmdb/credits/[id].ts": $api_tmdb_credits_id_,
|
|
||||||
"./routes/api/tmdb/query.ts": $api_tmdb_query,
|
|
||||||
"./routes/articles/[name].tsx": $articles_name_,
|
|
||||||
"./routes/articles/index.tsx": $articles_index,
|
|
||||||
"./routes/index.tsx": $index,
|
|
||||||
"./routes/movies/[name].tsx": $movies_name_,
|
|
||||||
"./routes/movies/index.tsx": $movies_index,
|
|
||||||
"./routes/recipes/[name].tsx": $recipes_name_,
|
|
||||||
"./routes/recipes/index.tsx": $recipes_index,
|
|
||||||
"./routes/series/[name].tsx": $series_name_,
|
|
||||||
"./routes/series/index.tsx": $series_index,
|
|
||||||
},
|
|
||||||
islands: {
|
|
||||||
"./islands/Counter.tsx": $Counter,
|
|
||||||
"./islands/IngredientsList.tsx": $IngredientsList,
|
|
||||||
"./islands/KMenu.tsx": $KMenu,
|
|
||||||
"./islands/KMenu/commands.ts": $KMenu_commands,
|
|
||||||
"./islands/KMenu/commands/add_movie_infos.ts":
|
|
||||||
$KMenu_commands_add_movie_infos,
|
|
||||||
"./islands/KMenu/commands/add_series_infos.ts":
|
|
||||||
$KMenu_commands_add_series_infos,
|
|
||||||
"./islands/KMenu/commands/create_article.ts":
|
|
||||||
$KMenu_commands_create_article,
|
|
||||||
"./islands/KMenu/commands/create_movie.ts": $KMenu_commands_create_movie,
|
|
||||||
"./islands/KMenu/commands/create_recipe.ts": $KMenu_commands_create_recipe,
|
|
||||||
"./islands/KMenu/commands/create_recommendations.ts":
|
|
||||||
$KMenu_commands_create_recommendations,
|
|
||||||
"./islands/KMenu/commands/create_series.ts": $KMenu_commands_create_series,
|
|
||||||
"./islands/KMenu/types.ts": $KMenu_types,
|
|
||||||
"./islands/Link.tsx": $Link,
|
|
||||||
"./islands/Recommendations.tsx": $Recommendations,
|
|
||||||
"./islands/Search.tsx": $Search,
|
|
||||||
},
|
|
||||||
baseUrl: import.meta.url,
|
|
||||||
} satisfies Manifest;
|
|
||||||
|
|
||||||
export default manifest;
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Signal } from "@preact/signals";
|
import type { Signal } from "@preact/signals";
|
||||||
import { Button } from "@components/Button.tsx";
|
import { Button } from "@components/Button.tsx";
|
||||||
import { IconCircleMinus, IconCirclePlus } from "@components/icons.tsx";
|
import { TbCircleMinus, TbCirclePlus } from "@preact-icons/tb";
|
||||||
|
|
||||||
interface CounterProps {
|
interface CounterProps {
|
||||||
count: Signal<number>;
|
count: Signal<number>;
|
||||||
@@ -10,21 +10,21 @@ export default function Counter(props: CounterProps) {
|
|||||||
props.count.value = Math.max(1, props.count.value);
|
props.count.value = Math.max(1, props.count.value);
|
||||||
return (
|
return (
|
||||||
<div class="flex items-center px-1 py-2 rounded-xl">
|
<div class="flex items-center px-1 py-2 rounded-xl">
|
||||||
<Button
|
<Button onClick={() => props.count.value -= 1}>
|
||||||
class=""
|
<TbCircleMinus class="h-6 w-6" />
|
||||||
onClick={() => props.count.value -= 1}
|
|
||||||
>
|
|
||||||
<IconCircleMinus />
|
|
||||||
</Button>
|
</Button>
|
||||||
<input
|
<input
|
||||||
class="text-3xl bg-transparent inline text-center -mx-4"
|
class="text-3xl bg-transparent inline text-center -mx-4"
|
||||||
type="number"
|
type="number"
|
||||||
size={props.count.toString().length}
|
size={props.count.toString().length}
|
||||||
value={props.count}
|
value={props.count}
|
||||||
onInput={(ev) => props.count.value = ev.target?.value}
|
onInput={(ev) => {
|
||||||
|
const target = ev.target as HTMLInputElement;
|
||||||
|
props.count.value = Math.max(1, Number(target.value));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<Button onClick={() => props.count.value += 1}>
|
<Button onClick={() => props.count.value += 1}>
|
||||||
<IconCirclePlus />
|
<TbCirclePlus class="h-6 w-6" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { Signal } from "@preact/signals";
|
import { Signal } from "@preact/signals";
|
||||||
import type { Ingredient, IngredientGroup } from "@lib/recipeSchema.ts";
|
import type { Ingredient, IngredientGroup } from "@lib/recipeSchema.ts";
|
||||||
import { FunctionalComponent } from "preact";
|
|
||||||
import { unitsOfMeasure } from "@lib/parseIngredient.ts";
|
import { unitsOfMeasure } from "@lib/parseIngredient.ts";
|
||||||
|
|
||||||
function formatAmount(num: number) {
|
function formatAmount(num: number) {
|
||||||
if (num === 0) return "";
|
if (num === 0) return "";
|
||||||
return (Math.floor(num * 4) / 4).toString();
|
return (Math.round(num * 4) / 4).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatUnit(unit: string, amount: number) {
|
function formatUnit(unit: string, amount: number) {
|
||||||
@@ -50,14 +49,12 @@ const Ingredient = (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const IngredientsList: FunctionalComponent<
|
export const IngredientsList = (
|
||||||
{
|
{ ingredients, amount, portion }: {
|
||||||
ingredients: (Ingredient | IngredientGroup)[];
|
ingredients: (Ingredient | IngredientGroup)[];
|
||||||
amount: Signal<number>;
|
amount: Signal<number>;
|
||||||
portion?: number;
|
portion?: number;
|
||||||
}
|
},
|
||||||
> = (
|
|
||||||
{ ingredients, amount, portion },
|
|
||||||
) => {
|
) => {
|
||||||
return (
|
return (
|
||||||
<table class="w-full border-collapse table-auto">
|
<table class="w-full border-collapse table-auto">
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useEventListener } from "@lib/hooks/useEventListener.ts";
|
|||||||
import { menus } from "@islands/KMenu/commands.ts";
|
import { menus } from "@islands/KMenu/commands.ts";
|
||||||
import { MenuEntry } from "@islands/KMenu/types.ts";
|
import { MenuEntry } from "@islands/KMenu/types.ts";
|
||||||
import * as icons from "@components/icons.tsx";
|
import * as icons from "@components/icons.tsx";
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { isKMenuOpen } from "@lib/kmenu.ts";
|
||||||
const KMenuEntry = (
|
const KMenuEntry = (
|
||||||
{ entry, activeIndex, index }: {
|
{ entry, activeIndex, index }: {
|
||||||
entry: MenuEntry;
|
entry: MenuEntry;
|
||||||
@@ -21,7 +21,7 @@ const KMenuEntry = (
|
|||||||
: "text-gray-400"
|
: "text-gray-400"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{entry?.icon && icons[entry.icon]({ class: "w-4 h-4 mr-1" })}
|
{entry?.icon && icons[entry.icon]({ class: "min-w-4 h-4 mr-1" })}
|
||||||
{entry.title}
|
{entry.title}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -42,7 +42,7 @@ export const KMenu = (
|
|||||||
const input = useRef<HTMLInputElement>(null);
|
const input = useRef<HTMLInputElement>(null);
|
||||||
const commandInput = useSignal("");
|
const commandInput = useSignal("");
|
||||||
|
|
||||||
const visible = useSignal(false);
|
const visible = isKMenuOpen;
|
||||||
if (visible.value === false) {
|
if (visible.value === false) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
activeMenuType.value = "main";
|
activeMenuType.value = "main";
|
||||||
@@ -154,25 +154,27 @@ export const KMenu = (
|
|||||||
} else {
|
} else {
|
||||||
input.current?.blur();
|
input.current?.blur();
|
||||||
}
|
}
|
||||||
}, IS_BROWSER ? document?.body : undefined);
|
}, typeof document !== "undefined" ? document?.body : undefined);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={`${visible.value ? "opacity-100" : "opacity-0"} pointer-events-${
|
class={`${visible.value ? "opacity-100" : "opacity-0"} ${
|
||||||
visible.value ? "auto" : "none"
|
visible.value ? "pointer-events-auto" : "pointer-events-none"
|
||||||
} transition grid place-items-center w-full h-full fixed top-0 left-0 z-50`}
|
} transition grid place-items-center w-full h-full fixed top-0 left-0 z-50`}
|
||||||
style={{ background: "#141217ee" }}
|
style={{ background: "#141217ee" }}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class={`relative w-1/2 max-h-64 max-w-[400px] rounded-2xl shadow-2xl nnoisy-gradient overflow-hidden after:opacity-10 bg-gray-700`}
|
class={`relative w-1/2 max-h-64 max-w-100 rounded-2xl shadow-2xl nnoisy-gradient overflow-hidden after:opacity-10 bg-gray-700`}
|
||||||
style={{ background: "#2B2930", color: "#818181" }}
|
style={{ background: "#2B2930", color: "#818181" }}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class={`grid h-12 text-gray-400 ${
|
class={`grid min-h-12 text-gray-400 ${
|
||||||
activeState.value !== "loading" && "border-b"
|
(activeState.value === "normal" || activeState.value === "input") &&
|
||||||
|
"border-b"
|
||||||
} border-gray-500 `}
|
} border-gray-500 `}
|
||||||
style={{
|
style={{
|
||||||
gridTemplateColumns: activeState.value !== "loading"
|
gridTemplateColumns:
|
||||||
|
(activeState.value === "normal" || activeState.value === "input")
|
||||||
? "auto 1fr"
|
? "auto 1fr"
|
||||||
: "1fr",
|
: "1fr",
|
||||||
}}
|
}}
|
||||||
@@ -198,12 +200,18 @@ export const KMenu = (
|
|||||||
)}
|
)}
|
||||||
{activeState.value === "loading" && (
|
{activeState.value === "loading" && (
|
||||||
<div class="py-3 px-4 flex items-center gap-2">
|
<div class="py-3 px-4 flex items-center gap-2">
|
||||||
<icons.IconLoader2 class="animate-spin w-4 h-4" />
|
<icons.IconLoader2 class="animate-spin min-w-4 h-4" />
|
||||||
{loadingText.value || "Loading..."}
|
{loadingText.value || "Loading..."}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{activeState.value === "error" && (
|
||||||
|
<div class="py-3 px-4 flex items-center gap-2 text-red-400">
|
||||||
|
<icons.IconAlertCircle class="min-w-4 h-4" />
|
||||||
|
{loadingText.value || "An error occurred"}
|
||||||
</div>
|
</div>
|
||||||
{activeState.value === "normal" &&
|
)}
|
||||||
|
</div>
|
||||||
|
{(activeState.value === "normal" || activeState.value === "input") &&
|
||||||
(
|
(
|
||||||
<div
|
<div
|
||||||
class=""
|
class=""
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import { createNewArticle } from "@islands/KMenu/commands/create_article.ts";
|
|||||||
import { getCookie } from "@lib/string.ts";
|
import { getCookie } from "@lib/string.ts";
|
||||||
import { addSeriesInfo } from "@islands/KMenu/commands/add_series_infos.ts";
|
import { addSeriesInfo } from "@islands/KMenu/commands/add_series_infos.ts";
|
||||||
import { createNewSeries } from "@islands/KMenu/commands/create_series.ts";
|
import { createNewSeries } from "@islands/KMenu/commands/create_series.ts";
|
||||||
import { updateAllRecommendations } from "@islands/KMenu/commands/create_recommendations.ts";
|
|
||||||
import { createNewRecipe } from "@islands/KMenu/commands/create_recipe.ts";
|
import { createNewRecipe } from "@islands/KMenu/commands/create_recipe.ts";
|
||||||
|
import { enhanceArticleInfo } from "@islands/KMenu/commands/enhance_article_infos.ts";
|
||||||
|
|
||||||
export const menus: Record<string, Menu> = {
|
export const menus: Record<string, Menu> = {
|
||||||
main: {
|
main: {
|
||||||
@@ -77,6 +77,7 @@ export const menus: Record<string, Menu> = {
|
|||||||
createNewSeries,
|
createNewSeries,
|
||||||
createNewRecipe,
|
createNewRecipe,
|
||||||
addMovieInfos,
|
addMovieInfos,
|
||||||
|
enhanceArticleInfo,
|
||||||
// updateAllRecommendations,
|
// updateAllRecommendations,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export const addMovieInfos: MenuEntry = {
|
|||||||
meta: "",
|
meta: "",
|
||||||
icon: "IconReportSearch",
|
icon: "IconReportSearch",
|
||||||
cb: async (state, context) => {
|
cb: async (state, context) => {
|
||||||
|
try {
|
||||||
state.activeState.value = "loading";
|
state.activeState.value = "loading";
|
||||||
const movie = context as ReviewResource;
|
const movie = context as ReviewResource;
|
||||||
|
|
||||||
@@ -17,6 +18,10 @@ export const addMovieInfos: MenuEntry = {
|
|||||||
`/api/tmdb/query?q=${encodeURIComponent(query)}`,
|
`/api/tmdb/query?q=${encodeURIComponent(query)}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(await response.text());
|
||||||
|
}
|
||||||
|
|
||||||
const json = await response.json() as TMDBMovie[];
|
const json = await response.json() as TMDBMovie[];
|
||||||
|
|
||||||
const menuID = `result/${movie.name}`;
|
const menuID = `result/${movie.name}`;
|
||||||
@@ -26,6 +31,7 @@ export const addMovieInfos: MenuEntry = {
|
|||||||
entries: json.map((m) => ({
|
entries: json.map((m) => ({
|
||||||
title: `${m.title} released ${m.release_date}`,
|
title: `${m.title} released ${m.release_date}`,
|
||||||
cb: async () => {
|
cb: async () => {
|
||||||
|
try {
|
||||||
state.activeState.value = "loading";
|
state.activeState.value = "loading";
|
||||||
await fetch(`/api/movies/enhance/${movie.name}/`, {
|
await fetch(`/api/movies/enhance/${movie.name}/`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -34,6 +40,14 @@ export const addMovieInfos: MenuEntry = {
|
|||||||
state.visible.value = false;
|
state.visible.value = false;
|
||||||
state.activeState.value = "normal";
|
state.activeState.value = "normal";
|
||||||
globalThis.location.reload();
|
globalThis.location.reload();
|
||||||
|
} catch (e) {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
if (e instanceof Error) {
|
||||||
|
if ("message" in e) {
|
||||||
|
state.loadingText.value = e.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
@@ -41,6 +55,14 @@ export const addMovieInfos: MenuEntry = {
|
|||||||
state.activeMenu.value = menuID;
|
state.activeMenu.value = menuID;
|
||||||
state.commandInput.value = "";
|
state.commandInput.value = "";
|
||||||
state.activeState.value = "normal";
|
state.activeState.value = "normal";
|
||||||
|
} catch (e) {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
if (e instanceof Error) {
|
||||||
|
if ("message" in e) {
|
||||||
|
state.loadingText.value = e.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
visible: () => {
|
visible: () => {
|
||||||
const loc = globalThis["location"];
|
const loc = globalThis["location"];
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export const addSeriesInfo: MenuEntry = {
|
|||||||
meta: "",
|
meta: "",
|
||||||
icon: "IconReportSearch",
|
icon: "IconReportSearch",
|
||||||
cb: async (state, context) => {
|
cb: async (state, context) => {
|
||||||
|
try {
|
||||||
state.activeState.value = "loading";
|
state.activeState.value = "loading";
|
||||||
const series = context as ReviewResource;
|
const series = context as ReviewResource;
|
||||||
|
|
||||||
@@ -17,6 +18,10 @@ export const addSeriesInfo: MenuEntry = {
|
|||||||
`/api/tmdb/query?q=${encodeURIComponent(query)}&type=serie`,
|
`/api/tmdb/query?q=${encodeURIComponent(query)}&type=serie`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(await response.text());
|
||||||
|
}
|
||||||
|
|
||||||
const json = await response.json() as TMDBSeries[];
|
const json = await response.json() as TMDBSeries[];
|
||||||
|
|
||||||
const menuID = `result/${series.name}`;
|
const menuID = `result/${series.name}`;
|
||||||
@@ -26,6 +31,7 @@ export const addSeriesInfo: MenuEntry = {
|
|||||||
entries: json.map((m) => ({
|
entries: json.map((m) => ({
|
||||||
title: `${m.name || m.original_name} released ${m.first_air_date}`,
|
title: `${m.name || m.original_name} released ${m.first_air_date}`,
|
||||||
cb: async () => {
|
cb: async () => {
|
||||||
|
try {
|
||||||
state.activeState.value = "loading";
|
state.activeState.value = "loading";
|
||||||
await fetch(`/api/series/enhance/${series.name}/`, {
|
await fetch(`/api/series/enhance/${series.name}/`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -34,6 +40,14 @@ export const addSeriesInfo: MenuEntry = {
|
|||||||
state.visible.value = false;
|
state.visible.value = false;
|
||||||
state.activeState.value = "normal";
|
state.activeState.value = "normal";
|
||||||
//window.location.reload();
|
//window.location.reload();
|
||||||
|
} catch (e) {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
if (e instanceof Error) {
|
||||||
|
if ("message" in e) {
|
||||||
|
state.loadingText.value = e.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
@@ -41,6 +55,14 @@ export const addSeriesInfo: MenuEntry = {
|
|||||||
state.commandInput.value = "";
|
state.commandInput.value = "";
|
||||||
state.activeMenu.value = menuID;
|
state.activeMenu.value = menuID;
|
||||||
state.activeState.value = "normal";
|
state.activeState.value = "normal";
|
||||||
|
} catch (e) {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
if (e instanceof Error) {
|
||||||
|
if ("message" in e) {
|
||||||
|
state.loadingText.value = e.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
visible: () => {
|
visible: () => {
|
||||||
const loc = globalThis["location"];
|
const loc = globalThis["location"];
|
||||||
|
|||||||
@@ -22,14 +22,16 @@ export const createNewArticle: MenuEntry = {
|
|||||||
state.activeState.value = "loading";
|
state.activeState.value = "loading";
|
||||||
|
|
||||||
fetchStream("/api/articles/create?url=" + value, (chunk) => {
|
fetchStream("/api/articles/create?url=" + value, (chunk) => {
|
||||||
if (chunk.startsWith("id:")) {
|
if (chunk.type === "error") {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
state.loadingText.value = chunk.message;
|
||||||
|
} else if (chunk.type === "finished") {
|
||||||
state.loadingText.value = "Finished";
|
state.loadingText.value = "Finished";
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = "/articles/" +
|
globalThis.location.href = "/articles/" + chunk.url;
|
||||||
chunk.replace("id:", "").trim();
|
|
||||||
}, 500);
|
}, 500);
|
||||||
} else {
|
} else {
|
||||||
state.loadingText.value = chunk;
|
state.loadingText.value = chunk.message;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export const createNewMovie: MenuEntry = {
|
|||||||
|
|
||||||
let currentQuery: string;
|
let currentQuery: string;
|
||||||
const search = debounce(async function search(query: string) {
|
const search = debounce(async function search(query: string) {
|
||||||
|
try {
|
||||||
currentQuery = query;
|
currentQuery = query;
|
||||||
if (query.length < 2) {
|
if (query.length < 2) {
|
||||||
return;
|
return;
|
||||||
@@ -38,6 +39,10 @@ export const createNewMovie: MenuEntry = {
|
|||||||
|
|
||||||
const response = await fetch("/api/tmdb/query?q=" + query);
|
const response = await fetch("/api/tmdb/query?q=" + query);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(await response.text());
|
||||||
|
}
|
||||||
|
|
||||||
const movies = await response.json() as TMDBMovie[];
|
const movies = await response.json() as TMDBMovie[];
|
||||||
|
|
||||||
if (query !== currentQuery) return;
|
if (query !== currentQuery) return;
|
||||||
@@ -48,18 +53,38 @@ export const createNewMovie: MenuEntry = {
|
|||||||
return {
|
return {
|
||||||
title: `${r.title} - ${r.release_date}`,
|
title: `${r.title} - ${r.release_date}`,
|
||||||
cb: async () => {
|
cb: async () => {
|
||||||
|
try {
|
||||||
state.activeState.value = "loading";
|
state.activeState.value = "loading";
|
||||||
const response = await fetch("/api/movies/" + r.id, {
|
const response = await fetch("/api/movies/" + r.id, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(await response.text());
|
||||||
|
}
|
||||||
const movie = await response.json() as ReviewResource;
|
const movie = await response.json() as ReviewResource;
|
||||||
unsub();
|
unsub();
|
||||||
globalThis.location.href = "/movies/" + movie.name;
|
globalThis.location.href = "/movies/" + movie.name;
|
||||||
|
} catch (e) {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
if (e instanceof Error) {
|
||||||
|
if ("message" in e) {
|
||||||
|
state.loadingText.value = e.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
state.activeMenu.value = "input_link";
|
state.activeMenu.value = "input_link";
|
||||||
|
} catch (e) {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
if (e instanceof Error) {
|
||||||
|
if ("message" in e) {
|
||||||
|
state.loadingText.value = e.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
const unsub = state.commandInput.subscribe((value) => {
|
const unsub = state.commandInput.subscribe((value) => {
|
||||||
|
|||||||
@@ -21,15 +21,17 @@ export const createNewRecipe: MenuEntry = {
|
|||||||
|
|
||||||
state.activeState.value = "loading";
|
state.activeState.value = "loading";
|
||||||
|
|
||||||
fetchStream("/api/recipes/create?url=" + value, (chunk) => {
|
fetchStream("/api/recipes/create?url=" + value, (msg) => {
|
||||||
if (chunk.startsWith("id:")) {
|
if (msg.type === "error") {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
state.loadingText.value = msg.message;
|
||||||
|
} else if (msg.type === "finished") {
|
||||||
state.loadingText.value = "Finished";
|
state.loadingText.value = "Finished";
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
globalThis.location.href = "/recipes/" +
|
globalThis.location.href = "/recipes/" + msg.url;
|
||||||
chunk.replace("id:", "").trim();
|
|
||||||
}, 500);
|
}, 500);
|
||||||
} else {
|
} else {
|
||||||
state.loadingText.value = chunk;
|
state.loadingText.value = msg.message;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,15 @@ export const updateAllRecommendations: MenuEntry = {
|
|||||||
state.activeState.value = "loading";
|
state.activeState.value = "loading";
|
||||||
|
|
||||||
fetchStream("/api/recommendation/all", (chunk) => {
|
fetchStream("/api/recommendation/all", (chunk) => {
|
||||||
if (chunk.toLowerCase().includes("finish")) {
|
if (chunk.type === "error") {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
state.loadingText.value = chunk.message;
|
||||||
|
} else if (chunk.type === "finished") {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.reload();
|
globalThis.location.reload();
|
||||||
}, 500);
|
}, 500);
|
||||||
} else {
|
} else {
|
||||||
state.loadingText.value = chunk;
|
state.loadingText.value = chunk.message;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export const createNewSeries: MenuEntry = {
|
|||||||
|
|
||||||
let currentQuery: string;
|
let currentQuery: string;
|
||||||
const search = debounce(async function search(query: string) {
|
const search = debounce(async function search(query: string) {
|
||||||
|
try {
|
||||||
currentQuery = query;
|
currentQuery = query;
|
||||||
if (query.length < 2) {
|
if (query.length < 2) {
|
||||||
return;
|
return;
|
||||||
@@ -40,6 +41,10 @@ export const createNewSeries: MenuEntry = {
|
|||||||
"/api/tmdb/query?q=" + query + "&type=series",
|
"/api/tmdb/query?q=" + query + "&type=series",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(await response.text());
|
||||||
|
}
|
||||||
|
|
||||||
const series = await response.json() as TMDBSeries[];
|
const series = await response.json() as TMDBSeries[];
|
||||||
|
|
||||||
if (query !== currentQuery) return;
|
if (query !== currentQuery) return;
|
||||||
@@ -50,19 +55,39 @@ export const createNewSeries: MenuEntry = {
|
|||||||
return {
|
return {
|
||||||
title: `${r.name} - ${r.first_air_date}`,
|
title: `${r.name} - ${r.first_air_date}`,
|
||||||
cb: async () => {
|
cb: async () => {
|
||||||
|
try {
|
||||||
state.activeState.value = "loading";
|
state.activeState.value = "loading";
|
||||||
const response = await fetch("/api/series/" + r.id, {
|
const response = await fetch("/api/series/" + r.id, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(await response.text());
|
||||||
|
}
|
||||||
const series = await response.json() as ReviewResource;
|
const series = await response.json() as ReviewResource;
|
||||||
unsub();
|
unsub();
|
||||||
globalThis.location.href = "/series/" + series.name;
|
globalThis.location.href = "/series/" + series.name;
|
||||||
|
} catch (e) {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
if (e instanceof Error) {
|
||||||
|
if ("message" in e) {
|
||||||
|
state.loadingText.value = e.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
state.commandInput.value = "";
|
state.commandInput.value = "";
|
||||||
state.activeMenu.value = "input_link";
|
state.activeMenu.value = "input_link";
|
||||||
|
} catch (e) {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
if (e instanceof Error) {
|
||||||
|
if ("message" in e) {
|
||||||
|
state.loadingText.value = e.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
const unsub = state.commandInput.subscribe((value) => {
|
const unsub = state.commandInput.subscribe((value) => {
|
||||||
|
|||||||
41
islands/KMenu/commands/enhance_article_infos.ts
Normal file
41
islands/KMenu/commands/enhance_article_infos.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { getCookie } from "@lib/string.ts";
|
||||||
|
import { MenuEntry } from "../types.ts";
|
||||||
|
import { ArticleResource } from "@lib/marka/schema.ts";
|
||||||
|
import { fetchStream } from "@lib/helpers.ts";
|
||||||
|
|
||||||
|
export const enhanceArticleInfo: MenuEntry = {
|
||||||
|
title: "Enhance Article Info",
|
||||||
|
meta: "Update metadata and content from source url",
|
||||||
|
icon: "IconReportSearch",
|
||||||
|
cb: (state, context) => {
|
||||||
|
state.activeState.value = "loading";
|
||||||
|
const article = context as ArticleResource;
|
||||||
|
|
||||||
|
fetchStream(
|
||||||
|
`/api/articles/enhance/${article.name}/`,
|
||||||
|
(chunk) => {
|
||||||
|
if (chunk.type === "error") {
|
||||||
|
state.activeState.value = "error";
|
||||||
|
state.loadingText.value = chunk.message;
|
||||||
|
} else if (chunk.type == "finished") {
|
||||||
|
state.loadingText.value = "Finished";
|
||||||
|
setTimeout(() => {
|
||||||
|
state.visible.value = false;
|
||||||
|
state.activeState.value = "normal";
|
||||||
|
globalThis.location.reload();
|
||||||
|
}, 500);
|
||||||
|
} else {
|
||||||
|
state.loadingText.value = chunk.message;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ method: "POST" },
|
||||||
|
);
|
||||||
|
},
|
||||||
|
visible: () => {
|
||||||
|
const loc = globalThis["location"];
|
||||||
|
if (!getCookie("session_cookie")) return false;
|
||||||
|
|
||||||
|
return (loc?.pathname?.includes("article") &&
|
||||||
|
!loc.pathname.endsWith("articles"));
|
||||||
|
},
|
||||||
|
};
|
||||||
14
islands/KMenuButton.tsx
Normal file
14
islands/KMenuButton.tsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { Button } from "@components/Button.tsx";
|
||||||
|
import { IconMenu2 } from "@components/icons.tsx";
|
||||||
|
import { isKMenuOpen } from "@lib/kmenu.ts";
|
||||||
|
|
||||||
|
export default function KMenuButton() {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
class="fixed bottom-4 right-4 md:hidden bg-gray-800 text-white p-3 rounded-full shadow-lg z-50"
|
||||||
|
onClick={() => (isKMenuOpen.value = true)}
|
||||||
|
>
|
||||||
|
<IconMenu2 class="w-6 h-6" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ export function Link(
|
|||||||
props: {
|
props: {
|
||||||
href?: string;
|
href?: string;
|
||||||
class?: string;
|
class?: string;
|
||||||
style?: preact.JSX.CSSProperties;
|
style?: preact.CSSProperties;
|
||||||
children: preact.ComponentChildren;
|
children: preact.ComponentChildren;
|
||||||
"data-thumb"?: string;
|
"data-thumb"?: string;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { IconLoader2, IconSearch } from "@components/icons.tsx";
|
|||||||
import { useEventListener } from "@lib/hooks/useEventListener.ts";
|
import { useEventListener } from "@lib/hooks/useEventListener.ts";
|
||||||
import { resources } from "@lib/resources.ts";
|
import { resources } from "@lib/resources.ts";
|
||||||
import { getCookie } from "@lib/string.ts";
|
import { getCookie } from "@lib/string.ts";
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { IS_BROWSER } from "fresh/runtime";
|
||||||
import Checkbox from "@components/Checkbox.tsx";
|
import Checkbox from "@components/Checkbox.tsx";
|
||||||
import { Rating } from "@components/Rating.tsx";
|
import { Rating } from "@components/Rating.tsx";
|
||||||
import { useSignal } from "@preact/signals";
|
import { useSignal } from "@preact/signals";
|
||||||
@@ -23,7 +23,7 @@ export async function fetchQueryResource(url: URL, type = "") {
|
|||||||
url.searchParams.set("status", "not-seen");
|
url.searchParams.set("status", "not-seen");
|
||||||
}
|
}
|
||||||
if (type) {
|
if (type) {
|
||||||
url.searchParams.set("types", type);
|
url.searchParams.set("type", type);
|
||||||
}
|
}
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const jsonData = await response.json();
|
const jsonData = await response.json();
|
||||||
@@ -55,8 +55,8 @@ const SearchResultImage = ({ src }: { src: string }) => {
|
|||||||
return (
|
return (
|
||||||
<Image
|
<Image
|
||||||
class="object-cover w-12 h-12 rounded-full"
|
class="object-cover w-12 h-12 rounded-full"
|
||||||
width="50"
|
width={100}
|
||||||
height="50"
|
height={100}
|
||||||
src={src}
|
src={src}
|
||||||
alt="preview image"
|
alt="preview image"
|
||||||
/>
|
/>
|
||||||
@@ -114,6 +114,7 @@ const Search = (
|
|||||||
const searchQuery = useSignal(q);
|
const searchQuery = useSignal(q);
|
||||||
const data = useSignal<GenericResource[] | undefined>(results);
|
const data = useSignal<GenericResource[] | undefined>(results);
|
||||||
const isLoading = useSignal(false);
|
const isLoading = useSignal(false);
|
||||||
|
const rating = useSignal<number | undefined>(undefined);
|
||||||
const showSeenStatus = useSignal(false);
|
const showSeenStatus = useSignal(false);
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
@@ -122,8 +123,10 @@ const Search = (
|
|||||||
if (u.searchParams.get("q") !== searchQuery.value) {
|
if (u.searchParams.get("q") !== searchQuery.value) {
|
||||||
u.searchParams.set("q", searchQuery.value);
|
u.searchParams.set("q", searchQuery.value);
|
||||||
}
|
}
|
||||||
if (showSeenStatus.value) {
|
if (showSeenStatus.value === true) {
|
||||||
u.searchParams.set("rating", "0");
|
u.searchParams.set("rating", "0");
|
||||||
|
} else if (rating.value) {
|
||||||
|
u.searchParams.set("rating", rating.value.toString());
|
||||||
} else {
|
} else {
|
||||||
u.searchParams.delete("rating");
|
u.searchParams.delete("rating");
|
||||||
}
|
}
|
||||||
@@ -162,7 +165,7 @@ const Search = (
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
debouncedFetchData(); // Call the debounced fetch function with the updated search query
|
debouncedFetchData(); // Call the debounced fetch function with the updated search query
|
||||||
}, [searchQuery.value, showSeenStatus.value]);
|
}, [searchQuery.value, showSeenStatus.value, rating.value]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
debouncedFetchData();
|
debouncedFetchData();
|
||||||
@@ -187,8 +190,12 @@ const Search = (
|
|||||||
onInput={handleInputChange}
|
onInput={handleInputChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Checkbox label="seen" checked={showSeenStatus} />
|
<Checkbox label="unrated" checked={showSeenStatus} />
|
||||||
<Rating rating={4} />
|
<div
|
||||||
|
class={showSeenStatus.value ? "opacity-10" : ""}
|
||||||
|
>
|
||||||
|
<Rating rating={rating} />
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
{data.value?.length && !isLoading.value
|
{data.value?.length && !isLoading.value
|
||||||
? <SearchResultList showEmoji={!type} result={data.value} />
|
? <SearchResultList showEmoji={!type} result={data.value} />
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { OAuth2Client } from "https://deno.land/x/oauth2_client@v1.0.2/mod.ts";
|
import { OAuth2Client } from "@cmd-johnson/oauth2-client";
|
||||||
import {
|
import {
|
||||||
GITEA_CLIENT_ID,
|
GITEA_CLIENT_ID,
|
||||||
GITEA_CLIENT_SECRET,
|
GITEA_CLIENT_SECRET,
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ export const userTable = sqliteTable("user", {
|
|||||||
id: text()
|
id: text()
|
||||||
.primaryKey(),
|
.primaryKey(),
|
||||||
createdAt: integer("created_at", { mode: "timestamp" })
|
createdAt: integer("created_at", { mode: "timestamp" })
|
||||||
.default(sql`(current_timestamp)`)
|
.default(sql`
|
||||||
|
(CURRENT_TIMESTAMP)
|
||||||
|
`)
|
||||||
.notNull(),
|
.notNull(),
|
||||||
email: text()
|
email: text()
|
||||||
.notNull(),
|
.notNull(),
|
||||||
@@ -24,7 +26,9 @@ export const sessionTable = sqliteTable("session", {
|
|||||||
id: text("id")
|
id: text("id")
|
||||||
.primaryKey(),
|
.primaryKey(),
|
||||||
createdAt: integer("created_at", { mode: "timestamp_ms" }).default(
|
createdAt: integer("created_at", { mode: "timestamp_ms" }).default(
|
||||||
sql`(current_timestamp)`,
|
sql`
|
||||||
|
(CURRENT_TIMESTAMP)
|
||||||
|
`,
|
||||||
),
|
),
|
||||||
expiresAt: integer("expires_at", { mode: "timestamp" })
|
expiresAt: integer("expires_at", { mode: "timestamp" })
|
||||||
.notNull(),
|
.notNull(),
|
||||||
@@ -38,12 +42,16 @@ export const performanceTable = sqliteTable("performance", {
|
|||||||
time: int().notNull(),
|
time: int().notNull(),
|
||||||
createdAt: integer("created_at", {
|
createdAt: integer("created_at", {
|
||||||
mode: "timestamp_ms",
|
mode: "timestamp_ms",
|
||||||
}).default(sql`(STRFTIME('%s', 'now') * 1000)`),
|
}).default(sql`
|
||||||
|
(STRFTIME('%s', 'now') * 1000)
|
||||||
|
`),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const imageTable = sqliteTable("image", {
|
export const imageTable = sqliteTable("image", {
|
||||||
createdAt: integer("created_at", { mode: "timestamp" }).default(
|
createdAt: integer("created_at", { mode: "timestamp" }).default(
|
||||||
sql`(current_timestamp)`,
|
sql`
|
||||||
|
(unixepoch())
|
||||||
|
`,
|
||||||
),
|
),
|
||||||
url: text().notNull(),
|
url: text().notNull(),
|
||||||
average: text().notNull(),
|
average: text().notNull(),
|
||||||
@@ -70,7 +78,9 @@ export const cacheTable = sqliteTable("cache", {
|
|||||||
json: text({ mode: "json" }),
|
json: text({ mode: "json" }),
|
||||||
binary: blob(),
|
binary: blob(),
|
||||||
createdAt: integer("created_at", { mode: "timestamp" }).default(
|
createdAt: integer("created_at", { mode: "timestamp" }).default(
|
||||||
sql`(current_timestamp)`,
|
sql`
|
||||||
|
(CURRENT_TIMESTAMP)
|
||||||
|
`,
|
||||||
),
|
),
|
||||||
expiresAt: integer("expires_at", { mode: "timestamp" }),
|
expiresAt: integer("expires_at", { mode: "timestamp" }),
|
||||||
}, (table) => {
|
}, (table) => {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import path from "node:path";
|
|||||||
|
|
||||||
const DB_FILE = "file:" + path.resolve(DATA_DIR, "db.sqlite");
|
const DB_FILE = "file:" + path.resolve(DATA_DIR, "db.sqlite");
|
||||||
|
|
||||||
// You can specify any property from the libsql connection options
|
|
||||||
export const db = drizzle({
|
export const db = drizzle({
|
||||||
connection: {
|
connection: {
|
||||||
url: DB_FILE,
|
url: DB_FILE,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export const PROXY_PASSWORD = Deno.env.get("PROXY_PASSWORD");
|
|||||||
export const TMDB_API_KEY = Deno.env.get("TMDB_API_KEY");
|
export const TMDB_API_KEY = Deno.env.get("TMDB_API_KEY");
|
||||||
export const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
|
export const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
|
||||||
export const YOUTUBE_API_KEY = Deno.env.get("YOUTUBE_API_KEY");
|
export const YOUTUBE_API_KEY = Deno.env.get("YOUTUBE_API_KEY");
|
||||||
|
export const UNSPLASH_API_KEY = Deno.env.get("UNSPLASH_API_KEY");
|
||||||
export const TELEGRAM_API_KEY = Deno.env.get("TELEGRAM_API_KEY")!;
|
export const TELEGRAM_API_KEY = Deno.env.get("TELEGRAM_API_KEY")!;
|
||||||
|
|
||||||
export const GITEA_SERVER = Deno.env.get("GITEA_SERVER");
|
export const GITEA_SERVER = Deno.env.get("GITEA_SERVER");
|
||||||
@@ -18,6 +19,7 @@ const duration = Deno.env.get("SESSION_DURATION");
|
|||||||
export const SESSION_DURATION = duration ? +duration : (60 * 60 * 24);
|
export const SESSION_DURATION = duration ? +duration : (60 * 60 * 24);
|
||||||
|
|
||||||
export const MARKA_API_KEY = Deno.env.get("MARKA_API_KEY");
|
export const MARKA_API_KEY = Deno.env.get("MARKA_API_KEY");
|
||||||
|
export const MARKA_API_URL = Deno.env.get("MARKA_API_URL");
|
||||||
|
|
||||||
export const JWT_SECRET = Deno.env.get("JWT_SECRET");
|
export const JWT_SECRET = Deno.env.get("JWT_SECRET");
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { FreshContext } from "$fresh/server.ts";
|
import { Context } from "fresh";
|
||||||
|
import { State } from "../utils.ts";
|
||||||
|
|
||||||
class DomainError extends Error {
|
class DomainError extends Error {
|
||||||
status = 500;
|
status = 500;
|
||||||
render?: (ctx: FreshContext) => void;
|
render?: (ctx: Context<State>) => void;
|
||||||
constructor(public statusText = "Internal Server Error") {
|
constructor(public statusText = "Internal Server Error") {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,19 +31,54 @@ export const fixRenderedMarkdown = (content: string) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function fetchStream(url: string, cb: (chunk: string) => void) {
|
type StreamMessage = {
|
||||||
const response = await fetch(url);
|
type: "info";
|
||||||
const reader = response?.body?.getReader();
|
message: string;
|
||||||
if (reader) {
|
} | {
|
||||||
|
type: "error";
|
||||||
|
message: string;
|
||||||
|
} | {
|
||||||
|
type: "warning";
|
||||||
|
message: string;
|
||||||
|
} | {
|
||||||
|
type: "finished";
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function fetchStream(
|
||||||
|
url: string,
|
||||||
|
cb: (chunk: StreamMessage) => void,
|
||||||
|
init?: RequestInit,
|
||||||
|
) {
|
||||||
|
const res = await fetch(url, init);
|
||||||
|
if (!res.body) return;
|
||||||
|
|
||||||
|
let buffer = "";
|
||||||
|
const reader = res.body
|
||||||
|
.pipeThrough(new TextDecoderStream())
|
||||||
|
.pipeThrough(
|
||||||
|
new TransformStream<string, string>({
|
||||||
|
transform(chunk, controller) {
|
||||||
|
buffer += chunk;
|
||||||
|
let idx;
|
||||||
|
while ((idx = buffer.indexOf("\n")) >= 0) {
|
||||||
|
const line = buffer.slice(0, idx).trim();
|
||||||
|
buffer = buffer.slice(idx + 1);
|
||||||
|
if (line) controller.enqueue(line);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
flush(controller) {
|
||||||
|
const line = buffer.trim();
|
||||||
|
if (line) controller.enqueue(line);
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.getReader();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read();
|
const { done, value } = await reader.read();
|
||||||
if (done) return;
|
if (done) break;
|
||||||
const data = new TextDecoder().decode(value);
|
cb(JSON.parse(value));
|
||||||
data
|
|
||||||
.split("$")
|
|
||||||
.filter((d) => d && d.length)
|
|
||||||
.map((d) => cb(Array.isArray(d) ? d[0] : d));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,32 +93,53 @@ export function hashString(message: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const createStreamResponse = () => {
|
export const createStreamResponse = () => {
|
||||||
let controller: ReadableStreamController<ArrayBufferView>;
|
const encoder = new TextEncoder();
|
||||||
const body = new ReadableStream({
|
let controller: ReadableStreamDefaultController<Uint8Array>;
|
||||||
start(cont) {
|
|
||||||
controller = cont;
|
const body = new ReadableStream<Uint8Array>({
|
||||||
|
start(c) {
|
||||||
|
controller = c;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = new Response(body, {
|
const response = new Response(body, {
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "text/plain",
|
// newline-delimited JSON
|
||||||
|
"content-type": "application/x-ndjson; charset=utf-8",
|
||||||
|
// prevent intermediaries from buffering/transforming
|
||||||
|
"cache-control": "no-cache, no-transform",
|
||||||
"x-content-type-options": "nosniff",
|
"x-content-type-options": "nosniff",
|
||||||
|
// nginx hint to disable proxy buffering
|
||||||
|
"x-accel-buffering": "no",
|
||||||
|
// if you control compression, keep it off for streams
|
||||||
|
// "content-encoding": "identity",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function cancel() {
|
const send = (obj: unknown) => {
|
||||||
controller.close();
|
controller.enqueue(encoder.encode(JSON.stringify(obj) + "\n")); // ← delimiter
|
||||||
|
};
|
||||||
|
const cancel = () => controller.close();
|
||||||
|
|
||||||
|
function info(message: string) {
|
||||||
|
return send({ type: "info", message });
|
||||||
}
|
}
|
||||||
|
|
||||||
function enqueue(chunk: string) {
|
function error(message: string) {
|
||||||
controller?.enqueue(new TextEncoder().encode("$" + chunk));
|
return send({ type: "error", message });
|
||||||
|
}
|
||||||
|
|
||||||
|
function warning(message: string) {
|
||||||
|
return send({ type: "warning", message });
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response,
|
response,
|
||||||
cancel,
|
cancel,
|
||||||
enqueue,
|
send,
|
||||||
|
info,
|
||||||
|
error,
|
||||||
|
warning,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
15
lib/image.ts
15
lib/image.ts
@@ -1,14 +1,13 @@
|
|||||||
import { rgbToHex } from "@lib/string.ts";
|
import { rgbToHex } from "@lib/string.ts";
|
||||||
import { createLogger } from "@lib/log/index.ts";
|
import { createLogger } from "@lib/log/index.ts";
|
||||||
import { generateThumbhash } from "@lib/thumbhash.ts";
|
import { generateThumbhash } from "@lib/thumbhash.ts";
|
||||||
import { parseMediaType } from "https://deno.land/std@0.224.0/media_types/parse_media_type.ts";
|
import { parseMediaType } from "@std/media-types";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { mkdir } from "node:fs/promises";
|
import { mkdir } from "node:fs/promises";
|
||||||
import { DATA_DIR } from "@lib/env.ts";
|
import { DATA_DIR } from "@lib/env.ts";
|
||||||
import { db } from "@lib/db/sqlite.ts";
|
import { db } from "@lib/db/sqlite.ts";
|
||||||
import { imageTable } from "@lib/db/schema.ts";
|
import { imageTable } from "@lib/db/schema.ts";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import sharp from "npm:sharp@next";
|
|
||||||
|
|
||||||
const log = createLogger("cache/image");
|
const log = createLogger("cache/image");
|
||||||
|
|
||||||
@@ -158,6 +157,8 @@ async function resizeImage(
|
|||||||
mediaType: string;
|
mediaType: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
const sharp = (await import("sharp")).default;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.debug("Resizing image", { params });
|
log.debug("Resizing image", { params });
|
||||||
|
|
||||||
@@ -211,6 +212,8 @@ async function resizeImage(
|
|||||||
async function createThumbhash(
|
async function createThumbhash(
|
||||||
image: Uint8Array,
|
image: Uint8Array,
|
||||||
): Promise<{ hash: string; average: string }> {
|
): Promise<{ hash: string; average: string }> {
|
||||||
|
const sharp = (await import("sharp")).default;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resizedImage = await sharp(image)
|
const resizedImage = await sharp(image)
|
||||||
.resize(100, 100, { fit: "cover" }) // Keep aspect ratio within bounds
|
.resize(100, 100, { fit: "cover" }) // Keep aspect ratio within bounds
|
||||||
@@ -219,7 +222,11 @@ async function createThumbhash(
|
|||||||
.raw()
|
.raw()
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
|
|
||||||
const [hash, average] = generateThumbhash(resizedImage, 100, 100);
|
const [hash, average] = generateThumbhash(
|
||||||
|
new Uint8Array(resizedImage),
|
||||||
|
100,
|
||||||
|
100,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hash: btoa(String.fromCharCode(...hash)),
|
hash: btoa(String.fromCharCode(...hash)),
|
||||||
@@ -234,6 +241,8 @@ async function createThumbhash(
|
|||||||
* Verifies that an image buffer contains valid image data
|
* Verifies that an image buffer contains valid image data
|
||||||
*/
|
*/
|
||||||
async function verifyImage(imageBuffer: Uint8Array): Promise<boolean> {
|
async function verifyImage(imageBuffer: Uint8Array): Promise<boolean> {
|
||||||
|
const sharp = (await import("sharp")).default;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const metadata = await sharp(imageBuffer).metadata();
|
const metadata = await sharp(imageBuffer).metadata();
|
||||||
return !!(metadata.width && metadata.height && metadata.format);
|
return !!(metadata.width && metadata.height && metadata.format);
|
||||||
|
|||||||
3
lib/kmenu.ts
Normal file
3
lib/kmenu.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { signal } from "@preact/signals";
|
||||||
|
|
||||||
|
export const isKMenuOpen = signal(false);
|
||||||
@@ -36,12 +36,12 @@ export async function getLogs() {
|
|||||||
.map((line) => {
|
.map((line) => {
|
||||||
const [date, ...rest] = line.split(" | ");
|
const [date, ...rest] = line.split(" | ");
|
||||||
const parsed = JSON.parse(rest.join(" | ")) as Log;
|
const parsed = JSON.parse(rest.join(" | ")) as Log;
|
||||||
|
const dateObj = new Date(date);
|
||||||
return {
|
return {
|
||||||
...parsed,
|
...parsed,
|
||||||
date: new Date(date),
|
date: isNaN(dateObj.getTime()) ? new Date() : dateObj,
|
||||||
} as Log;
|
} as Log;
|
||||||
});
|
});
|
||||||
console.log(logs);
|
|
||||||
|
|
||||||
// Return the logs sorted by date
|
// Return the logs sorted by date
|
||||||
return logs.sort((a, b) => a.date.getTime() - b.date.getTime());
|
return logs.sort((a, b) => a.date.getTime() - b.date.getTime());
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ export function createLogger(scope: string, _options?: LoggerOptions): Logger {
|
|||||||
export function loggerFromStream(stream: StreamResponse) {
|
export function loggerFromStream(stream: StreamResponse) {
|
||||||
return {
|
return {
|
||||||
debug: (...data: unknown[]) =>
|
debug: (...data: unknown[]) =>
|
||||||
stream.enqueue(`${data.length > 1 ? data.join(" ") : data[0]}`),
|
stream.info(`${data.length > 1 ? data.join(" ") : data[0]}`),
|
||||||
info: (...data: unknown[]) =>
|
info: (...data: unknown[]) =>
|
||||||
stream.enqueue(`${data.length > 1 ? data.join(" ") : data[0]}`),
|
stream.info(`${data.length > 1 ? data.join(" ") : data[0]}`),
|
||||||
error: (...data: unknown[]) =>
|
error: (...data: unknown[]) =>
|
||||||
stream.enqueue(`[ERROR]: ${data.length > 1 ? data.join(" ") : data[0]}`),
|
stream.error(`[ERROR]: ${data.length > 1 ? data.join(" ") : data[0]}`),
|
||||||
warn: (...data: unknown[]) =>
|
warn: (...data: unknown[]) =>
|
||||||
stream.enqueue(`[WARN]: ${data.length > 1 ? data.join(" ") : data[0]}`),
|
stream.warning(`[WARN]: ${data.length > 1 ? data.join(" ") : data[0]}`),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import { MARKA_API_KEY } from "../env.ts";
|
import { createCache } from "../cache.ts";
|
||||||
|
import { MARKA_API_KEY, MARKA_API_URL } from "../env.ts";
|
||||||
import { getImage } from "../image.ts";
|
import { getImage } from "../image.ts";
|
||||||
import { GenericResource } from "./schema.ts";
|
import { GenericResource } from "./schema.ts";
|
||||||
|
|
||||||
const url = `https://marka.max-richter.dev`;
|
|
||||||
//const url = "http://localhost:8080";
|
|
||||||
|
|
||||||
async function addImageToResource<T extends GenericResource>(
|
async function addImageToResource<T extends GenericResource>(
|
||||||
resource: GenericResource,
|
resource: GenericResource,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
@@ -14,7 +12,7 @@ async function addImageToResource<T extends GenericResource>(
|
|||||||
const absoluteImageUrl = (imageUrl.startsWith("https://") ||
|
const absoluteImageUrl = (imageUrl.startsWith("https://") ||
|
||||||
imageUrl.startsWith("http://"))
|
imageUrl.startsWith("http://"))
|
||||||
? imageUrl
|
? imageUrl
|
||||||
: `${url}/${imageUrl}`;
|
: `${MARKA_API_URL}/${imageUrl}`;
|
||||||
const image = await getImage(absoluteImageUrl);
|
const image = await getImage(absoluteImageUrl);
|
||||||
return { ...resource, image } as T;
|
return { ...resource, image } as T;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -24,34 +22,68 @@ async function addImageToResource<T extends GenericResource>(
|
|||||||
return resource as T;
|
return resource as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Resource = GenericResource & {
|
||||||
|
content: GenericResource["content"] & Array<GenericResource>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchCache = createCache<Resource>("marka");
|
||||||
|
const cacheLock = new Map<string, Promise<Resource>>();
|
||||||
|
|
||||||
|
async function fetchAndStoreUrl(url: string) {
|
||||||
|
const response = await fetch(url);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to fetch resource: ${response.status}`);
|
||||||
|
}
|
||||||
|
const res = await response.json();
|
||||||
|
fetchCache.set(url, res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function cachedFetch(
|
||||||
|
url: string,
|
||||||
|
): Promise<Resource | undefined> {
|
||||||
|
if (fetchCache.has(url)) {
|
||||||
|
fetchAndStoreUrl(url); // Fetch the url in the background
|
||||||
|
return fetchCache.get(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cacheLock.has(url)) return cacheLock.get(url);
|
||||||
|
|
||||||
|
const response = fetchAndStoreUrl(url);
|
||||||
|
cacheLock.set(url, response);
|
||||||
|
|
||||||
|
const res = await response;
|
||||||
|
cacheLock.delete(url);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchResource<T extends GenericResource>(
|
export async function fetchResource<T extends GenericResource>(
|
||||||
resource: string,
|
resource: string,
|
||||||
): Promise<T | undefined> {
|
): Promise<T | undefined> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const d = `${MARKA_API_URL}/resources/${resource}`;
|
||||||
`${url}/resources/${resource}`,
|
const res = await cachedFetch(d);
|
||||||
);
|
if (!res) return;
|
||||||
const res = await response.json();
|
|
||||||
return addImageToResource<T>(res);
|
return addImageToResource<T>(res);
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listResources<T = GenericResource>(
|
export async function listResources<T extends GenericResource>(
|
||||||
resource: string,
|
resource: string,
|
||||||
): Promise<T[]> {
|
): Promise<T[]> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const d = `${MARKA_API_URL}/resources/${resource}`;
|
||||||
`${url}/resources/${resource}`,
|
const list = await cachedFetch(d);
|
||||||
);
|
if (!list) return [];
|
||||||
const list = await response.json();
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
list?.content
|
list?.content
|
||||||
.filter((a: GenericResource) => a?.content?._type)
|
.filter((a) => a?.content?._type)
|
||||||
.map((res: GenericResource) => addImageToResource(res)),
|
.map((res) => addImageToResource(res) as Promise<T>),
|
||||||
);
|
);
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
|
console.log(`Failed to fetch resource: ${resource}`, _e);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +94,7 @@ export async function createResource(
|
|||||||
) {
|
) {
|
||||||
const isJson = typeof content === "object" &&
|
const isJson = typeof content === "object" &&
|
||||||
!(content instanceof ArrayBuffer);
|
!(content instanceof ArrayBuffer);
|
||||||
const fetchUrl = `${url}/resources/${path}`;
|
const fetchUrl = `${MARKA_API_URL}/resources/${path}`;
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
headers.append("Content-Type", isJson ? "application/json" : "");
|
headers.append("Content-Type", isJson ? "application/json" : "");
|
||||||
if (MARKA_API_KEY) {
|
if (MARKA_API_KEY) {
|
||||||
@@ -74,7 +106,12 @@ export async function createResource(
|
|||||||
body: isJson ? JSON.stringify(content) : content,
|
body: isJson ? JSON.stringify(content) : content,
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to create resource: ${response.status}`);
|
const text = await response.text();
|
||||||
|
throw new Error(
|
||||||
|
`failed to create resource (resources/${path}): ${
|
||||||
|
text || response.status
|
||||||
|
}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { render } from "gfm";
|
import { render } from "gfm";
|
||||||
import "https://esm.sh/prismjs@1.29.0/components/prism-typescript?no-check";
|
import "prismjs/components/prism-typescript.js";
|
||||||
import "https://esm.sh/prismjs@1.29.0/components/prism-bash?no-check";
|
import "prismjs/components/prism-bash.js";
|
||||||
import "https://esm.sh/prismjs@1.29.0/components/prism-rust?no-check";
|
import "prismjs/components/prism-rust.js";
|
||||||
|
|
||||||
export type Document = {
|
export type Document = {
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { articleMetadataSchema } from "./marka/schema.ts";
|
|||||||
|
|
||||||
const openAI = OPENAI_API_KEY && new OpenAI({ apiKey: OPENAI_API_KEY });
|
const openAI = OPENAI_API_KEY && new OpenAI({ apiKey: OPENAI_API_KEY });
|
||||||
|
|
||||||
interface MovieRecommendation {
|
export interface MovieRecommendation {
|
||||||
year: number;
|
year: number;
|
||||||
title: string;
|
title: string;
|
||||||
}
|
}
|
||||||
@@ -181,20 +181,37 @@ respond with a plain unordered list each item starting with the year the movie w
|
|||||||
|
|
||||||
if (!res) return;
|
if (!res) return;
|
||||||
|
|
||||||
const recommendations = res.split("\n").map((entry) => {
|
const recommendations = res.split("\n").map((entry: string) => {
|
||||||
const [year, ...title] = entry.split("-");
|
const [year, ...title] = entry.split("-");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
year: parseInt(year.trim()),
|
year: parseInt(year.trim()),
|
||||||
title: title.join(" ").replaceAll('"', "").trim(),
|
title: title.join(" ").replaceAll('"', "").trim(),
|
||||||
};
|
};
|
||||||
}).filter((y) => !Number.isNaN(y.year));
|
}).filter((y: { year: number }) => !Number.isNaN(y.year));
|
||||||
|
|
||||||
cache.set(cacheId, recommendations);
|
cache.set(cacheId, recommendations);
|
||||||
|
|
||||||
return recommendations;
|
return recommendations;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export async function createUnsplashSearchTerm(content: string) {
|
||||||
|
if (!openAI) return;
|
||||||
|
const chatCompletion = await openAI.chat.completions.create({
|
||||||
|
model: model,
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content:
|
||||||
|
"Please respond with a search term for unsplash for the following article",
|
||||||
|
},
|
||||||
|
{ role: "user", content: content.slice(0, 10_000) },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
return chatCompletion.choices[0].message.content?.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
export async function createTags(content: string) {
|
export async function createTags(content: string) {
|
||||||
if (!openAI) return;
|
if (!openAI) return;
|
||||||
const chatCompletion = await openAI.chat.completions.create({
|
const chatCompletion = await openAI.chat.completions.create({
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { firefox } from "npm:playwright-extra";
|
import { firefox } from "playwright-extra";
|
||||||
import { createStreamResponse } from "@lib/helpers.ts";
|
import { createStreamResponse } from "@lib/helpers.ts";
|
||||||
import StealthPlugin from "npm:puppeteer-extra-plugin-stealth";
|
import StealthPlugin from "puppeteer-extra-plugin-stealth";
|
||||||
import * as env from "@lib/env.ts";
|
import * as env from "@lib/env.ts";
|
||||||
|
|
||||||
firefox.use(StealthPlugin());
|
firefox.use(StealthPlugin());
|
||||||
@@ -9,7 +9,7 @@ export async function fetchHtmlWithPlaywright(
|
|||||||
fetchUrl: string,
|
fetchUrl: string,
|
||||||
streamResponse: ReturnType<typeof createStreamResponse>,
|
streamResponse: ReturnType<typeof createStreamResponse>,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
streamResponse.enqueue("booting up playwright");
|
streamResponse.info("booting up playwright");
|
||||||
|
|
||||||
const config: Parameters<typeof firefox.launch>[0] = {};
|
const config: Parameters<typeof firefox.launch>[0] = {};
|
||||||
if (env.PROXY_SERVER) {
|
if (env.PROXY_SERVER) {
|
||||||
@@ -24,7 +24,7 @@ export async function fetchHtmlWithPlaywright(
|
|||||||
// Launch the Playwright browser
|
// Launch the Playwright browser
|
||||||
const browser = await firefox.launch(config);
|
const browser = await firefox.launch(config);
|
||||||
|
|
||||||
streamResponse.enqueue("fetching html");
|
streamResponse.info("fetching html");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Open a new browser context and page
|
// Open a new browser context and page
|
||||||
@@ -42,7 +42,7 @@ export async function fetchHtmlWithPlaywright(
|
|||||||
|
|
||||||
return html;
|
return html;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
streamResponse.enqueue("error fetching html");
|
streamResponse.error("error fetching html");
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return "";
|
return "";
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
105
lib/promise.ts
105
lib/promise.ts
@@ -1,105 +0,0 @@
|
|||||||
/**
|
|
||||||
* Interface zur Beschreibung eines eingereihten Promises in der `PromiseQueue`.
|
|
||||||
*/
|
|
||||||
interface QueuedPromise<T = any> {
|
|
||||||
promise: () => Promise<T>;
|
|
||||||
resolve: (value: T) => void;
|
|
||||||
reject: (reason?: any) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Eine einfache Promise Queue, die es ermöglicht mehrere Aufgaben in kontrollierter
|
|
||||||
* Reihenfolge abzuarbeiten.
|
|
||||||
*
|
|
||||||
* Lizenz: CC BY-NC-SA 4.0
|
|
||||||
* (c) Peter Müller <peter@crycode.de> (https://crycode.de/promise-queue-in-typescript)
|
|
||||||
*/
|
|
||||||
export class PromiseQueue {
|
|
||||||
/**
|
|
||||||
* Eingereihte Promises.
|
|
||||||
*/
|
|
||||||
private queue: QueuedPromise[] = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indikator, dass aktuell ein Promise abgearbeitet wird.
|
|
||||||
*/
|
|
||||||
private working = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ein Promise einreihen.
|
|
||||||
* Dies fügt das Promise der Warteschlange hinzu. Wenn die Warteschlange leer
|
|
||||||
* ist, dann wird das Promise sofort gestartet.
|
|
||||||
* @param promise Funktion, die das Promise zurückgibt.
|
|
||||||
* @returns Ein Promise, welches eingelöst (oder zurückgewiesen) wird sobald das eingereihte Promise abgearbeitet ist.
|
|
||||||
*/
|
|
||||||
public enqueue<T = void>(promise: () => Promise<T>): Promise<T> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.queue.push({
|
|
||||||
promise,
|
|
||||||
resolve,
|
|
||||||
reject,
|
|
||||||
});
|
|
||||||
this.dequeue();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Das erste Promise aus der Warteschlange holen und starten, sofern nicht
|
|
||||||
* bereits ein Promise aktiv ist.
|
|
||||||
* @returns `true` wenn ein Promise aus der Warteschlange gestartet wurde oder `false` wenn bereits ein Promise aktiv oder die Warteschlange leer ist.
|
|
||||||
*/
|
|
||||||
private dequeue(): boolean {
|
|
||||||
if (this.working) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const item = this.queue.shift();
|
|
||||||
if (!item) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.working = true;
|
|
||||||
item.promise()
|
|
||||||
.then((value) => {
|
|
||||||
item.resolve(value);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
item.reject(err);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.working = false;
|
|
||||||
this.dequeue();
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
item.reject(err);
|
|
||||||
this.working = false;
|
|
||||||
this.dequeue();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ConcurrentPromiseQueue {
|
|
||||||
/**
|
|
||||||
* Eingereihte Promises.
|
|
||||||
*/
|
|
||||||
private queues: PromiseQueue[] = [];
|
|
||||||
|
|
||||||
constructor(concurrency: number = 1) {
|
|
||||||
this.queues = Array.from({ length: concurrency }).map(() => {
|
|
||||||
return new PromiseQueue();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private queueIndex = 0;
|
|
||||||
private getQueue() {
|
|
||||||
this.queueIndex = (this.queueIndex + 1) % this.queues.length;
|
|
||||||
return this.queues[this.queueIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
public enqueue<T = void>(promise: () => Promise<T>): Promise<T> {
|
|
||||||
return this.getQueue().enqueue(promise);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { z } from "npm:zod";
|
import { z } from "zod";
|
||||||
import { RecipeResource } from "./marka/schema.ts";
|
import { RecipeResource } from "./marka/schema.ts";
|
||||||
|
|
||||||
export const IngredientSchema = z.object({
|
export const IngredientSchema = z.object({
|
||||||
@@ -18,8 +18,9 @@ export const IngredientGroupSchema = z.object({
|
|||||||
export type IngredientGroup = z.infer<typeof IngredientGroupSchema>;
|
export type IngredientGroup = z.infer<typeof IngredientGroupSchema>;
|
||||||
|
|
||||||
const recipeSchema = z.object({
|
const recipeSchema = z.object({
|
||||||
|
_type: z.literal("Recipe"),
|
||||||
name: z.string().describe(
|
name: z.string().describe(
|
||||||
"Title of the Recipe, without the name of the website or author",
|
"Name of the Recipe, without the name of the website or author",
|
||||||
),
|
),
|
||||||
description: z.string().describe(
|
description: z.string().describe(
|
||||||
"Optional, short description of the recipe",
|
"Optional, short description of the recipe",
|
||||||
@@ -41,11 +42,7 @@ const recipeSchema = z.object({
|
|||||||
|
|
||||||
export type Recipe = z.infer<typeof recipeSchema>;
|
export type Recipe = z.infer<typeof recipeSchema>;
|
||||||
|
|
||||||
const noRecipeSchema = z.object({
|
const noRecipeSchema = z.literal("none").describe("No Recipe found");
|
||||||
errorMessages: z.array(z.string()).describe(
|
|
||||||
"List of error messages, if no recipe was found",
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const recipeResponseSchema = z.union([recipeSchema, noRecipeSchema]);
|
export const recipeResponseSchema = z.union([recipeSchema, noRecipeSchema]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as openai from "@lib/openai.ts";
|
import * as openai from "@lib/openai.ts";
|
||||||
|
import { type MovieRecommendation } from "@lib/openai.ts";
|
||||||
import * as tmdb from "@lib/tmdb.ts";
|
import * as tmdb from "@lib/tmdb.ts";
|
||||||
import { parseRating } from "@lib/helpers.ts";
|
import { parseRating } from "@lib/helpers.ts";
|
||||||
import { createCache } from "@lib/cache.ts";
|
import { createCache } from "@lib/cache.ts";
|
||||||
@@ -60,8 +61,10 @@ export async function createRecommendationResource(
|
|||||||
const d = typeof datePublished === "string"
|
const d = typeof datePublished === "string"
|
||||||
? new Date(datePublished)
|
? new Date(datePublished)
|
||||||
: datePublished;
|
: datePublished;
|
||||||
|
if (!isNaN(d.getTime())) {
|
||||||
resource.year = d.getFullYear();
|
resource.year = d.getFullYear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cache.set(cacheId, JSON.stringify(resource));
|
cache.set(cacheId, JSON.stringify(resource));
|
||||||
}
|
}
|
||||||
@@ -74,7 +77,7 @@ export function getRecommendation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getSimilarMovies(id: string) {
|
export async function getSimilarMovies(id: string) {
|
||||||
const recs = getRecommendation(id, "movie");
|
const recs = getRecommendation(id, "movies");
|
||||||
if (!recs?.keywords?.length) return;
|
if (!recs?.keywords?.length) return;
|
||||||
|
|
||||||
const recommendations = await openai.getMovieRecommendations(
|
const recommendations = await openai.getMovieRecommendations(
|
||||||
@@ -83,10 +86,12 @@ export async function getSimilarMovies(id: string) {
|
|||||||
);
|
);
|
||||||
if (!recommendations) return;
|
if (!recommendations) return;
|
||||||
|
|
||||||
const movies = await Promise.all(recommendations.map(async (rec) => {
|
const movies = await Promise.all(
|
||||||
|
recommendations.map(async (rec: MovieRecommendation) => {
|
||||||
const m = await tmdb.searchMovie(rec.title, rec.year);
|
const m = await tmdb.searchMovie(rec.title, rec.year);
|
||||||
return m?.results?.[0];
|
return m?.results?.[0];
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
return movies.filter(Boolean);
|
return movies.filter(Boolean);
|
||||||
}
|
}
|
||||||
@@ -96,5 +101,7 @@ export async function getAllRecommendations(): Promise<
|
|||||||
> {
|
> {
|
||||||
const keys = cache.keys();
|
const keys = cache.keys();
|
||||||
const res = await Promise.all(keys.map((k) => cache.get(k)));
|
const res = await Promise.all(keys.map((k) => cache.get(k)));
|
||||||
return res.filter((s) => !!s).map((r) => JSON.parse(r));
|
return res.filter((s) => !!s).map((r) =>
|
||||||
|
typeof r === "string" ? JSON.parse(r) : r
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
export const resources = {
|
export const resources = {
|
||||||
"home": {
|
"home": {
|
||||||
emoji: "House with Garden.png",
|
emoji: "home_icon.png",
|
||||||
name: "Home",
|
name: "Home",
|
||||||
link: "/",
|
link: "/",
|
||||||
},
|
},
|
||||||
"recipe": {
|
"recipe": {
|
||||||
emoji: "Fork and Knife with Plate.png",
|
emoji: "recipes_icon.png",
|
||||||
name: "Recipes",
|
name: "Recipes",
|
||||||
link: "/recipes",
|
link: "/recipes",
|
||||||
},
|
},
|
||||||
"movie": {
|
"movie": {
|
||||||
emoji: "Popcorn.png",
|
emoji: "movies_icon.png",
|
||||||
name: "Movies",
|
name: "Movies",
|
||||||
link: "/movies",
|
link: "/movies",
|
||||||
},
|
},
|
||||||
"article": {
|
"article": {
|
||||||
emoji: "Writing Hand Medium-Light Skin Tone.png",
|
emoji: "articles_icon.png",
|
||||||
name: "Articles",
|
name: "Articles",
|
||||||
link: "/articles",
|
link: "/articles",
|
||||||
},
|
},
|
||||||
"series": {
|
"series": {
|
||||||
emoji: "Television.png",
|
emoji: "tv_series_icon.png",
|
||||||
name: "Series",
|
name: "Series",
|
||||||
link: "/series",
|
link: "/series",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export function parseResourceUrl(_url: string | URL): SearchParams | undefined {
|
|||||||
try {
|
try {
|
||||||
const url = typeof _url === "string" ? new URL(_url) : _url;
|
const url = typeof _url === "string" ? new URL(_url) : _url;
|
||||||
let query = url.searchParams.get("q") || "*";
|
let query = url.searchParams.get("q") || "*";
|
||||||
if (!query) {
|
if (!(typeof query === "string")) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
query = decodeURIComponent(query);
|
query = decodeURIComponent(query);
|
||||||
@@ -54,12 +54,14 @@ export async function searchResource(
|
|||||||
{ q, tags = [], types, rating }: SearchParams,
|
{ q, tags = [], types, rating }: SearchParams,
|
||||||
): Promise<GenericResource[]> {
|
): Promise<GenericResource[]> {
|
||||||
const resources = (await Promise.all([
|
const resources = (await Promise.all([
|
||||||
(!types || types.includes("movie")) && listResources("movies"),
|
(!types || types.includes("movies")) && listResources("movies"),
|
||||||
(!types || types.includes("series")) && listResources("series"),
|
(!types || types.includes("series")) && listResources("series"),
|
||||||
(!types || types.includes("article")) && listResources("articles"),
|
(!types || types.includes("articles")) && listResources("articles"),
|
||||||
(!types || types.includes("recipe")) && listResources("recipes"),
|
(!types || types.includes("recipes")) && listResources("recipes"),
|
||||||
])).flat().filter(isResource);
|
])).flat().filter(isResource);
|
||||||
|
|
||||||
|
console.log({ types, rating, tags, q, resourceLength: resources.length });
|
||||||
|
|
||||||
const results: Record<string, GenericResource> = {};
|
const results: Record<string, GenericResource> = {};
|
||||||
|
|
||||||
for (const resource of resources) {
|
for (const resource of resources) {
|
||||||
@@ -71,9 +73,18 @@ export async function searchResource(
|
|||||||
results[resource.name] = resource;
|
results[resource.name] = resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select not-rated resources
|
||||||
if (
|
if (
|
||||||
!(resource.name in results) &&
|
rating === 0 &&
|
||||||
rating && resource.content.reviewRating?.ratingValue &&
|
resource.content?.reviewRating?.ratingValue === undefined
|
||||||
|
) {
|
||||||
|
results[resource.name] = resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof rating === "number" &&
|
||||||
|
rating !== 0 &&
|
||||||
|
resource.content.reviewRating?.ratingValue &&
|
||||||
parseRating(resource.content.reviewRating.ratingValue) >= rating
|
parseRating(resource.content.reviewRating.ratingValue) >= rating
|
||||||
) {
|
) {
|
||||||
results[resource.name] = resource;
|
results[resource.name] = resource;
|
||||||
@@ -81,6 +92,7 @@ export async function searchResource(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (q.length && q !== "*") {
|
if (q.length && q !== "*") {
|
||||||
|
q = decodeURIComponent(q);
|
||||||
const fuzzyResult = fuzzysort.go(q, resources, {
|
const fuzzyResult = fuzzysort.go(q, resources, {
|
||||||
keys: [
|
keys: [
|
||||||
"name",
|
"name",
|
||||||
@@ -92,6 +104,7 @@ export async function searchResource(
|
|||||||
],
|
],
|
||||||
threshold: 0.3,
|
threshold: 0.3,
|
||||||
});
|
});
|
||||||
|
console.log({ fuzzyResult });
|
||||||
for (const result of fuzzyResult) {
|
for (const result of fuzzyResult) {
|
||||||
results[result.obj.name] = result.obj;
|
results[result.obj.name] = result.obj;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,37 @@
|
|||||||
export function formatDate(date: Date): string {
|
export function formatDate(date?: string | Date): string {
|
||||||
|
if (!date) return "";
|
||||||
|
if (typeof date === "string") {
|
||||||
|
try {
|
||||||
|
const d = new Date(date);
|
||||||
|
return formatDate(d);
|
||||||
|
} catch (_e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
const options = { year: "numeric", month: "long", day: "numeric" } as const;
|
const options = { year: "numeric", month: "long", day: "numeric" } as const;
|
||||||
return new Intl.DateTimeFormat("en-US", options).format(date);
|
return new Intl.DateTimeFormat("en-US", options).format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function safeFileName(inputString: string): string {
|
export function safeFileName(input: string): string {
|
||||||
let fileName = inputString.toLowerCase();
|
return input
|
||||||
fileName = fileName.replace(/ /g, "_");
|
.normalize("NFKD")
|
||||||
fileName = fileName.replace(/[^\w.-]/g, "");
|
.replace(/[\u0300-\u036f]/g, "")
|
||||||
fileName = fileName.replaceAll(":", "");
|
.replace(/[\s-]+/g, "_")
|
||||||
return fileName;
|
.replace(/-+/g, "-")
|
||||||
|
.replace(/[^A-Za-z0-9_]+/g, "")
|
||||||
|
.replace(/_+/g, "_")
|
||||||
|
// Trim underscores/dots from ends and prevent leading dots
|
||||||
|
.replace(/^[_\.]+|[_\.]+$/g, "").replace(/^\.+/, "")
|
||||||
|
.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toUrlSafeString(input: string): string {
|
export function toUrlSafeString(input: string): string {
|
||||||
return input
|
return input
|
||||||
.trim() // Remove leading and trailing whitespace
|
.normalize("NFKD")
|
||||||
.toLowerCase() // Convert to lowercase
|
.replace(/[\u0300-\u036f]/g, "")
|
||||||
.replace(/[^a-z0-9\s-]/g, "") // Remove non-alphanumeric characters except spaces and hyphens
|
.replace(/[^A-Za-z0-9 _-]+/g, "")
|
||||||
.replace(/\s+/g, "-") // Replace spaces with hyphens
|
.replace(/\s+/g, " ")
|
||||||
.replace(/-+/g, "-"); // Remove consecutive hyphens
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractHashTags(inputString: string) {
|
export function extractHashTags(inputString: string) {
|
||||||
@@ -172,3 +186,7 @@ export function removeMarkdownFormatting(text: string): string {
|
|||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fileExtension(fname: string) {
|
||||||
|
return fname.slice((fname.lastIndexOf(".") - 1 >>> 0) + 2);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,110 +0,0 @@
|
|||||||
import { transcribe } from "@lib/openai.ts";
|
|
||||||
import { createResource } from "@lib/marka/index.ts";
|
|
||||||
import { createLogger } from "./log/index.ts";
|
|
||||||
import { convertOggToMp3 } from "./helpers.ts";
|
|
||||||
|
|
||||||
const log = createLogger("taskManager");
|
|
||||||
|
|
||||||
// In-memory task state
|
|
||||||
const activeTasks: Record<
|
|
||||||
string,
|
|
||||||
{
|
|
||||||
noteName: string;
|
|
||||||
entries: Array<
|
|
||||||
{ type: string; content: string | ArrayBufferLike; fileName?: string }
|
|
||||||
>;
|
|
||||||
}
|
|
||||||
> = {};
|
|
||||||
|
|
||||||
export function startTask(chatId: string, noteName: string) {
|
|
||||||
activeTasks[chatId] = { noteName, entries: [] };
|
|
||||||
log.info(`Started note: ${noteName}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function endTask(chatId: string): Promise<string | null> {
|
|
||||||
const task = activeTasks[chatId];
|
|
||||||
if (!task) return null;
|
|
||||||
|
|
||||||
log.info("Ending note", task.noteName);
|
|
||||||
|
|
||||||
let finalNote = `# ${task.noteName}\n\n`;
|
|
||||||
|
|
||||||
const photoTasks: { content: ArrayBuffer; path: string }[] = [];
|
|
||||||
|
|
||||||
let photoIndex = 0;
|
|
||||||
for (const entry of task.entries) {
|
|
||||||
if (entry.type === "text") {
|
|
||||||
finalNote += entry.content + "\n\n";
|
|
||||||
} else if (entry.type === "voice") {
|
|
||||||
try {
|
|
||||||
log.info("Converting OGG to MP3");
|
|
||||||
const mp3Data = await convertOggToMp3(entry.content as ArrayBuffer);
|
|
||||||
log.info("Finished converting OGG to MP3, transcribing...");
|
|
||||||
const transcript = await transcribe(mp3Data);
|
|
||||||
finalNote += `**Voice Transcript:**\n${transcript}\n\n`;
|
|
||||||
log.info("Finished transcribing");
|
|
||||||
} catch (error) {
|
|
||||||
log.error(error);
|
|
||||||
finalNote += "**[Voice message could not be transcribed]**\n\n";
|
|
||||||
}
|
|
||||||
} else if (entry.type === "photo") {
|
|
||||||
const photoUrl = `${
|
|
||||||
task.noteName.replace(/\.md$/, "")
|
|
||||||
}/photo-${photoIndex++}.jpg`;
|
|
||||||
|
|
||||||
finalNote += `**Photo**:\n ${photoUrl}\n\n`;
|
|
||||||
photoTasks.push({
|
|
||||||
content: entry.content as ArrayBuffer,
|
|
||||||
path: photoUrl,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (const entry of photoTasks) {
|
|
||||||
await createResource(entry.path, entry.content);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
log.error("Error creating photo document:", err);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await createResource(task.noteName, finalNote);
|
|
||||||
} catch (error) {
|
|
||||||
log.error("Error creating document:", error);
|
|
||||||
return error instanceof Error
|
|
||||||
? error.toString()
|
|
||||||
: "Error creating document";
|
|
||||||
}
|
|
||||||
|
|
||||||
delete activeTasks[chatId];
|
|
||||||
log.debug({ finalNote });
|
|
||||||
return finalNote;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addTextEntry(chatId: string, text: string) {
|
|
||||||
const task = activeTasks[chatId];
|
|
||||||
if (!task) return;
|
|
||||||
const entry = { type: "text", content: text };
|
|
||||||
log.debug("New Entry", entry);
|
|
||||||
task.entries.push(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addVoiceEntry(chatId: string, buffer: ArrayBufferLike) {
|
|
||||||
const task = activeTasks[chatId];
|
|
||||||
if (!task) return;
|
|
||||||
const entry = { type: "voice", content: buffer };
|
|
||||||
log.debug("New Entry", entry);
|
|
||||||
task.entries.push(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addPhotoEntry(
|
|
||||||
chatId: string,
|
|
||||||
buffer: ArrayBufferLike,
|
|
||||||
fileName: string,
|
|
||||||
) {
|
|
||||||
const task = activeTasks[chatId];
|
|
||||||
if (!task) return;
|
|
||||||
const entry = { type: "photo", content: buffer, fileName };
|
|
||||||
log.debug("New Entry", entry);
|
|
||||||
task.entries.push(entry);
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
import { Bot } from "https://deno.land/x/grammy@v1.36.1/mod.ts";
|
|
||||||
import { TELEGRAM_API_KEY } from "@lib/env.ts";
|
|
||||||
import { createLogger } from "./log/index.ts";
|
|
||||||
|
|
||||||
const bot = new Bot(TELEGRAM_API_KEY);
|
|
||||||
const log = createLogger("telegram");
|
|
||||||
|
|
||||||
import * as manager from "./taskManager.ts";
|
|
||||||
|
|
||||||
async function downloadFile(filePath: string): Promise<Uint8Array> {
|
|
||||||
log.info(`Downloading file from path: ${filePath}`);
|
|
||||||
const url = `https://api.telegram.org/file/bot${bot.token}/${filePath}`;
|
|
||||||
const response = await fetch(url);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error("Failed to download file: " + response.statusText);
|
|
||||||
}
|
|
||||||
log.info("File downloaded successfully");
|
|
||||||
const buffer = await response.arrayBuffer();
|
|
||||||
return new Uint8Array(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.command("start", async (ctx) => {
|
|
||||||
log.info("Received /start command");
|
|
||||||
const [_, noteName] = ctx.message?.text?.split(" ") || [];
|
|
||||||
if (!noteName) {
|
|
||||||
return ctx.reply("Please provide a note name. Usage: /start NoteName");
|
|
||||||
}
|
|
||||||
manager.startTask(ctx.chat.id.toString(), noteName);
|
|
||||||
await ctx.reply(`Started note: ${noteName}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.command("end", async (ctx) => {
|
|
||||||
log.info("Received /end command");
|
|
||||||
const finalNote = await manager.endTask(ctx.chat.id.toString());
|
|
||||||
if (!finalNote) return ctx.reply("No active note found.");
|
|
||||||
|
|
||||||
try {
|
|
||||||
await ctx.reply("Note complete. Here is your markdown:");
|
|
||||||
await ctx.reply(finalNote, { parse_mode: "MarkdownV2" });
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error sending final note:", err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on("message:text", (ctx) => {
|
|
||||||
log.info("Received text message");
|
|
||||||
manager.addTextEntry(ctx.chat.id.toString(), ctx.message.text);
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on("message:voice", async (ctx) => {
|
|
||||||
log.info("Received photo message");
|
|
||||||
log.info("Received voice message");
|
|
||||||
const file = await ctx.getFile();
|
|
||||||
const buffer = await downloadFile(file.file_path!);
|
|
||||||
manager.addVoiceEntry(ctx.chat.id.toString(), buffer.buffer);
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on("message:photo", async (ctx) => {
|
|
||||||
const file = await ctx.getFile();
|
|
||||||
const buffer = await downloadFile(file.file_path!);
|
|
||||||
const fileName = file.file_path!.split("/").pop()!;
|
|
||||||
manager.addPhotoEntry(ctx.chat.id.toString(), buffer.buffer, fileName);
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.start();
|
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
import * as thumbhash from "thumbhash";
|
import * as thumbhash from "thumbhash";
|
||||||
|
|
||||||
export function generateThumbhash(buffer: Uint8Array, w: number, h: number) {
|
export function generateThumbhash(
|
||||||
|
buffer: ArrayLike<number>,
|
||||||
|
w: number,
|
||||||
|
h: number,
|
||||||
|
) {
|
||||||
const hash = thumbhash.rgbaToThumbHash(w, h, buffer);
|
const hash = thumbhash.rgbaToThumbHash(w, h, buffer);
|
||||||
return [hash, thumbhash.thumbHashToAverageRGBA(hash)] as const;
|
return [hash, thumbhash.thumbHashToAverageRGBA(hash)] as const;
|
||||||
}
|
}
|
||||||
|
|||||||
29
lib/unsplash.ts
Normal file
29
lib/unsplash.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { UNSPLASH_API_KEY } from "./env.ts";
|
||||||
|
|
||||||
|
const API_URL = "https://api.unsplash.com";
|
||||||
|
|
||||||
|
export async function getImageBySearchTerm(
|
||||||
|
searchTerm: string,
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
if (!UNSPLASH_API_KEY) {
|
||||||
|
throw new Error("UNSPLASH_API_KEY is not set");
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL("/search/photos", API_URL);
|
||||||
|
url.searchParams.append("query", searchTerm);
|
||||||
|
url.searchParams.append("per_page", "1");
|
||||||
|
url.searchParams.append("orientation", "landscape");
|
||||||
|
|
||||||
|
const response = await fetch(url.toString(), {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Client-ID ${UNSPLASH_API_KEY}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Unsplash API request failed: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
return data.results[0]?.urls?.regular;
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import { JSDOM } from "jsdom";
|
import { JSDOM } from "jsdom";
|
||||||
import { fetchHtmlWithPlaywright } from "./playwright.ts";
|
import { fetchHtmlWithPlaywright } from "./playwright.ts";
|
||||||
import { createStreamResponse } from "./helpers.ts";
|
import { createStreamResponse } from "./helpers.ts";
|
||||||
|
import { Defuddle } from "defuddle/node";
|
||||||
|
import TurndownService from "turndown";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mutates the given JSDOM instance: rewrites all relevant URL-bearing attributes
|
* Mutates the given JSDOM instance: rewrites all relevant URL-bearing attributes
|
||||||
@@ -45,7 +47,7 @@ export function absolutizeDomUrls(dom: JSDOM, domain: string): void {
|
|||||||
|
|
||||||
document
|
document
|
||||||
.querySelectorAll("img[srcset], source[srcset]")
|
.querySelectorAll("img[srcset], source[srcset]")
|
||||||
.forEach((el: HTMLImageElement) => {
|
.forEach((el) => {
|
||||||
const v = el.getAttribute("srcset");
|
const v = el.getAttribute("srcset");
|
||||||
if (!v) return;
|
if (!v) return;
|
||||||
const abs = absolutizeSrcset(v, base);
|
const abs = absolutizeSrcset(v, base);
|
||||||
@@ -53,7 +55,7 @@ export function absolutizeDomUrls(dom: JSDOM, domain: string): void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
document.querySelectorAll("[style]").forEach(
|
document.querySelectorAll("[style]").forEach(
|
||||||
(el: HTMLElement) => {
|
(el) => {
|
||||||
const v = el.getAttribute("style");
|
const v = el.getAttribute("style");
|
||||||
if (!v) return;
|
if (!v) return;
|
||||||
const abs = absolutizeCssUrls(v, base);
|
const abs = absolutizeCssUrls(v, base);
|
||||||
@@ -71,7 +73,7 @@ export function absolutizeDomUrls(dom: JSDOM, domain: string): void {
|
|||||||
|
|
||||||
document
|
document
|
||||||
.querySelectorAll('meta[http-equiv="refresh" i][content]')
|
.querySelectorAll('meta[http-equiv="refresh" i][content]')
|
||||||
.forEach((meta: HTMLMetaElement) => {
|
.forEach((meta) => {
|
||||||
const content = meta.getAttribute("content") || "";
|
const content = meta.getAttribute("content") || "";
|
||||||
const abs = absolutizeMetaRefresh(content, base);
|
const abs = absolutizeMetaRefresh(content, base);
|
||||||
if (abs !== content) meta.setAttribute("content", abs);
|
if (abs !== content) meta.setAttribute("content", abs);
|
||||||
@@ -164,13 +166,32 @@ function absolutizeMetaRefresh(content: string, base: string): string {
|
|||||||
return `${delay}; url=${abs}`;
|
return `${delay}; url=${abs}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const turndownService = new TurndownService();
|
||||||
|
|
||||||
|
export interface WebScrapeResult {
|
||||||
|
title?: string;
|
||||||
|
image?: string;
|
||||||
|
published?: string;
|
||||||
|
content: string;
|
||||||
|
schemaOrgData?: { author?: { name?: string } };
|
||||||
|
markdown: string;
|
||||||
|
dom: JSDOM["window"]["document"];
|
||||||
|
}
|
||||||
|
|
||||||
export async function webScrape(
|
export async function webScrape(
|
||||||
url: string,
|
url: string,
|
||||||
streamResponse: ReturnType<typeof createStreamResponse>,
|
streamResponse: ReturnType<typeof createStreamResponse>,
|
||||||
): JSDOM {
|
) {
|
||||||
const u = new URL(url);
|
const u = new URL(url);
|
||||||
const html = await fetchHtmlWithPlaywright(url, streamResponse);
|
const html = await fetchHtmlWithPlaywright(url, streamResponse);
|
||||||
const dom = new JSDOM(html);
|
const dom = new JSDOM(html);
|
||||||
absolutizeDomUrls(dom, u.origin);
|
absolutizeDomUrls(dom, u.origin);
|
||||||
return dom;
|
|
||||||
|
const result = await Defuddle(dom, url);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
dom: dom.window.document,
|
||||||
|
markdown: turndownService.turndown(result.content),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,12 +56,10 @@ export interface ContentDetails {
|
|||||||
definition: string;
|
definition: string;
|
||||||
caption: string;
|
caption: string;
|
||||||
licensedContent: boolean;
|
licensedContent: boolean;
|
||||||
contentRating: ContentRating;
|
contentRating: Record<string, unknown>;
|
||||||
projection: string;
|
projection: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ContentRating {}
|
|
||||||
|
|
||||||
export interface Statistics {
|
export interface Statistics {
|
||||||
viewCount: string;
|
viewCount: string;
|
||||||
likeCount: string;
|
likeCount: string;
|
||||||
@@ -74,6 +72,11 @@ export interface PageInfo {
|
|||||||
resultsPerPage: number;
|
resultsPerPage: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getYoutubeVideoCover(id: string): Promise<ArrayBuffer> {
|
||||||
|
const res = await fetch(`https://i.ytimg.com/vi/${id}/maxresdefault.jpg`);
|
||||||
|
return res.arrayBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
export async function getYoutubeVideoDetails(
|
export async function getYoutubeVideoDetails(
|
||||||
id: string,
|
id: string,
|
||||||
): Promise<Item> {
|
): Promise<Item> {
|
||||||
@@ -81,6 +84,5 @@ export async function getYoutubeVideoDetails(
|
|||||||
`${BASE_URL}videos?part=snippet%2CcontentDetails%2Cstatistics&id=${id}&key=${YOUTUBE_API_KEY}`,
|
`${BASE_URL}videos?part=snippet%2CcontentDetails%2Cstatistics&id=${id}&key=${YOUTUBE_API_KEY}`,
|
||||||
);
|
);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
|
||||||
return json?.items[0];
|
return json?.items[0];
|
||||||
}
|
}
|
||||||
|
|||||||
16
main.ts
16
main.ts
@@ -1,12 +1,8 @@
|
|||||||
/// <reference no-default-lib="true" />
|
import { App, staticFiles } from "fresh";
|
||||||
/// <reference lib="dom" />
|
import { type State } from "./utils.ts";
|
||||||
/// <reference lib="dom.iterable" />
|
|
||||||
/// <reference lib="dom.asynciterable" />
|
|
||||||
/// <reference lib="deno.ns" />
|
|
||||||
|
|
||||||
import { start } from "$fresh/server.ts";
|
export const app = new App<State>();
|
||||||
import manifest from "./fresh.gen.ts";
|
|
||||||
import config from "./fresh.config.ts";
|
|
||||||
// import "@lib/telegram.ts";
|
|
||||||
|
|
||||||
await start(manifest, config);
|
app.use(staticFiles());
|
||||||
|
|
||||||
|
app.fsRoutes();
|
||||||
|
|||||||
@@ -1,35 +1,47 @@
|
|||||||
import { PageProps } from "$fresh/server.ts";
|
import { define } from "../utils.ts";
|
||||||
import { Partial } from "$fresh/runtime.ts";
|
|
||||||
import { useEffect } from "preact/hooks";
|
|
||||||
|
|
||||||
export default function App({ Component }: PageProps) {
|
|
||||||
const globalCss = Deno
|
|
||||||
.readTextFileSync("./static/global.css")
|
|
||||||
.replaceAll("\n", "");
|
|
||||||
|
|
||||||
|
export default define.page(function ({ Component }) {
|
||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="/prism-material-dark.css" />
|
<link rel="stylesheet" href="/prism-material-dark.css" />
|
||||||
<link rel="stylesheet" href="/styles.css" />
|
|
||||||
<link
|
<link
|
||||||
rel="icon"
|
rel="icon"
|
||||||
type="image/png"
|
type="image/png"
|
||||||
href="/favicon.png"
|
href="/favicon.png"
|
||||||
/>
|
/>
|
||||||
<link rel="manifest" href="/site.webmanifest" />
|
<link rel="manifest" href="/site.webmanifest" />
|
||||||
|
<link
|
||||||
|
rel="preload"
|
||||||
|
href="/fonts/work-sans-v18-latin-regular.woff2"
|
||||||
|
as="font"
|
||||||
|
type="font/woff2"
|
||||||
|
/>
|
||||||
|
<link
|
||||||
|
rel="preload"
|
||||||
|
href="/fonts/work-sans-v18-latin-700.woff2"
|
||||||
|
as="font"
|
||||||
|
type="font/woff2"
|
||||||
|
/>
|
||||||
|
<link rel="stylesheet" href="/global.css" />
|
||||||
|
|
||||||
<meta name="msapplication-TileColor" content="#da532c" />
|
<meta name="msapplication-TileColor" content="#da532c" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<meta name="theme-color" content="#141218" />
|
<meta name="theme-color" content="#141218" />
|
||||||
<style>{globalCss}</style>
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<style
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: Deno.readTextFileSync("./static/global.css"),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
</style>
|
||||||
|
|
||||||
<title>Memorium</title>
|
<title>Memorium</title>
|
||||||
</head>
|
</head>
|
||||||
<body f-client-nav>
|
<body>
|
||||||
<Partial name="body">
|
|
||||||
<Component />
|
<Component />
|
||||||
</Partial>
|
|
||||||
</body>
|
</body>
|
||||||
<script src="/thumbhash.js" type="module" async defer />
|
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
import { Head } from "$fresh/runtime.ts";
|
import { Head } from "fresh/runtime";
|
||||||
import { MainLayout } from "@components/layouts/main.tsx";
|
import { MainLayout } from "@components/layouts/main.tsx";
|
||||||
|
import { HttpError, PageProps } from "fresh";
|
||||||
|
|
||||||
|
export default function ErrorPage(props: PageProps) {
|
||||||
|
const error = props.error; // Contains the thrown Error or HTTPError
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
const status = error.status; // HTTP status code
|
||||||
|
|
||||||
|
// Render a 404 not found page
|
||||||
|
if (status === 404) {
|
||||||
|
return <h1>404 - Page not found</h1>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function Error404() {
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
@@ -9,7 +20,7 @@ export default function Error404() {
|
|||||||
</Head>
|
</Head>
|
||||||
<MainLayout url="">
|
<MainLayout url="">
|
||||||
<div class="px-8 text-white mt-10">
|
<div class="px-8 text-white mt-10">
|
||||||
<div class="max-w-screen-md mx-auto flex flex-col items-center justify-center">
|
<div class="max-w-3xl mx-auto flex flex-col items-center justify-center">
|
||||||
<h1 class="text-4xl font-bold">404 - Page not found</h1>
|
<h1 class="text-4xl font-bold">404 - Page not found</h1>
|
||||||
<p class="my-4">
|
<p class="my-4">
|
||||||
The page you were looking for doesn't exist.
|
The page you were looking for doesn't exist.
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import { PageProps } from "$fresh/server.ts";
|
|
||||||
import { resources } from "@lib/resources.ts";
|
import { resources } from "@lib/resources.ts";
|
||||||
import { Link } from "@islands/Link.tsx";
|
|
||||||
import { Emoji } from "@components/Emoji.tsx";
|
import { Emoji } from "@components/Emoji.tsx";
|
||||||
|
import KMenuButton from "@islands/KMenuButton.tsx";
|
||||||
|
import { PageProps } from "fresh";
|
||||||
|
import { define } from "../utils.ts";
|
||||||
|
|
||||||
export default function MyLayout({ Component }: PageProps) {
|
export default define.layout(function ({ Component }: PageProps) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class="md:grid mx-auto"
|
class="md:grid mx-auto"
|
||||||
@@ -13,22 +14,20 @@ export default function MyLayout({ Component }: PageProps) {
|
|||||||
<nav class="min-h-fit rounded-3xl p-3 grid gap-3 fixed t-0">
|
<nav class="min-h-fit rounded-3xl p-3 grid gap-3 fixed t-0">
|
||||||
{Object.values(resources).map((m) => {
|
{Object.values(resources).map((m) => {
|
||||||
return (
|
return (
|
||||||
<Link
|
<a
|
||||||
href={m.link}
|
href={m.link}
|
||||||
class="flex items-center gap-2 text-white data-[current]:bg-white data-[current]:text-black p-3 text-xl w-full rounded-2xl"
|
class="flex items-center gap-2 text-white data-current:bg-white data-current:text-black p-3 text-xl w-full rounded-2xl"
|
||||||
>
|
>
|
||||||
<Emoji class="w-6 h-6" name={m.emoji} /> {m.name}
|
<Emoji class="w-6 h-6" name={m.emoji} /> {m.name}
|
||||||
</Link>
|
</a>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</nav>
|
</nav>
|
||||||
</aside>
|
</aside>
|
||||||
<main
|
<main class="py-5">
|
||||||
class="py-5"
|
|
||||||
style={{ fontFamily: "Work Sans" }}
|
|
||||||
>
|
|
||||||
<Component />
|
<Component />
|
||||||
</main>
|
</main>
|
||||||
|
<KMenuButton />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|||||||
@@ -1,27 +1,39 @@
|
|||||||
//routes/middleware-error-handler/_middleware.ts
|
|
||||||
import { FreshContext } from "$fresh/server.ts";
|
|
||||||
import { DomainError } from "@lib/errors.ts";
|
import { DomainError } from "@lib/errors.ts";
|
||||||
import { getCookies } from "@std/http/cookie";
|
import { getCookies } from "@std/http/cookie";
|
||||||
import { verify } from "https://deno.land/x/djwt@v2.2/mod.ts";
|
import { verify } from "@zaubrik/djwt";
|
||||||
import * as perf from "@lib/performance.ts";
|
import * as perf from "@lib/performance.ts";
|
||||||
import { JWT_SECRET } from "@lib/env.ts";
|
import { JWT_SECRET } from "@lib/env.ts";
|
||||||
|
import { define } from "../utils.ts";
|
||||||
|
|
||||||
export async function handler(
|
function importKey(secret: string) {
|
||||||
req: Request,
|
return crypto.subtle.importKey(
|
||||||
ctx: FreshContext,
|
"raw",
|
||||||
|
new TextEncoder().encode(secret),
|
||||||
|
{ name: "HMAC", hash: "SHA-512" },
|
||||||
|
false,
|
||||||
|
["sign", "verify"],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const authMiddleware = define.middleware(async function (
|
||||||
|
ctx,
|
||||||
) {
|
) {
|
||||||
|
const req = ctx.req;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
performance.mark("a");
|
performance.mark("a");
|
||||||
const allCookies = getCookies(req.headers);
|
const allCookies = getCookies(req.headers);
|
||||||
const sessionCookie = allCookies["session_cookie"];
|
const sessionCookie = allCookies["session_cookie"];
|
||||||
if (!ctx.state.session && sessionCookie && JWT_SECRET) {
|
if (!ctx.state.session && sessionCookie && JWT_SECRET) {
|
||||||
try {
|
try {
|
||||||
const payload = await verify(sessionCookie, JWT_SECRET, "HS512");
|
const payload = await verify<typeof ctx.state.session>(
|
||||||
|
sessionCookie,
|
||||||
|
await importKey(JWT_SECRET),
|
||||||
|
);
|
||||||
if (payload) {
|
if (payload) {
|
||||||
ctx.state.session = payload;
|
ctx.state.session = payload;
|
||||||
}
|
}
|
||||||
} catch (_err) {
|
} catch (_err) {
|
||||||
//
|
|
||||||
console.log({ _err });
|
console.log({ _err });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,4 +56,6 @@ export async function handler(
|
|||||||
status: 500,
|
status: 500,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
export default [authMiddleware];
|
||||||
|
|||||||
32
routes/admin/cache/index.tsx
vendored
32
routes/admin/cache/index.tsx
vendored
@@ -1,32 +0,0 @@
|
|||||||
import { MainLayout } from "@components/layouts/main.tsx";
|
|
||||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
|
||||||
import { getCacheInfo } from "@lib/cache.ts";
|
|
||||||
|
|
||||||
export const handler: Handlers<
|
|
||||||
{ cacheInfo: ReturnType<typeof getCacheInfo> }
|
|
||||||
> = {
|
|
||||||
GET(_, ctx) {
|
|
||||||
return ctx.render({ cacheInfo: getCacheInfo() });
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function Greet(
|
|
||||||
props: PageProps<
|
|
||||||
{ cacheInfo: ReturnType<typeof getCacheInfo> }
|
|
||||||
>,
|
|
||||||
) {
|
|
||||||
const { cacheInfo } = props.data;
|
|
||||||
return (
|
|
||||||
<MainLayout
|
|
||||||
url={props.url}
|
|
||||||
title="Recipes"
|
|
||||||
context={{ type: "recipe" }}
|
|
||||||
>
|
|
||||||
<code>
|
|
||||||
<pre class="text-white">
|
|
||||||
{JSON.stringify(cacheInfo, null, 2)}
|
|
||||||
</pre>
|
|
||||||
</code>
|
|
||||||
</MainLayout>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
import { MainLayout } from "@components/layouts/main.tsx";
|
|
||||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
|
||||||
import { AccessDeniedError } from "@lib/errors.ts";
|
|
||||||
import { getLogs, Log } from "@lib/log/index.ts";
|
|
||||||
import { formatDate } from "@lib/string.ts";
|
|
||||||
import { renderMarkdown } from "@lib/markdown.ts";
|
|
||||||
|
|
||||||
const renderLog = (t: unknown) =>
|
|
||||||
renderMarkdown(`\`\`\`js
|
|
||||||
${typeof t === "string" ? t : JSON.stringify(t, null, 2).trim()}
|
|
||||||
\`\`\``);
|
|
||||||
|
|
||||||
export const handler: Handlers = {
|
|
||||||
async GET(_, ctx) {
|
|
||||||
const logs = await getLogs();
|
|
||||||
if (!("session" in ctx.state)) {
|
|
||||||
throw new AccessDeniedError();
|
|
||||||
}
|
|
||||||
return ctx.render({
|
|
||||||
logs: logs.map((l) => {
|
|
||||||
return {
|
|
||||||
...l,
|
|
||||||
html: l.args.map(renderLog).join("<br/>"),
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
function LogLine(
|
|
||||||
{ log }: {
|
|
||||||
log: Log & { html?: string };
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
class="mt-4 flex flex-col gap-2 bg-gray-900 px-4 py-2 rounded-2xl max-w-3xl"
|
|
||||||
style={{ background: "var(--light)" }}
|
|
||||||
>
|
|
||||||
<div class="flex gap-2">
|
|
||||||
<span class="bg-gray-600 py-1 px-2 text-xs rounded-xl text-white">
|
|
||||||
{log.date.getHours().toString().padStart(2, "0")}:{log.date
|
|
||||||
.getMinutes().toString().padStart(2, "0")}:{log.date.getSeconds()
|
|
||||||
.toString().padStart(2, "0")} {formatDate(log.date)}
|
|
||||||
</span>
|
|
||||||
<span class="bg-gray-600 py-1 px-2 text-xs rounded-xl text-white">
|
|
||||||
{log.scope}
|
|
||||||
</span>
|
|
||||||
<span class="bg-gray-600 py-1 px-2 text-xs rounded-xl text-white">
|
|
||||||
{log.level}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="text-white"
|
|
||||||
// deno-lint-ignore react-no-danger
|
|
||||||
dangerouslySetInnerHTML={{ __html: log.html ?? "" }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Greet(
|
|
||||||
{ data: { logs }, url }: PageProps<{ logs: Log[] }>,
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<MainLayout url={url}>
|
|
||||||
<h1 class="text-white text-4xl">Logs</h1>
|
|
||||||
|
|
||||||
{logs.map((r) => {
|
|
||||||
return (
|
|
||||||
<LogLine
|
|
||||||
log={r}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</MainLayout>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
import { MainLayout } from "@components/layouts/main.tsx";
|
|
||||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
|
||||||
import { getPerformances, PerformanceRes } from "@lib/performance.ts";
|
|
||||||
import { AccessDeniedError } from "@lib/errors.ts";
|
|
||||||
|
|
||||||
export const handler: Handlers = {
|
|
||||||
async GET(_, ctx) {
|
|
||||||
const performances = await getPerformances();
|
|
||||||
if (!("session" in ctx.state)) {
|
|
||||||
throw new AccessDeniedError();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.render({ performances });
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
function PerformanceLine(
|
|
||||||
{ maximum, data: [amount, min, average, max], url }: {
|
|
||||||
maximum: number;
|
|
||||||
url: string;
|
|
||||||
data: readonly [number, number, number, number];
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
class="mt-10 flex flex-col gap-2 bg-gray-900 px-4 py-2 rounded-2xl"
|
|
||||||
style={{ background: "var(--light)" }}
|
|
||||||
>
|
|
||||||
<div style={{ color: "var(--foreground)" }}>
|
|
||||||
{url}
|
|
||||||
</div>
|
|
||||||
<div class="flex gap-2">
|
|
||||||
<span class="bg-gray-600 p-1 text-xs rounded-xl text-white">
|
|
||||||
{Math.floor(average / 1000)}ms
|
|
||||||
</span>
|
|
||||||
<span class="bg-gray-600 p-1 text-xs rounded-xl text-white">
|
|
||||||
{amount}x
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="" style={{ maxWidth: "75vw" }}>
|
|
||||||
<div
|
|
||||||
class="h-2 bg-red-200 rounded"
|
|
||||||
style={{
|
|
||||||
width: `${Math.floor((max / maximum) * 100)}%`,
|
|
||||||
borderRadius: "1rem 1rem 1rem 0px",
|
|
||||||
minWidth: "5px",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
class="h-2 bg-green-200 rounded"
|
|
||||||
style={{
|
|
||||||
width: `${Math.floor((average / maximum) * 100)}%`,
|
|
||||||
borderStartEndRadius: "0px",
|
|
||||||
borderRadius: "0px 0px 1rem 0px",
|
|
||||||
minWidth: "5px",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
class="h-2 bg-yellow-200 rounded"
|
|
||||||
style={{
|
|
||||||
width: `${Math.floor((min / maximum) * 100)}%`,
|
|
||||||
borderRadius: "0px 0px 1rem 1rem",
|
|
||||||
minWidth: "5px",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Greet(
|
|
||||||
{ data: { performances }, url }: PageProps<{ performances: PerformanceRes }>,
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<MainLayout url={url}>
|
|
||||||
<h1 class="text-white text-4xl ">Performance</h1>
|
|
||||||
|
|
||||||
{performances.res.map((r) => {
|
|
||||||
return (
|
|
||||||
<PerformanceLine
|
|
||||||
maximum={performances.max}
|
|
||||||
url={r.url}
|
|
||||||
data={r.data}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</MainLayout>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { fetchResource } from "@lib/marka/index.ts";
|
import { fetchResource } from "@lib/marka/index.ts";
|
||||||
|
import { define } from "../../../utils.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
async GET(_, ctx) {
|
async GET(ctx) {
|
||||||
const article = await fetchResource(`articles/${ctx.params.name}`);
|
const article = await fetchResource(`articles/${ctx.params.name}`);
|
||||||
return json(article);
|
return json(article);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,21 +1,79 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { Defuddle } from "defuddle/node";
|
|
||||||
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
|
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
|
||||||
import { createStreamResponse, isValidUrl } from "@lib/helpers.ts";
|
import { createStreamResponse, isValidUrl } from "@lib/helpers.ts";
|
||||||
import * as openai from "@lib/openai.ts";
|
import * as openai from "@lib/openai.ts";
|
||||||
|
import * as unsplash from "@lib/unsplash.ts";
|
||||||
import { getYoutubeVideoDetails } from "@lib/youtube.ts";
|
import { getYoutubeVideoDetails } from "@lib/youtube.ts";
|
||||||
import {
|
import {
|
||||||
extractYoutubeId,
|
extractYoutubeId,
|
||||||
|
fileExtension,
|
||||||
|
formatDate,
|
||||||
isYoutubeLink,
|
isYoutubeLink,
|
||||||
|
safeFileName,
|
||||||
toUrlSafeString,
|
toUrlSafeString,
|
||||||
} from "@lib/string.ts";
|
} from "@lib/string.ts";
|
||||||
import { createLogger } from "@lib/log/index.ts";
|
import { createLogger } from "@lib/log/index.ts";
|
||||||
import { createResource } from "@lib/marka/index.ts";
|
import { createResource } from "@lib/marka/index.ts";
|
||||||
import { webScrape } from "@lib/webScraper.ts";
|
import { webScrape } from "@lib/webScraper.ts";
|
||||||
import { ArticleResource } from "@lib/marka/schema.ts";
|
import { ArticleResource } from "@lib/marka/schema.ts";
|
||||||
|
import { define } from "../../../../utils.ts";
|
||||||
|
|
||||||
const log = createLogger("api/article");
|
const log = createLogger("api/article");
|
||||||
|
|
||||||
|
async function getUnsplashCoverImage(
|
||||||
|
content: string,
|
||||||
|
streamResponse: ReturnType<typeof createStreamResponse>,
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
try {
|
||||||
|
streamResponse.info("creating unsplash search term");
|
||||||
|
const searchTerm = await openai.createUnsplashSearchTerm(content);
|
||||||
|
if (!searchTerm) return;
|
||||||
|
streamResponse.info(`searching for ${searchTerm}`);
|
||||||
|
const unsplashUrl = await unsplash.getImageBySearchTerm(searchTerm);
|
||||||
|
return unsplashUrl;
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Failed to get unsplash cover image", e);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ext(str: string) {
|
||||||
|
try {
|
||||||
|
const u = new URL(str);
|
||||||
|
if (u.searchParams.has("fm")) {
|
||||||
|
return u.searchParams.get("fm")!;
|
||||||
|
}
|
||||||
|
return fileExtension(u.pathname);
|
||||||
|
} catch (_e) {
|
||||||
|
return fileExtension(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchAndStoreCover(
|
||||||
|
imageUrl: string | undefined,
|
||||||
|
title: string,
|
||||||
|
streamResponse?: ReturnType<typeof createStreamResponse>,
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
if (!imageUrl) return;
|
||||||
|
const imagePath = `articles/images/${safeFileName(title)}_cover.${
|
||||||
|
ext(imageUrl)
|
||||||
|
}`;
|
||||||
|
try {
|
||||||
|
streamResponse?.info("downloading image");
|
||||||
|
const res = await fetch(imageUrl);
|
||||||
|
streamResponse?.info("saving image");
|
||||||
|
if (!res.ok) {
|
||||||
|
console.log(`Failed to download remote image: ${imageUrl}`, res.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const buffer = await res.arrayBuffer();
|
||||||
|
await createResource(imagePath, buffer);
|
||||||
|
return `resources/${imagePath}`;
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`Failed to save image: ${imageUrl}`, err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function processCreateArticle(
|
async function processCreateArticle(
|
||||||
{ fetchUrl, streamResponse }: {
|
{ fetchUrl, streamResponse }: {
|
||||||
fetchUrl: string;
|
fetchUrl: string;
|
||||||
@@ -24,39 +82,53 @@ async function processCreateArticle(
|
|||||||
) {
|
) {
|
||||||
log.info("create article from url", { url: fetchUrl });
|
log.info("create article from url", { url: fetchUrl });
|
||||||
|
|
||||||
streamResponse.enqueue("downloading article");
|
streamResponse.info("downloading article");
|
||||||
|
|
||||||
const doc = await webScrape(fetchUrl, streamResponse);
|
const scrapeResult = await webScrape(fetchUrl, streamResponse);
|
||||||
|
|
||||||
const result = await Defuddle(doc, fetchUrl, {
|
log.debug("downloaded and parse parsed", scrapeResult);
|
||||||
markdown: true,
|
|
||||||
|
streamResponse.info("parsed article, creating tags with openai");
|
||||||
|
|
||||||
|
const aiMeta = await openai.extractArticleMetadata(scrapeResult.markdown);
|
||||||
|
|
||||||
|
streamResponse.info("postprocessing article");
|
||||||
|
|
||||||
|
const title = scrapeResult?.title || aiMeta?.headline || "";
|
||||||
|
|
||||||
|
let coverImagePath: string | undefined = undefined;
|
||||||
|
if (scrapeResult?.image?.length) {
|
||||||
|
log.debug("using local image for cover image", {
|
||||||
|
image: scrapeResult.image,
|
||||||
});
|
});
|
||||||
|
coverImagePath = await fetchAndStoreCover(
|
||||||
|
scrapeResult.image,
|
||||||
|
title,
|
||||||
|
streamResponse,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const urlPath = await getUnsplashCoverImage(
|
||||||
|
scrapeResult.markdown,
|
||||||
|
streamResponse,
|
||||||
|
);
|
||||||
|
coverImagePath = await fetchAndStoreCover(urlPath, title, streamResponse);
|
||||||
|
log.debug("using unsplash for cover image", { image: coverImagePath });
|
||||||
|
}
|
||||||
|
|
||||||
log.debug("downloaded and parse parsed", {
|
const url = toUrlSafeString(title);
|
||||||
url: fetchUrl,
|
|
||||||
content: result.content,
|
|
||||||
});
|
|
||||||
|
|
||||||
streamResponse.enqueue("parsed article, creating tags with openai");
|
|
||||||
|
|
||||||
const aiMeta = await openai.extractArticleMetadata(result.content);
|
|
||||||
|
|
||||||
streamResponse.enqueue("postprocessing article");
|
|
||||||
|
|
||||||
const title = result?.title || aiMeta?.headline || "";
|
|
||||||
const id = toUrlSafeString(title);
|
|
||||||
|
|
||||||
const newArticle: ArticleResource["content"] = {
|
const newArticle: ArticleResource["content"] = {
|
||||||
_type: "Article",
|
_type: "Article",
|
||||||
headline: title,
|
headline: title,
|
||||||
articleBody: result.content,
|
articleBody: scrapeResult.markdown,
|
||||||
url: fetchUrl,
|
url: fetchUrl,
|
||||||
datePublished: result?.published || aiMeta?.datePublished ||
|
datePublished: formatDate(
|
||||||
new Date().toISOString(),
|
scrapeResult?.published || aiMeta?.datePublished || undefined,
|
||||||
image: result?.image,
|
),
|
||||||
|
image: coverImagePath,
|
||||||
author: {
|
author: {
|
||||||
_type: "Person",
|
_type: "Person",
|
||||||
name: (result.schemaOrgData?.author?.name || aiMeta?.author || "")
|
name: (scrapeResult.schemaOrgData?.author?.name || aiMeta?.author || "")
|
||||||
.replace(
|
.replace(
|
||||||
"@",
|
"@",
|
||||||
"twitter:",
|
"twitter:",
|
||||||
@@ -64,11 +136,16 @@ async function processCreateArticle(
|
|||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
streamResponse.enqueue("writing to disk");
|
streamResponse.info("writing to disk");
|
||||||
|
|
||||||
await createResource(`articles/${id}.md`, newArticle);
|
log.debug("writing to disk", {
|
||||||
|
...newArticle,
|
||||||
|
articleBody: newArticle.articleBody?.slice(0, 200),
|
||||||
|
});
|
||||||
|
|
||||||
streamResponse.enqueue("id: " + id);
|
await createResource(`articles/${url}.md`, newArticle);
|
||||||
|
|
||||||
|
streamResponse.send({ type: "finished", url });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processCreateYoutubeVideo(
|
async function processCreateYoutubeVideo(
|
||||||
@@ -81,40 +158,53 @@ async function processCreateYoutubeVideo(
|
|||||||
url: fetchUrl,
|
url: fetchUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
streamResponse.enqueue("getting video infos from youtube api");
|
streamResponse.info("getting video infos from youtube api");
|
||||||
|
|
||||||
const youtubeId = extractYoutubeId(fetchUrl);
|
const youtubeId = extractYoutubeId(fetchUrl);
|
||||||
|
|
||||||
const video = await getYoutubeVideoDetails(youtubeId);
|
const video = await getYoutubeVideoDetails(youtubeId);
|
||||||
|
|
||||||
streamResponse.enqueue("shortening title with openai");
|
streamResponse.info("shortening title with openai");
|
||||||
const newId = await openai.shortenTitle(video.snippet.title);
|
const videoTitle = await openai.shortenTitle(video.snippet.title) ||
|
||||||
|
video.snippet.title;
|
||||||
|
|
||||||
const id = newId || youtubeId;
|
const thumbnail = video?.snippet?.thumbnails?.maxres;
|
||||||
|
const coverImagePath = await fetchAndStoreCover(
|
||||||
|
thumbnail.url,
|
||||||
|
videoTitle || video.snippet.title,
|
||||||
|
streamResponse,
|
||||||
|
);
|
||||||
|
|
||||||
const newArticle: ArticleResource["content"] = {
|
const newArticle: ArticleResource["content"] = {
|
||||||
_type: "Article",
|
_type: "Article",
|
||||||
headline: video.snippet.title,
|
headline: video.snippet.title,
|
||||||
articleBody: video.snippet.description,
|
articleBody: video.snippet.description,
|
||||||
|
image: coverImagePath,
|
||||||
url: fetchUrl,
|
url: fetchUrl,
|
||||||
datePublished: new Date(video.snippet.publishedAt).toISOString(),
|
datePublished: formatDate(video.snippet.publishedAt),
|
||||||
author: {
|
author: {
|
||||||
_type: "Person",
|
_type: "Person",
|
||||||
name: video.snippet.channelTitle,
|
name: video.snippet.channelTitle,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
streamResponse.enqueue("creating article");
|
streamResponse.info("creating article");
|
||||||
|
|
||||||
await createResource(`articles/${id}.md`, newArticle);
|
const filename = toUrlSafeString(videoTitle);
|
||||||
|
|
||||||
streamResponse.enqueue("finished");
|
await createResource(
|
||||||
|
`articles/${filename}.md`,
|
||||||
|
newArticle,
|
||||||
|
);
|
||||||
|
|
||||||
streamResponse.enqueue("id: " + id);
|
streamResponse.info("finished");
|
||||||
|
|
||||||
|
streamResponse.send({ type: "finished", url: filename });
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
GET(req, ctx) {
|
GET(ctx) {
|
||||||
|
const req = ctx.req;
|
||||||
const session = ctx.state.session;
|
const session = ctx.state.session;
|
||||||
if (!session) {
|
if (!session) {
|
||||||
throw new AccessDeniedError();
|
throw new AccessDeniedError();
|
||||||
@@ -151,4 +241,4 @@ export const handler: Handlers = {
|
|||||||
|
|
||||||
return streamResponse.response;
|
return streamResponse.response;
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
185
routes/api/articles/enhance/[name].ts
Normal file
185
routes/api/articles/enhance/[name].ts
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
import { fileExtension, formatDate, safeFileName } from "@lib/string.ts";
|
||||||
|
import { createStreamResponse } from "@lib/helpers.ts";
|
||||||
|
import {
|
||||||
|
AccessDeniedError,
|
||||||
|
BadRequestError,
|
||||||
|
NotFoundError,
|
||||||
|
} from "@lib/errors.ts";
|
||||||
|
import { createResource, fetchResource } from "@lib/marka/index.ts";
|
||||||
|
import { ArticleResource } from "@lib/marka/schema.ts";
|
||||||
|
import { webScrape } from "@lib/webScraper.ts";
|
||||||
|
import * as openai from "@lib/openai.ts";
|
||||||
|
import * as unsplash from "@lib/unsplash.ts";
|
||||||
|
import { createLogger } from "@lib/log/index.ts";
|
||||||
|
import { define } from "../../../../utils.ts";
|
||||||
|
|
||||||
|
function ext(str: string) {
|
||||||
|
try {
|
||||||
|
const u = new URL(str);
|
||||||
|
if (u.searchParams.has("fm")) {
|
||||||
|
return u.searchParams.get("fm")!;
|
||||||
|
}
|
||||||
|
return fileExtension(u.pathname);
|
||||||
|
} catch (_e) {
|
||||||
|
return fileExtension(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const log = createLogger("api/article/enhance");
|
||||||
|
|
||||||
|
async function getUnsplashCoverImage(
|
||||||
|
content: string,
|
||||||
|
streamResponse: ReturnType<typeof createStreamResponse>,
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
try {
|
||||||
|
streamResponse.info("creating unsplash search term");
|
||||||
|
const searchTerm = await openai.createUnsplashSearchTerm(content);
|
||||||
|
if (!searchTerm) return;
|
||||||
|
streamResponse.info(`searching for ${searchTerm}`);
|
||||||
|
const unsplashUrl = await unsplash.getImageBySearchTerm(searchTerm);
|
||||||
|
return unsplashUrl;
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Failed to get unsplash cover image", e);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchAndStoreCover(
|
||||||
|
imageUrl: string | undefined,
|
||||||
|
title: string,
|
||||||
|
streamResponse: ReturnType<typeof createStreamResponse>,
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
if (!imageUrl) return;
|
||||||
|
const imagePath = `articles/images/${safeFileName(title)}_cover.${
|
||||||
|
ext(imageUrl)
|
||||||
|
}`;
|
||||||
|
try {
|
||||||
|
streamResponse.info("downloading cover");
|
||||||
|
const res = await fetch(imageUrl);
|
||||||
|
if (!res.ok) {
|
||||||
|
log.error(`Failed to download remote image: ${imageUrl}`, {
|
||||||
|
status: res.status,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const buffer = await res.arrayBuffer();
|
||||||
|
streamResponse.info("saving cover");
|
||||||
|
await createResource(imagePath, buffer);
|
||||||
|
return `resources/${imagePath}`;
|
||||||
|
} catch (err) {
|
||||||
|
log.error(`Failed to save image: ${imageUrl}`, err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function processEnhanceArticle(
|
||||||
|
name: string,
|
||||||
|
streamResponse: ReturnType<typeof createStreamResponse>,
|
||||||
|
) {
|
||||||
|
const article = await fetchResource<ArticleResource>(
|
||||||
|
`articles/${name}`,
|
||||||
|
);
|
||||||
|
if (!article) {
|
||||||
|
throw new NotFoundError();
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchUrl = article.content?.url;
|
||||||
|
if (!fetchUrl) {
|
||||||
|
throw new BadRequestError("Article has no URL to enhance from.");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("enhancing article from url", { url: fetchUrl });
|
||||||
|
streamResponse.info("scraping url");
|
||||||
|
const result = await webScrape(fetchUrl, streamResponse);
|
||||||
|
|
||||||
|
streamResponse.info("parsing content");
|
||||||
|
|
||||||
|
log.debug("downloaded and parsed", result);
|
||||||
|
|
||||||
|
streamResponse.info("extracting metadata with openai");
|
||||||
|
const aiMeta = await openai.extractArticleMetadata(result.markdown);
|
||||||
|
|
||||||
|
const title = result?.title || aiMeta?.headline ||
|
||||||
|
article.content?.headline || "";
|
||||||
|
|
||||||
|
article.content ??= {
|
||||||
|
_type: "Article",
|
||||||
|
headline: title,
|
||||||
|
url: fetchUrl,
|
||||||
|
};
|
||||||
|
|
||||||
|
article.content.articleBody = result.markdown;
|
||||||
|
article.content.datePublished ??= formatDate(
|
||||||
|
result?.published || aiMeta?.datePublished || undefined,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!article.content.author?.name || article.content.author.name === "") {
|
||||||
|
article.content.author = {
|
||||||
|
_type: "Person",
|
||||||
|
name: (result.schemaOrgData?.author?.name || aiMeta?.author || "")
|
||||||
|
.replace(
|
||||||
|
"@",
|
||||||
|
"twitter:",
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!article.content.image) {
|
||||||
|
let coverImagePath: string | undefined = undefined;
|
||||||
|
if (result?.image?.length) {
|
||||||
|
log.debug("using local image for cover image", { image: result.image });
|
||||||
|
coverImagePath = await fetchAndStoreCover(
|
||||||
|
result.image,
|
||||||
|
title,
|
||||||
|
streamResponse,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const urlPath = await getUnsplashCoverImage(
|
||||||
|
result.content,
|
||||||
|
streamResponse,
|
||||||
|
);
|
||||||
|
coverImagePath = await fetchAndStoreCover(urlPath, title, streamResponse);
|
||||||
|
log.debug("using unsplash for cover image", { image: coverImagePath });
|
||||||
|
}
|
||||||
|
if (coverImagePath) {
|
||||||
|
article.content.image = coverImagePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("writing to disk", {
|
||||||
|
name: name,
|
||||||
|
article: {
|
||||||
|
...article,
|
||||||
|
content: {
|
||||||
|
...article.content,
|
||||||
|
articleBody: article.content.articleBody?.slice(0, 200),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
streamResponse.info("writing to disk");
|
||||||
|
await createResource(`articles/${name}`, article.content);
|
||||||
|
streamResponse.send({ type: "finished", url: name.replace(/$\.md/, "") });
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handler = define.handlers({
|
||||||
|
POST: (ctx) => {
|
||||||
|
const session = ctx.state.session;
|
||||||
|
if (!session) {
|
||||||
|
throw new AccessDeniedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
const streamResponse = createStreamResponse();
|
||||||
|
|
||||||
|
processEnhanceArticle(ctx.params.name, streamResponse)
|
||||||
|
.catch((err) => {
|
||||||
|
log.error(err);
|
||||||
|
streamResponse.error(err.message);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
streamResponse.cancel();
|
||||||
|
});
|
||||||
|
|
||||||
|
return streamResponse.response;
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { fetchResource } from "@lib/marka/index.ts";
|
import { fetchResource } from "@lib/marka/index.ts";
|
||||||
|
import { define } from "../../../utils.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
async GET() {
|
async GET() {
|
||||||
const articles = await fetchResource("articles");
|
const articles = await fetchResource("articles");
|
||||||
return json(articles?.content);
|
return json(articles?.content);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { create, getNumericDate } from "@zaubrik/djwt";
|
||||||
import { create, getNumericDate } from "https://deno.land/x/djwt@v2.2/mod.ts";
|
|
||||||
import { oauth2Client } from "@lib/auth.ts";
|
import { oauth2Client } from "@lib/auth.ts";
|
||||||
import { getCookies, setCookie } from "@std/http/cookie";
|
import { getCookies, setCookie } from "@std/http/cookie";
|
||||||
import { codeChallengeMap } from "./login.ts";
|
import { codeChallengeMap } from "./login.ts";
|
||||||
@@ -9,15 +8,16 @@ import { BadRequestError } from "@lib/errors.ts";
|
|||||||
import { db } from "@lib/db/sqlite.ts";
|
import { db } from "@lib/db/sqlite.ts";
|
||||||
import { userTable } from "@lib/db/schema.ts";
|
import { userTable } from "@lib/db/schema.ts";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
import { define } from "../../../utils.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
async GET(request) {
|
async GET(ctx) {
|
||||||
if (!JWT_SECRET) {
|
if (!JWT_SECRET) {
|
||||||
throw new BadRequestError();
|
throw new BadRequestError();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exchange the authorization code for an access token
|
// Exchange the authorization code for an access token
|
||||||
const cookies = getCookies(request.headers);
|
const cookies = getCookies(ctx.req.headers);
|
||||||
|
|
||||||
const stored = codeChallengeMap.get(cookies["code_challenge"]);
|
const stored = codeChallengeMap.get(cookies["code_challenge"]);
|
||||||
if (!stored) {
|
if (!stored) {
|
||||||
@@ -26,7 +26,7 @@ export const handler: Handlers = {
|
|||||||
|
|
||||||
const { codeVerifier, redirect } = stored;
|
const { codeVerifier, redirect } = stored;
|
||||||
|
|
||||||
const tokens = await oauth2Client.code.getToken(request.url, {
|
const tokens = await oauth2Client.code.getToken(ctx.req.url, {
|
||||||
codeVerifier,
|
codeVerifier,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -53,11 +53,23 @@ export const handler: Handlers = {
|
|||||||
user = res[0];
|
user = res[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!JWT_SECRET) {
|
||||||
|
throw new BadRequestError();
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = await crypto.subtle.importKey(
|
||||||
|
"raw",
|
||||||
|
new TextEncoder().encode(JWT_SECRET),
|
||||||
|
{ name: "HMAC", hash: "SHA-512" },
|
||||||
|
false,
|
||||||
|
["sign", "verify"],
|
||||||
|
);
|
||||||
|
|
||||||
const jwt = await create({ alg: "HS512", type: "JWT" }, {
|
const jwt = await create({ alg: "HS512", type: "JWT" }, {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
name: user.name,
|
name: user.name,
|
||||||
exp: getNumericDate(SESSION_DURATION),
|
exp: getNumericDate(SESSION_DURATION),
|
||||||
}, JWT_SECRET);
|
}, key);
|
||||||
|
|
||||||
const headers = new Headers({
|
const headers = new Headers({
|
||||||
location: redirect || "/",
|
location: redirect || "/",
|
||||||
@@ -78,4 +90,4 @@ export const handler: Handlers = {
|
|||||||
status: 302,
|
status: 302,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { oauth2Client } from "@lib/auth.ts";
|
import { oauth2Client } from "@lib/auth.ts";
|
||||||
import { setCookie } from "@std/http/cookie";
|
import { setCookie } from "@std/http/cookie";
|
||||||
|
import { define } from "../../../utils.ts";
|
||||||
|
|
||||||
export const codeChallengeMap = new Map<
|
export const codeChallengeMap = new Map<
|
||||||
string,
|
string,
|
||||||
{ codeVerifier: string; redirect?: string }
|
{ codeVerifier: string; redirect?: string }
|
||||||
>();
|
>();
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
async GET(req) {
|
async GET(ctx) {
|
||||||
|
const req = ctx.req;
|
||||||
const url = new URL(req.url);
|
const url = new URL(req.url);
|
||||||
|
|
||||||
const { codeVerifier, uri } = await oauth2Client.code.getAuthorizationUri();
|
const { codeVerifier, uri } = await oauth2Client.code.getAuthorizationUri();
|
||||||
@@ -33,4 +34,4 @@ export const handler: Handlers = {
|
|||||||
status: 302,
|
status: 302,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { deleteCookie } from "@std/http/cookie";
|
import { deleteCookie } from "@std/http/cookie";
|
||||||
import { Handlers } from "$fresh/server.ts";
|
import { define } from "../../../utils.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
GET(req) {
|
GET(ctx) {
|
||||||
|
const req = ctx.req;
|
||||||
const url = new URL(req.url);
|
const url = new URL(req.url);
|
||||||
|
|
||||||
const redirect = decodeURIComponent(url.searchParams.get("redirect") || "");
|
const redirect = decodeURIComponent(url.searchParams.get("redirect") || "");
|
||||||
@@ -19,4 +20,4 @@ export const handler: Handlers = {
|
|||||||
status: 302,
|
status: 302,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { documentTable } from "@lib/db/schema.ts";
|
import { documentTable } from "@lib/db/schema.ts";
|
||||||
import { db } from "@lib/db/sqlite.ts";
|
import { db } from "@lib/db/sqlite.ts";
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { caches } from "@lib/cache.ts";
|
import { caches } from "@lib/cache.ts";
|
||||||
|
import { define } from "../../utils.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
async DELETE() {
|
async DELETE() {
|
||||||
for (const cache of caches.values()) {
|
for (const cache of caches.values()) {
|
||||||
cache.clear();
|
cache.clear();
|
||||||
@@ -12,4 +12,4 @@ export const handler: Handlers = {
|
|||||||
await db.delete(documentTable).run();
|
await db.delete(documentTable).run();
|
||||||
return json({ status: "ok" });
|
return json({ status: "ok" });
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
|
||||||
import { getImageContent } from "@lib/image.ts";
|
import { getImageContent } from "@lib/image.ts";
|
||||||
import { createLogger } from "@lib/log/index.ts";
|
import { createLogger } from "@lib/log/index.ts";
|
||||||
|
import { Context } from "fresh";
|
||||||
|
|
||||||
const log = createLogger("api/image");
|
const log = createLogger("api/image");
|
||||||
|
|
||||||
@@ -69,9 +69,9 @@ async function generateETag(content: Uint8Array<ArrayBuffer>): Promise<string> {
|
|||||||
}"`;
|
}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
|
async function GET(ctx: Context<unknown>): Promise<Response> {
|
||||||
try {
|
try {
|
||||||
const url = new URL(req.url);
|
const url = new URL(ctx.req.url);
|
||||||
const params = parseParams(url);
|
const params = parseParams(url);
|
||||||
|
|
||||||
if (typeof params === "string") {
|
if (typeof params === "string") {
|
||||||
@@ -106,6 +106,6 @@ async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = {
|
||||||
GET,
|
GET,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
|
import { define } from "../../utils.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
async GET() {
|
GET() {
|
||||||
return json([]);
|
return json([]);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { createStreamResponse } from "@lib/helpers.ts";
|
import { createStreamResponse } from "@lib/helpers.ts";
|
||||||
|
import { define } from "../../utils.ts";
|
||||||
|
|
||||||
const activeResponses: ReturnType<typeof createStreamResponse>[] = [];
|
const activeResponses: ReturnType<typeof createStreamResponse>[] = [];
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
GET() {
|
GET() {
|
||||||
const r = createStreamResponse();
|
const r = createStreamResponse();
|
||||||
|
|
||||||
@@ -11,4 +11,4 @@ export const handler: Handlers = {
|
|||||||
|
|
||||||
return r.response;
|
return r.response;
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,39 +1,40 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import * as tmdb from "@lib/tmdb.ts";
|
import * as tmdb from "@lib/tmdb.ts";
|
||||||
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
|
import {
|
||||||
import { isString, safeFileName } from "@lib/string.ts";
|
fileExtension,
|
||||||
import { AccessDeniedError } from "@lib/errors.ts";
|
formatDate,
|
||||||
|
isString,
|
||||||
|
safeFileName,
|
||||||
|
toUrlSafeString,
|
||||||
|
} from "@lib/string.ts";
|
||||||
|
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
|
||||||
import { createResource, fetchResource } from "@lib/marka/index.ts";
|
import { createResource, fetchResource } from "@lib/marka/index.ts";
|
||||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||||
|
import { define } from "../../../utils.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
async GET(_, ctx) {
|
async GET(ctx) {
|
||||||
const movie = await fetchResource(`movies/${ctx.params.name}`);
|
const movie = await fetchResource(`movies/${ctx.params.name}`);
|
||||||
return json(movie?.content);
|
return json(movie?.content);
|
||||||
},
|
},
|
||||||
async POST(_, ctx) {
|
async POST(ctx) {
|
||||||
const session = ctx.state.session;
|
const session = ctx.state.session;
|
||||||
if (!session) {
|
if (!session) throw new AccessDeniedError();
|
||||||
throw new AccessDeniedError();
|
|
||||||
}
|
|
||||||
|
|
||||||
const tmdbId = parseInt(ctx.params.name);
|
const tmdbId = parseInt(ctx.params.name);
|
||||||
|
if (Number.isNaN(tmdbId)) throw new BadRequestError();
|
||||||
|
|
||||||
const movieDetails = await tmdb.getMovie(tmdbId);
|
const [movieDetails, movieCredits] = await Promise.all([
|
||||||
const movieCredits = await tmdb.getMovieCredits(tmdbId);
|
tmdb.getMovie(tmdbId),
|
||||||
|
tmdb.getMovieCredits(tmdbId),
|
||||||
|
]);
|
||||||
|
|
||||||
const releaseDate = movieDetails.release_date;
|
const name = movieDetails.title ||
|
||||||
const posterPath = movieDetails.poster_path;
|
movieDetails.original_title ||
|
||||||
const director = movieCredits?.crew?.filter?.((person) =>
|
|
||||||
person.job === "Director"
|
|
||||||
)[0];
|
|
||||||
|
|
||||||
movieDetails.overview;
|
|
||||||
|
|
||||||
let finalPath = "";
|
|
||||||
const name = movieDetails.title || movieDetails.original_title ||
|
|
||||||
ctx.params.name;
|
ctx.params.name;
|
||||||
|
|
||||||
|
const posterPath = movieDetails.poster_path;
|
||||||
|
let finalPath = "";
|
||||||
if (posterPath) {
|
if (posterPath) {
|
||||||
const poster = await tmdb.getMoviePoster(posterPath);
|
const poster = await tmdb.getMoviePoster(posterPath);
|
||||||
const extension = fileExtension(posterPath);
|
const extension = fileExtension(posterPath);
|
||||||
@@ -41,33 +42,32 @@ export const handler: Handlers = {
|
|||||||
await createResource(finalPath, poster);
|
await createResource(finalPath, poster);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tags: string[] = [];
|
const keywords = movieDetails.genres
|
||||||
if (movieDetails.genres) {
|
?.map((g) => g.name?.toLowerCase())
|
||||||
tags.push(
|
.filter(isString) || [];
|
||||||
...movieDetails.genres.map((g) => g.name?.toLowerCase()).filter(
|
|
||||||
isString,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const movie: ReviewResource["content"] = {
|
const movie: ReviewResource["content"] = {
|
||||||
_type: "Review",
|
_type: "Review",
|
||||||
image: `resources/${finalPath}`,
|
image: `resources/${finalPath}`,
|
||||||
datePublished: releaseDate,
|
datePublished: formatDate(movieDetails.release_date),
|
||||||
tmdbId,
|
tmdbId,
|
||||||
author: {
|
author: {
|
||||||
_type: "Person",
|
_type: "Person",
|
||||||
name: director?.name,
|
name: movieCredits.crew?.filter?.((person) =>
|
||||||
|
person.job === "Director"
|
||||||
|
)[0]?.name,
|
||||||
},
|
},
|
||||||
itemReviewed: {
|
itemReviewed: {
|
||||||
name: name,
|
name,
|
||||||
},
|
},
|
||||||
reviewBody: "",
|
reviewBody: "",
|
||||||
keywords: tags,
|
keywords,
|
||||||
};
|
};
|
||||||
|
|
||||||
await createResource(`movies/${safeFileName(name)}.md`, movie);
|
const fileName = toUrlSafeString(name);
|
||||||
|
|
||||||
return json(movie);
|
await createResource(`movies/${fileName}.md`, movie);
|
||||||
|
|
||||||
|
return json({ name: fileName });
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
|
||||||
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
|
|
||||||
import * as tmdb from "@lib/tmdb.ts";
|
import * as tmdb from "@lib/tmdb.ts";
|
||||||
import { formatDate, isString, safeFileName } from "@lib/string.ts";
|
import {
|
||||||
|
fileExtension,
|
||||||
|
formatDate,
|
||||||
|
isString,
|
||||||
|
safeFileName,
|
||||||
|
toUrlSafeString,
|
||||||
|
} from "@lib/string.ts";
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import {
|
import {
|
||||||
AccessDeniedError,
|
AccessDeniedError,
|
||||||
@@ -11,11 +15,10 @@ import {
|
|||||||
import { createRecommendationResource } from "@lib/recommendation.ts";
|
import { createRecommendationResource } from "@lib/recommendation.ts";
|
||||||
import { createResource, fetchResource } from "@lib/marka/index.ts";
|
import { createResource, fetchResource } from "@lib/marka/index.ts";
|
||||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||||
|
import { define } from "../../../../utils.ts";
|
||||||
|
|
||||||
const POST = async (
|
export const handler = define.handlers({
|
||||||
req: Request,
|
POST: async function (ctx) {
|
||||||
ctx: FreshContext,
|
|
||||||
): Promise<Response> => {
|
|
||||||
const session = ctx.state.session;
|
const session = ctx.state.session;
|
||||||
if (!session) {
|
if (!session) {
|
||||||
throw new AccessDeniedError();
|
throw new AccessDeniedError();
|
||||||
@@ -28,7 +31,7 @@ const POST = async (
|
|||||||
throw new NotFoundError();
|
throw new NotFoundError();
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = await req.json();
|
const body = await ctx.req.json();
|
||||||
const name = ctx.params.name;
|
const name = ctx.params.name;
|
||||||
const { tmdbId } = body;
|
const { tmdbId } = body;
|
||||||
if (!name || !tmdbId) {
|
if (!name || !tmdbId) {
|
||||||
@@ -39,15 +42,16 @@ const POST = async (
|
|||||||
const movieCredits = !movie.content?.author &&
|
const movieCredits = !movie.content?.author &&
|
||||||
await tmdb.getMovieCredits(tmdbId);
|
await tmdb.getMovieCredits(tmdbId);
|
||||||
|
|
||||||
const releaseDate = movieDetails.release_date;
|
|
||||||
if (releaseDate && !movie.content?.datePublished) {
|
|
||||||
movie.content = movie.content || {};
|
|
||||||
movie.content.datePublished = formatDate(new Date(releaseDate));
|
|
||||||
}
|
|
||||||
const director = movieCredits &&
|
const director = movieCredits &&
|
||||||
movieCredits?.crew?.filter?.((person) => person.job === "Director")[0];
|
movieCredits?.crew?.filter?.((person) => person.job === "Director")[0];
|
||||||
|
|
||||||
|
movie.content ??= {
|
||||||
|
_type: "Review",
|
||||||
|
};
|
||||||
|
|
||||||
|
movie.content.datePublished ??= formatDate(movieDetails.release_date);
|
||||||
|
|
||||||
if (director && !movie.content?.author) {
|
if (director && !movie.content?.author) {
|
||||||
movie.content = movie.content || {};
|
|
||||||
movie.content.author = {
|
movie.content.author = {
|
||||||
_type: "Person",
|
_type: "Person",
|
||||||
name: director.name,
|
name: director.name,
|
||||||
@@ -65,28 +69,22 @@ const POST = async (
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!movie.name) {
|
movie.content.tmdbId ??= tmdbId;
|
||||||
movie.name = tmdbId;
|
|
||||||
}
|
|
||||||
|
|
||||||
let finalPath = "";
|
let finalPath = "";
|
||||||
const posterPath = movieDetails.poster_path;
|
const posterPath = movieDetails.poster_path;
|
||||||
if (posterPath && !movie.content?.image) {
|
if (posterPath && !movie.content.image) {
|
||||||
const poster = await tmdb.getMoviePoster(posterPath);
|
const poster = await tmdb.getMoviePoster(posterPath);
|
||||||
const extension = fileExtension(posterPath);
|
const extension = fileExtension(posterPath);
|
||||||
finalPath = `movies/images/${safeFileName(name)}_cover.${extension}`;
|
finalPath = `movies/images/${safeFileName(name)}_cover.${extension}`;
|
||||||
await createResource(finalPath, poster);
|
await createResource(finalPath, poster);
|
||||||
movie.content = movie.content || {};
|
|
||||||
movie.content.image = finalPath;
|
movie.content.image = finalPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
await createResource(`movies/${safeFileName(movie.name)}.md`, movie);
|
await createResource(`movies/${toUrlSafeString(movie.name)}.md`, movie);
|
||||||
|
|
||||||
createRecommendationResource(movie, movieDetails.overview);
|
createRecommendationResource(movie, movieDetails.overview);
|
||||||
|
|
||||||
return json(movie);
|
return json(movie);
|
||||||
};
|
},
|
||||||
|
});
|
||||||
export const handler: Handlers = {
|
|
||||||
POST,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { fetchResource } from "@lib/marka/index.ts";
|
import { fetchResource } from "@lib/marka/index.ts";
|
||||||
|
import { define } from "../../../utils.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
async GET() {
|
async GET() {
|
||||||
const movies = await fetchResource("movies");
|
const movies = await fetchResource("movies");
|
||||||
return json(movies);
|
return json(movies);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,28 +1,23 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { AccessDeniedError } from "@lib/errors.ts";
|
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
|
||||||
import { searchResource } from "@lib/search.ts";
|
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||||
|
import { define } from "../../../utils.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
async GET(req, ctx) {
|
async GET(ctx) {
|
||||||
|
const req = ctx.req;
|
||||||
const session = ctx.state.session;
|
const session = ctx.state.session;
|
||||||
if (!session) {
|
if (!session) {
|
||||||
throw new AccessDeniedError();
|
throw new AccessDeniedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = new URL(req.url);
|
const s = parseResourceUrl(req.url);
|
||||||
|
if (!s) {
|
||||||
|
throw new BadRequestError();
|
||||||
|
}
|
||||||
|
|
||||||
const types = url.searchParams.get("types")?.split(",");
|
const resources = await searchResource(s);
|
||||||
const tags = url.searchParams?.get("tags")?.split(",");
|
|
||||||
const authors = url.searchParams?.get("authors")?.split(",");
|
|
||||||
|
|
||||||
const resources = await searchResource({
|
|
||||||
q: url.searchParams.get("q") || "",
|
|
||||||
types,
|
|
||||||
tags,
|
|
||||||
authors,
|
|
||||||
});
|
|
||||||
|
|
||||||
return json(resources);
|
return json(resources);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { fetchResource } from "@lib/marka/index.ts";
|
import { fetchResource } from "@lib/marka/index.ts";
|
||||||
|
import { define } from "../../../utils.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler = define.handlers({
|
||||||
async GET(_, ctx) {
|
async GET(ctx) {
|
||||||
const recipe = await fetchResource(`recipes/${ctx.params.name}`);
|
const recipe = await fetchResource(`recipes/${ctx.params.name}`);
|
||||||
return json(recipe);
|
return json(recipe);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user