fix(url): handle error on url preview

add new post Rust 疑难杂症
This commit is contained in:
xfy
2024-03-23 12:29:59 +08:00
parent 3e09866515
commit 256212423a
2 changed files with 468 additions and 4 deletions

View File

@ -1,7 +1,6 @@
import { Octokit } from 'octokit';
import { cache } from 'react';
import { GistData, GistsFile, PageKeys, PageSize } from 'types';
import {} from 'octokit/';
const password = process.env.NEXT_PUBLIC_GITHUB_API;
const host = process.env.NEXT_PUBLIC_GISTS_HOST ?? 'https://api.github.com';
@ -149,8 +148,24 @@ export interface Meta {
author: string;
canonical: string;
}
const defaultLinkResult: LinkResult = {
meta: {
description: '',
title: '',
author: '',
canonical: '',
},
links: [],
rel: [],
};
export const urlMeta = cache(async (url: string) => {
return (await (
await fetch(`http://iframely.server.crestify.com/iframely?url=${url}`)
).json()) as LinkResult;
try {
const result: LinkResult = await (
await fetch(`http://iframely.server.crestify.com/iframely?url=${url}`)
).json();
return result;
} catch (err) {
console.error(err);
return defaultLinkResult;
}
});