feat: use logger

This commit is contained in:
2023-08-05 22:16:14 +02:00
parent 46cd823b6c
commit 32a7f89309
15 changed files with 99 additions and 37 deletions

View File

@ -9,10 +9,11 @@ import tds from "https://cdn.skypack.dev/turndown@7.1.1";
import { Article, createArticle } from "@lib/resource/articles.ts";
import { getYoutubeVideoDetails } from "@lib/youtube.ts";
import { extractYoutubeId, isYoutubeLink } from "@lib/string.ts";
import { createLogger } from "@lib/log.ts";
const parser = new DOMParser();
//service.use(gfm);
const log = createLogger("api/article");
async function processCreateArticle(
{ fetchUrl, streamResponse }: {
@ -20,7 +21,7 @@ async function processCreateArticle(
streamResponse: ReturnType<typeof createStreamResponse>;
},
) {
console.log("[api/article] create article from url", { url: fetchUrl });
log.info("create article from url", { url: fetchUrl });
streamResponse.enqueue("downloading article");
@ -48,7 +49,7 @@ async function processCreateArticle(
const result = readable.parse();
console.log("[api/article] parsed ", {
log.debug("parsed", {
url: fetchUrl,
content: result.textContent,
});
@ -173,7 +174,7 @@ async function processCreateYoutubeVideo(
streamResponse: ReturnType<typeof createStreamResponse>;
},
) {
console.log("[api/article] create youtube article from url", {
log.info("create youtube article from url", {
url: fetchUrl,
});
@ -187,6 +188,7 @@ async function processCreateYoutubeVideo(
const newId = await openai.shortenTitle(video.snippet.title);
const newArticle: Article = {
type: "article",
name: video.snippet.title,
id: newId || video.snippet.title,
content: video.snippet.description,
@ -227,18 +229,18 @@ export const handler: Handlers = {
if (isYoutubeLink(fetchUrl)) {
processCreateYoutubeVideo({ fetchUrl, streamResponse }).then(
(article) => {
console.log({ article });
log.debug("created article from youtube", { article });
},
).catch((err) => {
console.log(err);
log.error(err);
}).finally(() => {
streamResponse.cancel();
});
} else {
processCreateArticle({ fetchUrl, streamResponse }).then((article) => {
console.log({ article });
log.debug("created article from link", { article });
}).catch((err) => {
console.log(err);
log.error(err);
}).finally(() => {
streamResponse.cancel();
});