Compare commits
1 Commits
6027038b24
...
d3404786b2
Author | SHA1 | Date | |
---|---|---|---|
d3404786b2 |
@@ -9,11 +9,6 @@ const nextConfig = {
|
|||||||
destination: '/find',
|
destination: '/find',
|
||||||
permanent: true,
|
permanent: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
source: '/:langcode(\\w{2})/:slug*',
|
|
||||||
destination: '/:slug*',
|
|
||||||
permanent: true,
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
images: {
|
images: {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "libremdb",
|
"name": "libremdb",
|
||||||
"version": "4.2.0",
|
"version": "4.1.0",
|
||||||
"description": "a free & open source IMDb front-end",
|
"description": "a free & open source IMDb front-end",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
16
pnpm-lock.yaml
generated
16
pnpm-lock.yaml
generated
@@ -926,8 +926,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==}
|
resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==}
|
||||||
engines: {node: '>= 4'}
|
engines: {node: '>= 4'}
|
||||||
|
|
||||||
immutable@5.1.3:
|
immutable@5.1.2:
|
||||||
resolution: {integrity: sha512-+chQdDfvscSF1SJqv2gn4SRO2ZyS3xL3r7IW/wWEEzrzLisnOlKiQu5ytC/BVNcS15C39WT2Hg/bjKjDMcu+zg==}
|
resolution: {integrity: sha512-qHKXW1q6liAk1Oys6umoaZbDRqjcjgSrbnrifHsfsttza7zcvRAsL7mMV6xWcyhwQy7Xj5v4hhbr6b+iDYwlmQ==}
|
||||||
|
|
||||||
import-fresh@3.3.0:
|
import-fresh@3.3.0:
|
||||||
resolution: {integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==}
|
resolution: {integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==}
|
||||||
@@ -1434,6 +1434,9 @@ packages:
|
|||||||
tslib@2.5.0:
|
tslib@2.5.0:
|
||||||
resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==}
|
resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==}
|
||||||
|
|
||||||
|
tslib@2.6.2:
|
||||||
|
resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==}
|
||||||
|
|
||||||
tsutils@3.21.0:
|
tsutils@3.21.0:
|
||||||
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
|
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
|
||||||
engines: {node: '>= 6'}
|
engines: {node: '>= 6'}
|
||||||
@@ -1507,7 +1510,7 @@ snapshots:
|
|||||||
|
|
||||||
'@emnapi/runtime@0.44.0':
|
'@emnapi/runtime@0.44.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.5.0
|
tslib: 2.6.2
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@eslint/eslintrc@1.4.1':
|
'@eslint/eslintrc@1.4.1':
|
||||||
@@ -2460,7 +2463,7 @@ snapshots:
|
|||||||
|
|
||||||
ignore@5.2.4: {}
|
ignore@5.2.4: {}
|
||||||
|
|
||||||
immutable@5.1.3: {}
|
immutable@5.1.2: {}
|
||||||
|
|
||||||
import-fresh@3.3.0:
|
import-fresh@3.3.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -2867,7 +2870,7 @@ snapshots:
|
|||||||
sass@1.89.2:
|
sass@1.89.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
chokidar: 4.0.3
|
chokidar: 4.0.3
|
||||||
immutable: 5.1.3
|
immutable: 5.1.2
|
||||||
source-map-js: 1.2.1
|
source-map-js: 1.2.1
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@parcel/watcher': 2.5.1
|
'@parcel/watcher': 2.5.1
|
||||||
@@ -3002,6 +3005,9 @@ snapshots:
|
|||||||
|
|
||||||
tslib@2.5.0: {}
|
tslib@2.5.0: {}
|
||||||
|
|
||||||
|
tslib@2.6.2:
|
||||||
|
optional: true
|
||||||
|
|
||||||
tsutils@3.21.0(typescript@4.7.4):
|
tsutils@3.21.0(typescript@4.7.4):
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 1.14.1
|
tslib: 1.14.1
|
||||||
|
@@ -1,2 +0,0 @@
|
|||||||
onlyBuiltDependencies:
|
|
||||||
- sharp
|
|
@@ -1,7 +0,0 @@
|
|||||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
|
||||||
<ShortName>libremdb</ShortName>
|
|
||||||
<Description>Search libremdb</Description>
|
|
||||||
<InputEncoding>UTF-8</InputEncoding>
|
|
||||||
<Image width="16" height="16" type="image/x-icon">https://libremdb.iket.me/favicon.ico</Image>
|
|
||||||
<Url type="text/html" method="get" template="https://libremdb.iket.me/find?q={searchTerms}"/>
|
|
||||||
</OpenSearchDescription>
|
|
@@ -11,7 +11,6 @@ type Props = {
|
|||||||
message: string;
|
message: string;
|
||||||
statusCode?: number;
|
statusCode?: number;
|
||||||
originalPath?: string;
|
originalPath?: string;
|
||||||
stack?: string;
|
|
||||||
/** props specific to error boundary. */
|
/** props specific to error boundary. */
|
||||||
misc?: {
|
misc?: {
|
||||||
subtext: string;
|
subtext: string;
|
||||||
@@ -20,9 +19,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
const ErrorInfo = ({ message, statusCode, misc, originalPath }: Props) => {
|
||||||
|
|
||||||
const ErrorInfo = ({ message, statusCode, misc, originalPath, stack }: Props) => {
|
|
||||||
const title = statusCode ? `${message} (${statusCode})` : message;
|
const title = statusCode ? `${message} (${statusCode})` : message;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -42,11 +39,6 @@ const ErrorInfo = ({ message, statusCode, misc, originalPath, stack }: Props) =>
|
|||||||
<use href='/svg/sadgnu.svg#sad-gnu'></use>
|
<use href='/svg/sadgnu.svg#sad-gnu'></use>
|
||||||
</svg>
|
</svg>
|
||||||
<h1 className={`heading heading__primary ${styles.heading}`}>{title}</h1>
|
<h1 className={`heading heading__primary ${styles.heading}`}>{title}</h1>
|
||||||
{Boolean(stack && isDev) && (
|
|
||||||
<pre className={styles.stack}>
|
|
||||||
<code>{stack}</code>
|
|
||||||
</pre>
|
|
||||||
)}
|
|
||||||
{misc ? (
|
{misc ? (
|
||||||
<>
|
<>
|
||||||
<p>{misc.subtext}</p>
|
<p>{misc.subtext}</p>
|
||||||
@@ -72,13 +64,6 @@ const ErrorInfo = ({ message, statusCode, misc, originalPath, stack }: Props) =>
|
|||||||
.
|
.
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<p>
|
|
||||||
If you think this shouldn't happen,{' '}
|
|
||||||
<Link href='/contact'>
|
|
||||||
<a className='link'>let it be known</a>
|
|
||||||
</Link>
|
|
||||||
.
|
|
||||||
</p>
|
|
||||||
</Layout>
|
</Layout>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@@ -14,41 +14,32 @@ type Props = {
|
|||||||
const Media = ({ className, media }: Props) => {
|
const Media = ({ className, media }: Props) => {
|
||||||
return (
|
return (
|
||||||
<div className={`${className} ${styles.media}`}>
|
<div className={`${className} ${styles.media}`}>
|
||||||
{(media.trailers?.length || !!media.videos.total) && (
|
{(media.trailer || !!media.videos.total) && (
|
||||||
<section className={styles.videos}>
|
<section className={styles.videos}>
|
||||||
<h2 className='heading heading__secondary'>Videos</h2>
|
<h2 className='heading heading__secondary'>Videos</h2>
|
||||||
|
|
||||||
<div className={styles.videos__container}>
|
<div className={styles.videos__container}>
|
||||||
{media.trailers?.map(trailer => (
|
{media.trailer && (
|
||||||
<div className={styles.trailer} key={trailer.id}>
|
<div className={styles.trailer}>
|
||||||
<video
|
<video
|
||||||
aria-label={trailer.caption ?? 'trailer video'}
|
aria-label='trailer video'
|
||||||
controls
|
controls
|
||||||
playsInline
|
playsInline
|
||||||
poster={getProxiedIMDbImgUrl(modifyIMDbImg(trailer.thumbnail))}
|
poster={getProxiedIMDbImgUrl(modifyIMDbImg(media.trailer.thumbnail))}
|
||||||
className={styles.trailer__video}
|
className={styles.trailer__video}
|
||||||
preload='none'
|
preload='none'
|
||||||
muted
|
|
||||||
>
|
>
|
||||||
{trailer.urls.map(source => (
|
{media.trailer.urls.map(source => (
|
||||||
<source
|
<source
|
||||||
key={source.url}
|
key={source.url}
|
||||||
type='video/mp4'
|
type={source.mimeType ?? undefined}
|
||||||
src={getProxiedIMDbImgUrl(source.url)}
|
src={getProxiedIMDbImgUrl(source.url)}
|
||||||
media={source.resolution !== 'SD' ? '(min-width: 450px)' : undefined}
|
|
||||||
data-res={source.resolution}
|
data-res={source.resolution}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
<p>
|
|
||||||
{trailer.caption}:{' '}
|
|
||||||
<Link href={getProxiedIMDbImgUrl(trailer.urls[0]?.url)}>
|
|
||||||
<a className='link'>link</a>
|
|
||||||
</Link>
|
|
||||||
</p>
|
|
||||||
</video>
|
</video>
|
||||||
</div>
|
</div>
|
||||||
))}
|
)}
|
||||||
|
|
||||||
{!!media.videos.total &&
|
{!!media.videos.total &&
|
||||||
media.videos.videos.map(video => (
|
media.videos.videos.map(video => (
|
||||||
|
@@ -36,13 +36,6 @@ const Meta = ({
|
|||||||
<meta property='og:locale' content='en_US' />
|
<meta property='og:locale' content='en_US' />
|
||||||
<meta property='og:type' content='video.movie' />
|
<meta property='og:type' content='video.movie' />
|
||||||
<meta property='og:image' content={url.toString()} />
|
<meta property='og:image' content={url.toString()} />
|
||||||
|
|
||||||
<link
|
|
||||||
rel='search'
|
|
||||||
type='application/opensearchdescription+xml'
|
|
||||||
href='/opensearch.xml'
|
|
||||||
title='libremdb'
|
|
||||||
></link>
|
|
||||||
</Head>
|
</Head>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -9,54 +9,43 @@ type Props = {
|
|||||||
const DidYouKnow = ({ data }: Props) => (
|
const DidYouKnow = ({ data }: Props) => (
|
||||||
<section className={styles.container}>
|
<section className={styles.container}>
|
||||||
<h2 className='heading heading__secondary'>Did you know</h2>
|
<h2 className='heading heading__secondary'>Did you know</h2>
|
||||||
{isEmpty(data) ? (
|
{!!data.trivia?.total && (
|
||||||
<p>Nothing interesting to show.</p>
|
<section>
|
||||||
) : (
|
<h3 className='heading heading__tertiary'>Trivia</h3>
|
||||||
<>
|
<div dangerouslySetInnerHTML={{ __html: data.trivia.html }}></div>
|
||||||
{!!data.trivia?.total && (
|
</section>
|
||||||
<section>
|
)}
|
||||||
<h3 className='heading heading__tertiary'>Trivia</h3>
|
{!!data.quotes?.total && (
|
||||||
<div dangerouslySetInnerHTML={{ __html: data.trivia.html }}></div>
|
<section>
|
||||||
</section>
|
<h3 className='heading heading__tertiary'>Quotes</h3>
|
||||||
)}
|
<div dangerouslySetInnerHTML={{ __html: data.quotes.html }}></div>
|
||||||
{!!data.quotes?.total && (
|
</section>
|
||||||
<section>
|
)}
|
||||||
<h3 className='heading heading__tertiary'>Quotes</h3>
|
{!!data.trademark?.total && (
|
||||||
<div dangerouslySetInnerHTML={{ __html: data.quotes.html }}></div>
|
<section>
|
||||||
</section>
|
<h3 className='heading heading__tertiary'>Trademark</h3>
|
||||||
)}
|
<div dangerouslySetInnerHTML={{ __html: data.trademark.html }}></div>
|
||||||
{!!data.trademark?.total && (
|
</section>
|
||||||
<section>
|
)}
|
||||||
<h3 className='heading heading__tertiary'>Trademark</h3>
|
{!!data.nicknames.length && (
|
||||||
<div dangerouslySetInnerHTML={{ __html: data.trademark.html }}></div>
|
<section>
|
||||||
</section>
|
<h3 className='heading heading__tertiary'>Nicknames</h3>
|
||||||
)}
|
<p>{data.nicknames.join(', ')}</p>
|
||||||
{!!data.nicknames.length && (
|
</section>
|
||||||
<section>
|
)}
|
||||||
<h3 className='heading heading__tertiary'>Nicknames</h3>
|
{!!data.salary?.total && (
|
||||||
<p>{data.nicknames.join(', ')}</p>
|
<section>
|
||||||
</section>
|
<h3 className='heading heading__tertiary'>Salary</h3>
|
||||||
)}
|
<p>
|
||||||
{!!data.salary?.total && (
|
<span>{data.salary.value} in </span>
|
||||||
<section>
|
<Link href={`/title/${data.salary.title.id}`}>
|
||||||
<h3 className='heading heading__tertiary'>Salary</h3>
|
<a className={'link'}>{data.salary.title.text}</a>
|
||||||
<p>
|
</Link>
|
||||||
<span>{data.salary.value} in </span>
|
<span> ({data.salary.title.year})</span>
|
||||||
<Link href={`/title/${data.salary.title.id}`}>
|
</p>
|
||||||
<a className={'link'}>{data.salary.title.text}</a>
|
</section>
|
||||||
</Link>
|
|
||||||
<span> ({data.salary.title.year})</span>
|
|
||||||
</p>
|
|
||||||
</section>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|
||||||
export default DidYouKnow;
|
export default DidYouKnow;
|
||||||
|
|
||||||
const isEmpty = (data: Props['data']) =>
|
|
||||||
Boolean(
|
|
||||||
!data.nicknames.length && !data.quotes && !data.salary && !data.trademark && !data.trivia
|
|
||||||
);
|
|
@@ -86,21 +86,6 @@ const Basic = ({ data, className }: Props) => {
|
|||||||
))}
|
))}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!!data.interests.length && (
|
|
||||||
<p className={styles.genres}>
|
|
||||||
<span className={styles.genres__heading}>Interests: </span>
|
|
||||||
{data.interests.map((interest, i) => (
|
|
||||||
<Fragment key={interest.id}>
|
|
||||||
{i > 0 && ', '}
|
|
||||||
<Link href={`/interest/${interest.id}`}>
|
|
||||||
<a className={styles.link}>{interest.text}</a>
|
|
||||||
</Link>
|
|
||||||
</Fragment>
|
|
||||||
))}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<p className={styles.overview}>
|
<p className={styles.overview}>
|
||||||
<span className={styles.overview__heading}>Plot: </span>
|
<span className={styles.overview__heading}>Plot: </span>
|
||||||
<span className={styles.overview__text}>{data.plot || '-'}</span>
|
<span className={styles.overview__text}>{data.plot || '-'}</span>
|
||||||
|
@@ -7,13 +7,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const DidYouKnow = ({ data }: Props) => {
|
const DidYouKnow = ({ data }: Props) => {
|
||||||
if (!Object.keys(data).length)
|
if (!Object.keys(data).length) return <></>;
|
||||||
return (
|
|
||||||
<section className={styles.didYouKnow}>
|
|
||||||
<h2 className='heading heading__secondary'>Did you know</h2>
|
|
||||||
<p>Nothing interesting to show.</p>
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<section className={styles.didYouKnow}>
|
<section className={styles.didYouKnow}>
|
||||||
<h2 className='heading heading__secondary'>Did you know</h2>
|
<h2 className='heading heading__secondary'>Did you know</h2>
|
||||||
|
@@ -1,127 +1,82 @@
|
|||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import type { Reviews as TReviews } from 'src/interfaces/shared/title';
|
import { Reviews } from 'src/interfaces/shared/title';
|
||||||
import { formatNumber } from 'src/utils/helpers';
|
import { formatNumber } from 'src/utils/helpers';
|
||||||
import styles from 'src/styles/modules/components/title/reviews.module.scss';
|
import styles from 'src/styles/modules/components/title/reviews.module.scss';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
reviews: TReviews;
|
reviews: Reviews;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Reviews = ({ reviews }: Props) => {
|
const Reviews = ({ reviews }: Props) => {
|
||||||
return (
|
|
||||||
<section className={styles.reviews}>
|
|
||||||
<h2 className='heading heading__secondary'>Reviews</h2>
|
|
||||||
|
|
||||||
<RatingsDistribution ratings={reviews.ratingsDistribution} />
|
|
||||||
|
|
||||||
<section className={styles.userReviews}>
|
|
||||||
<h3 className='heading heading__tertiary'>User Reviews</h3>
|
|
||||||
{reviews.featuredReviews ? (
|
|
||||||
<ul className={styles.userReviews__list} role='list'>
|
|
||||||
{reviews.featuredReviews.map(featuredReview => (
|
|
||||||
<li key={featuredReview.id}>
|
|
||||||
<details className={styles.review}>
|
|
||||||
<summary className={styles.review__summary}>
|
|
||||||
<strong>{featuredReview.review.summary}</strong>
|
|
||||||
</summary>
|
|
||||||
<div
|
|
||||||
className={styles.review__text}
|
|
||||||
dangerouslySetInnerHTML={{
|
|
||||||
__html: featuredReview.review.html,
|
|
||||||
}}
|
|
||||||
></div>
|
|
||||||
<footer className={styles.review__metadata}>
|
|
||||||
<p>
|
|
||||||
{featuredReview.rating && <span>Rated {featuredReview.rating}/10</span>}
|
|
||||||
<span>
|
|
||||||
{' '}
|
|
||||||
by{' '}
|
|
||||||
<Link href={`/user/${featuredReview.reviewer.id}`}>
|
|
||||||
<a className='link'>{featuredReview.reviewer.name}</a>
|
|
||||||
</Link>
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
</footer>
|
|
||||||
</details>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
) : (
|
|
||||||
<p>No reviews yet.</p>
|
|
||||||
)}
|
|
||||||
</section>
|
|
||||||
|
|
||||||
{reviews.ai?.summary && (
|
|
||||||
<details className={styles.reviewAi}>
|
|
||||||
<summary className='heading heading__tertiary'>AI Summary</summary>
|
|
||||||
<p dangerouslySetInnerHTML={{ __html: reviews.ai.summary }} />
|
|
||||||
<ul>
|
|
||||||
{reviews.ai.themes.map(theme => (
|
|
||||||
<li key={theme.id}>{theme.text}</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</details>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<ReviewStats reviews={reviews} />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Reviews;
|
|
||||||
|
|
||||||
const RatingsDistribution = ({ ratings }: { ratings: Props['reviews']['ratingsDistribution'] }) => {
|
|
||||||
const maxRating = Math.max(...ratings.map(r => r.votes));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={styles.ratingsDistribution}>
|
|
||||||
<h3 className='heading heading__tertiary'>Ratings Distribution</h3>
|
|
||||||
{ratings.length ? (
|
|
||||||
<ul>
|
|
||||||
{ratings.map(rating => (
|
|
||||||
<li
|
|
||||||
key={rating.rating}
|
|
||||||
style={
|
|
||||||
{
|
|
||||||
'--bar-height': `${((rating.votes / maxRating) * 100).toFixed(2)}%`,
|
|
||||||
} as React.CSSProperties
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
{rating.rating} <span>({formatNumber(rating.votes)})</span>
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
) : (
|
|
||||||
<p>No ratings yet.</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const ReviewStats = ({ reviews }: { reviews: Props['reviews'] }) => {
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { titleId } = router.query;
|
const { titleId } = router.query;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.reviewStats}>
|
<section className={styles.reviews}>
|
||||||
<p>
|
<h2 className="heading heading__secondary">Reviews</h2>
|
||||||
<Link href={`/title/${titleId}/reviews`}>
|
|
||||||
<a className='link'>{formatNumber(reviews.numUserReviews)} User reviews</a>
|
{reviews.featuredReview && (
|
||||||
</Link>
|
<article className={styles.reviews__reviewContainer}>
|
||||||
</p>
|
<details className={styles.review}>
|
||||||
<p>
|
<summary className={styles.review__summary}>
|
||||||
<Link href={`/title/${titleId}/externalreviews`}>
|
<strong>{reviews.featuredReview.review.summary}</strong>
|
||||||
<a className='link'>{formatNumber(reviews.numCriticReviews)} Critic reviews</a>
|
</summary>
|
||||||
</Link>
|
<div
|
||||||
</p>
|
className={styles.review__text}
|
||||||
<p>
|
dangerouslySetInnerHTML={{
|
||||||
<Link href={`/title/${titleId}/criticreviews`}>
|
__html: reviews.featuredReview.review.html,
|
||||||
<a className='link'> {reviews.metacriticScore} Metascore</a>
|
}}
|
||||||
</Link>
|
></div>
|
||||||
</p>
|
</details>
|
||||||
</div>
|
<footer className={styles.review__metadata}>
|
||||||
|
<p>
|
||||||
|
{reviews.featuredReview.rating && (
|
||||||
|
<span>Rated {reviews.featuredReview.rating}/10</span>
|
||||||
|
)}
|
||||||
|
<span>
|
||||||
|
{' '}
|
||||||
|
by{' '}
|
||||||
|
<Link href={`/user/${reviews.featuredReview.reviewer.id}`}>
|
||||||
|
<a className="link">{reviews.featuredReview.reviewer.name}</a>
|
||||||
|
</Link>
|
||||||
|
</span>
|
||||||
|
<span> on {reviews.featuredReview.date}.</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span>
|
||||||
|
{formatNumber(reviews.featuredReview.votes.up)} upvotes
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
, {formatNumber(reviews.featuredReview.votes.down)} downvotes
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className={styles.reviews__stats}>
|
||||||
|
<p>
|
||||||
|
<Link href={`/title/${titleId}/reviews`}>
|
||||||
|
<a className="link">
|
||||||
|
{formatNumber(reviews.numUserReviews)} User reviews
|
||||||
|
</a>
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<Link href={`/title/${titleId}/externalreviews`}>
|
||||||
|
<a className="link">
|
||||||
|
{formatNumber(reviews.numCriticReviews)} Critic reviews
|
||||||
|
</a>
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<Link href={`/title/${titleId}/criticreviews`}>
|
||||||
|
<a className="link"> {reviews.metacriticScore} Metascore</a>
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
export default Reviews;
|
||||||
|
@@ -143,7 +143,7 @@ export default interface Name {
|
|||||||
value: string;
|
value: string;
|
||||||
language: string;
|
language: string;
|
||||||
};
|
};
|
||||||
videoMimeType?: string;
|
mimeType?: string;
|
||||||
url: string;
|
url: string;
|
||||||
}>;
|
}>;
|
||||||
recommendedTimedTextTrack?: {
|
recommendedTimedTextTrack?: {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,3 @@
|
|||||||
import { AppError as AppErrorClass } from 'src/utils/helpers';
|
import { AppError as AppErrorClass } from 'src/utils/helpers';
|
||||||
|
|
||||||
export type AppError = Pick<InstanceType<typeof AppErrorClass>, 'message' | 'statusCode' | 'stack'>;
|
export type AppError = Omit<InstanceType<typeof AppErrorClass>, 'name'>;
|
||||||
|
@@ -67,13 +67,13 @@ export const getServerSideProps: GetServerSideProps<Data, FindQueryParams> = asy
|
|||||||
props: { data: { title: query, results: res }, error: null, originalPath },
|
props: { data: { title: query, results: res }, error: null, originalPath },
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const err = getErrorProperties(error);
|
const { message, statusCode } = getErrorProperties(error);
|
||||||
ctx.res.statusCode = err.statusCode;
|
ctx.res.statusCode = statusCode;
|
||||||
ctx.res.statusMessage = err.message;
|
ctx.res.statusMessage = message;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
error: { message: err.message, statusCode: err.statusCode, stack: err.format() },
|
error: { message, statusCode },
|
||||||
data: { title: query, results: null },
|
data: { title: query, results: null },
|
||||||
originalPath,
|
originalPath,
|
||||||
},
|
},
|
||||||
|
@@ -55,17 +55,11 @@ export const getServerSideProps: GetServerSideProps<Data, Params> = async ctx =>
|
|||||||
|
|
||||||
return { props: { data, error: null, originalPath } };
|
return { props: { data, error: null, originalPath } };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const err = getErrorProperties(error);
|
const { message, statusCode } = getErrorProperties(error);
|
||||||
ctx.res.statusCode = err.statusCode;
|
ctx.res.statusCode = statusCode;
|
||||||
ctx.res.statusMessage = err.message;
|
ctx.res.statusMessage = message;
|
||||||
|
|
||||||
return {
|
return { props: { error: { message, statusCode }, data: null, originalPath } };
|
||||||
props: {
|
|
||||||
error: { message: err.message, statusCode: err.statusCode, stack: err.format() },
|
|
||||||
data: null,
|
|
||||||
originalPath,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ import ErrorInfo from 'src/components/error/ErrorInfo';
|
|||||||
import Media from 'src/components/media/Media';
|
import Media from 'src/components/media/Media';
|
||||||
import { Basic, Cast, DidYouKnow, Info, MoreLikeThis, Reviews } from 'src/components/title';
|
import { Basic, Cast, DidYouKnow, Info, MoreLikeThis, Reviews } from 'src/components/title';
|
||||||
import Title from 'src/interfaces/shared/title';
|
import Title from 'src/interfaces/shared/title';
|
||||||
import type { AppError } from 'src/interfaces/shared/error';
|
import { AppError } from 'src/interfaces/shared/error';
|
||||||
import getOrSetApiCache from 'src/utils/getOrSetApiCache';
|
import getOrSetApiCache from 'src/utils/getOrSetApiCache';
|
||||||
import title from 'src/utils/fetchers/title';
|
import title from 'src/utils/fetchers/title';
|
||||||
import { getErrorProperties, getProxiedIMDbImgUrl } from 'src/utils/helpers';
|
import { getErrorProperties, getProxiedIMDbImgUrl } from 'src/utils/helpers';
|
||||||
@@ -63,18 +63,12 @@ export const getServerSideProps: GetServerSideProps<Data, Params> = async ctx =>
|
|||||||
const data = await getOrSetApiCache(titleKey(titleId), title, titleId);
|
const data = await getOrSetApiCache(titleKey(titleId), title, titleId);
|
||||||
|
|
||||||
return { props: { data, error: null, originalPath } };
|
return { props: { data, error: null, originalPath } };
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
const err = getErrorProperties(e);
|
const { message, statusCode } = getErrorProperties(error);
|
||||||
ctx.res.statusCode = err.statusCode;
|
ctx.res.statusCode = statusCode;
|
||||||
ctx.res.statusMessage = err.message;
|
ctx.res.statusMessage = message;
|
||||||
|
|
||||||
const error = {
|
return { props: { error: { message, statusCode }, data: null, originalPath } };
|
||||||
message: err.message,
|
|
||||||
statusCode: err.statusCode,
|
|
||||||
stack: err.format(),
|
|
||||||
};
|
|
||||||
console.error(err);
|
|
||||||
return { props: { error, data: null, originalPath } };
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
display: grid;
|
display: grid;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
justify-items: center;
|
justify-items: center;
|
||||||
gap: var(--comp-whitespace);
|
gap: var(--spacer-1);
|
||||||
|
|
||||||
@include helper.bp('bp-700') {
|
@include helper.bp('bp-700') {
|
||||||
--doc-whitespace: var(--spacer-5);
|
--doc-whitespace: var(--spacer-5);
|
||||||
@@ -31,19 +31,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stack {
|
|
||||||
max-width: 90%;
|
|
||||||
max-height: 20rem;
|
|
||||||
padding: var(--spacer-3);
|
|
||||||
white-space: pre-wrap;
|
|
||||||
overflow: scroll;
|
|
||||||
|
|
||||||
user-select: all;
|
|
||||||
|
|
||||||
border-radius: var(--spacer-1);
|
|
||||||
background-color: var(--clr-bg-muted);
|
|
||||||
}
|
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
align-self: end;
|
align-self: end;
|
||||||
|
|
||||||
|
@@ -1,94 +1,26 @@
|
|||||||
.reviews {
|
.reviews {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: var(--comp-whitespace);
|
gap: var(--comp-whitespace);
|
||||||
}
|
|
||||||
|
|
||||||
.ratingsDistribution {
|
&__reviewContainer {
|
||||||
overflow: hidden;
|
// background-color: antiquewhite;
|
||||||
|
}
|
||||||
|
|
||||||
ul {
|
&__stats {
|
||||||
list-style: none;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: var(--spacer-2);
|
|
||||||
overflow-x: auto;
|
|
||||||
padding-block: var(--spacer-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
li {
|
|
||||||
text-align: center;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
height: 5em;
|
|
||||||
align-items: center;
|
|
||||||
flex-shrink: 0;
|
|
||||||
|
|
||||||
&::before {
|
|
||||||
display: block;
|
|
||||||
content: '';
|
|
||||||
|
|
||||||
height: var(--bar-height);
|
|
||||||
margin-top: auto;
|
|
||||||
background-color: var(--clr-fill);
|
|
||||||
width: var(--spacer-6);
|
|
||||||
border-radius: var(--spacer-0);
|
|
||||||
}
|
|
||||||
|
|
||||||
span {
|
|
||||||
font-weight: var(--fw-bold);
|
|
||||||
|
|
||||||
> span {
|
|
||||||
font-weight: initial;
|
|
||||||
font-size: 0.9em;
|
|
||||||
color: var(--clr-text-muted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.reviewAi {
|
|
||||||
summary {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
padding-block: var(--spacer-2);
|
|
||||||
}
|
|
||||||
ul {
|
|
||||||
list-style: none;
|
|
||||||
display: flex;
|
|
||||||
gap: var(--spacer-1);
|
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
gap: var(--spacer-2);
|
||||||
li {
|
|
||||||
padding: var(--spacer-1);
|
|
||||||
background-color: var(--clr-bg-muted);
|
|
||||||
border-radius: var(--spacer-0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.reviewStats {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: var(--spacer-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
.userReviews {
|
|
||||||
|
|
||||||
&__list {
|
|
||||||
padding-block-start: var(--spacer-1);
|
|
||||||
display: grid;
|
|
||||||
gap: var(--spacer-1);
|
|
||||||
list-style: none;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.review {
|
.review {
|
||||||
&__summary {
|
&__summary {
|
||||||
|
font-size: calc(var(--fs-5) * 1.1);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__text,
|
&__text,
|
||||||
&__metadata {
|
&__metadata {
|
||||||
padding-top: var(--spacer-1);
|
padding-top: var(--spacer-2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,18 +42,18 @@ const cleanName = (rawData: RawName) => {
|
|||||||
},
|
},
|
||||||
media: {
|
media: {
|
||||||
...(main.primaryVideos.edges.length && {
|
...(main.primaryVideos.edges.length && {
|
||||||
trailers: main.primaryVideos.edges.map(trailer => ({
|
trailer: {
|
||||||
id: trailer.node.id,
|
id: main.primaryVideos.edges[0].node.id,
|
||||||
isMature: trailer.node.isMature,
|
isMature: main.primaryVideos.edges[0].node.isMature,
|
||||||
thumbnail: trailer.node.thumbnail.url,
|
thumbnail: main.primaryVideos.edges[0].node.thumbnail.url,
|
||||||
runtime: trailer.node.runtime.value,
|
runtime: main.primaryVideos.edges[0].node.runtime.value,
|
||||||
caption: trailer.node.description?.value ?? null,
|
caption: main.primaryVideos.edges[0].node.description?.value ?? null,
|
||||||
urls: trailer.node.playbackURLs.map(url => ({
|
urls: main.primaryVideos.edges[0].node.playbackURLs.map(url => ({
|
||||||
resolution: url.displayName.value as 'SD' | '480p',
|
resolution: url.displayName.value,
|
||||||
mimeType: url.videoMimeType ?? null,
|
mimeType: url.mimeType ?? null,
|
||||||
url: url.url,
|
url: url.url,
|
||||||
})),
|
})),
|
||||||
})),
|
},
|
||||||
}),
|
}),
|
||||||
images: {
|
images: {
|
||||||
total: misc.images.total,
|
total: misc.images.total,
|
||||||
|
@@ -12,7 +12,6 @@ const cleanTitle = (rawData: RawTitle) => {
|
|||||||
titleId: main.id,
|
titleId: main.id,
|
||||||
basic: {
|
basic: {
|
||||||
id: main.id,
|
id: main.id,
|
||||||
isAdult: main.isAdult,
|
|
||||||
title: main.titleText.text,
|
title: main.titleText.text,
|
||||||
// ...(main.originalTitleText.text.toLowerCase() !==
|
// ...(main.originalTitleText.text.toLowerCase() !==
|
||||||
// main.titleText.text.toLowerCase() && {
|
// main.titleText.text.toLowerCase() && {
|
||||||
@@ -51,10 +50,6 @@ const cleanTitle = (rawData: RawTitle) => {
|
|||||||
id: genre.id,
|
id: genre.id,
|
||||||
text: genre.text,
|
text: genre.text,
|
||||||
})),
|
})),
|
||||||
interests: main.interests.edges.map(interest => ({
|
|
||||||
id: interest.node.id,
|
|
||||||
text: interest.node.primaryText.text,
|
|
||||||
})),
|
|
||||||
plot: main.plot?.plotText?.plainText || null,
|
plot: main.plot?.plotText?.plainText || null,
|
||||||
primaryCrew: main.principalCredits.map(type => ({
|
primaryCrew: main.principalCredits.map(type => ({
|
||||||
type: { category: type.category.text, id: type.category.id },
|
type: { category: type.category.text, id: type.category.id },
|
||||||
@@ -81,18 +76,18 @@ const cleanTitle = (rawData: RawTitle) => {
|
|||||||
})),
|
})),
|
||||||
media: {
|
media: {
|
||||||
...(main.primaryVideos.edges.length && {
|
...(main.primaryVideos.edges.length && {
|
||||||
trailers: main.primaryVideos.edges.map(trailer => ({
|
trailer: {
|
||||||
id: trailer.node.id,
|
id: main.primaryVideos.edges[0].node.id,
|
||||||
isMature: trailer.node.isMature,
|
isMature: main.primaryVideos.edges[0].node.isMature,
|
||||||
thumbnail: trailer.node.thumbnail.url,
|
thumbnail: main.primaryVideos.edges[0].node.thumbnail.url,
|
||||||
runtime: trailer.node.runtime.value,
|
runtime: main.primaryVideos.edges[0].node.runtime.value,
|
||||||
caption: trailer.node.description?.value ?? null,
|
caption: main.primaryVideos.edges[0].node.description?.value ?? null,
|
||||||
urls: trailer.node.playbackURLs.map(url => ({
|
urls: main.primaryVideos.edges[0].node.playbackURLs.map(url => ({
|
||||||
resolution: url.displayName.value as 'SD' | '480p',
|
resolution: url.displayName.value,
|
||||||
mimeType: url.videoMimeType ?? null,
|
mimeType: url.mimeType ?? null,
|
||||||
url: url.url,
|
url: url.url,
|
||||||
})),
|
})),
|
||||||
})),
|
},
|
||||||
}),
|
}),
|
||||||
images: {
|
images: {
|
||||||
total: misc.titleMainImages.total,
|
total: misc.titleMainImages.total,
|
||||||
@@ -127,9 +122,6 @@ const cleanTitle = (rawData: RawTitle) => {
|
|||||||
}),
|
}),
|
||||||
topRating: misc.ratingsSummary.topRanking?.rank || null,
|
topRating: misc.ratingsSummary.topRanking?.rank || null,
|
||||||
},
|
},
|
||||||
watchlist: {
|
|
||||||
text: main.engagementStatistics?.watchlistStatistics.displayableCount.text || null,
|
|
||||||
},
|
|
||||||
meta: {
|
meta: {
|
||||||
// for tv episode
|
// for tv episode
|
||||||
...(main.series && {
|
...(main.series && {
|
||||||
@@ -216,34 +208,24 @@ const cleanTitle = (rawData: RawTitle) => {
|
|||||||
metacriticScore: main.metacritic?.metascore.score || null,
|
metacriticScore: main.metacritic?.metascore.score || null,
|
||||||
numCriticReviews: main.criticReviewsTotal.total,
|
numCriticReviews: main.criticReviewsTotal.total,
|
||||||
numUserReviews: misc.reviews.total,
|
numUserReviews: misc.reviews.total,
|
||||||
ratingsDistribution:
|
|
||||||
misc.aggregateRatingsBreakdown.histogram?.histogramValues.map(v => ({
|
|
||||||
rating: v.rating,
|
|
||||||
votes: v.voteCount,
|
|
||||||
})) || [],
|
|
||||||
...(misc.reviewSummary && {
|
|
||||||
ai: {
|
|
||||||
summary: misc.reviewSummary.overall.medium.value.plaidHtml,
|
|
||||||
themes: misc.reviewSummary.themes.map(t => ({
|
|
||||||
text: t.label.value,
|
|
||||||
id: t.themeId,
|
|
||||||
sentiment: t.sentiment as 'POSITIVE' | 'NEGATIVE',
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
...(misc.featuredReviews.edges.length && {
|
...(misc.featuredReviews.edges.length && {
|
||||||
featuredReviews: misc.featuredReviews.edges.map(featuredReview => ({
|
featuredReview: {
|
||||||
id: featuredReview.node.id,
|
id: misc.featuredReviews.edges[0].node.id,
|
||||||
reviewer: {
|
reviewer: {
|
||||||
id: featuredReview.node.author.userId,
|
id: misc.featuredReviews.edges[0].node.author.userId,
|
||||||
name: featuredReview.node.author.username.text,
|
name: misc.featuredReviews.edges[0].node.author.nickName,
|
||||||
|
},
|
||||||
|
rating: misc.featuredReviews.edges[0].node.authorRating,
|
||||||
|
date: formatDate(misc.featuredReviews.edges[0].node.submissionDate),
|
||||||
|
votes: {
|
||||||
|
up: misc.featuredReviews.edges[0].node.helpfulness.upVotes,
|
||||||
|
down: misc.featuredReviews.edges[0].node.helpfulness.downVotes,
|
||||||
},
|
},
|
||||||
rating: featuredReview.node.authorRating,
|
|
||||||
review: {
|
review: {
|
||||||
summary: featuredReview.node.summary.originalText,
|
summary: misc.featuredReviews.edges[0].node.summary.originalText,
|
||||||
html: featuredReview.node.text.originalText.plaidHtml,
|
html: misc.featuredReviews.edges[0].node.text.originalText.plaidHtml,
|
||||||
},
|
},
|
||||||
})),
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
details: {
|
details: {
|
||||||
@@ -260,8 +242,8 @@ const cleanTitle = (rawData: RawTitle) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
...(misc.countriesDetails && {
|
...(misc.countriesOfOrigin && {
|
||||||
countriesOfOrigin: misc.countriesDetails.countries.map(country => ({
|
countriesOfOrigin: misc.countriesOfOrigin.countries.map(country => ({
|
||||||
id: country.id,
|
id: country.id,
|
||||||
text: country.text,
|
text: country.text,
|
||||||
})),
|
})),
|
||||||
@@ -371,10 +353,6 @@ const cleanTitle = (rawData: RawTitle) => {
|
|||||||
},
|
},
|
||||||
genres: title.node.titleGenres?.genres.map(genre => genre.genre.text) ?? null,
|
genres: title.node.titleGenres?.genres.map(genre => genre.genre.text) ?? null,
|
||||||
})),
|
})),
|
||||||
faqs: {
|
|
||||||
questions: misc.faqs.edges.map(q => ({ question: q.node.question, id: q.node.id })),
|
|
||||||
total: misc.faqs.total,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return cleanData;
|
return cleanData;
|
||||||
|
@@ -74,33 +74,12 @@ export const getProxiedIMDbImgUrl = (url: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const AppError = class extends Error {
|
export const AppError = class extends Error {
|
||||||
constructor(message: string, public statusCode: number, cause?: unknown) {
|
constructor(message: string, public statusCode: number, errorOptions?: unknown) {
|
||||||
const _cause = cause ? AppError.toError(cause) : undefined;
|
const saneErrorOptions = getErrorOptions(errorOptions);
|
||||||
super(message, { cause: _cause });
|
super(message, saneErrorOptions);
|
||||||
|
|
||||||
Error.captureStackTrace(this, AppError);
|
Error.captureStackTrace(this, AppError);
|
||||||
}
|
if (process.env.NODE_ENV === 'development') console.error(this);
|
||||||
|
|
||||||
static toError(err: unknown) {
|
|
||||||
if (err instanceof Error) return err;
|
|
||||||
return new Error(`Unexpected: ${JSON.stringify(err)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
format() {
|
|
||||||
let str = '';
|
|
||||||
let cur: Error | null = this;
|
|
||||||
let depth = 0;
|
|
||||||
|
|
||||||
while (cur && depth <= 4) {
|
|
||||||
if (cur.stack) str += `${cur.stack}\n`;
|
|
||||||
else str += `${cur.name}: ${cur.message}\n`;
|
|
||||||
|
|
||||||
cur = cur.cause instanceof Error ? cur.cause : null;
|
|
||||||
if (cur) str += 'Caused by:\n';
|
|
||||||
depth++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.trimEnd();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -131,6 +110,19 @@ export const isLocalStorageAvailable = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getErrorOptions = (error: unknown): ErrorOptions | undefined => {
|
||||||
|
if (!error || typeof error !== 'object') return undefined;
|
||||||
|
|
||||||
|
let cause: unknown;
|
||||||
|
// @ts-expect-error it's not an error! just that project's ts version is old, which can't be upgraded
|
||||||
|
if ('cause' in error) cause = error.cause;
|
||||||
|
// @ts-expect-error it's not an error! just that project's ts version is old, which can't be upgraded
|
||||||
|
else if ('stack' in error) cause = error.stack;
|
||||||
|
|
||||||
|
// @ts-expect-error it's not an error! just that project's ts version is old, which can't be upgraded
|
||||||
|
return { cause };
|
||||||
|
};
|
||||||
|
|
||||||
export const getErrorProperties = (
|
export const getErrorProperties = (
|
||||||
error: unknown,
|
error: unknown,
|
||||||
message = 'Something went very wrong',
|
message = 'Something went very wrong',
|
||||||
@@ -138,4 +130,4 @@ export const getErrorProperties = (
|
|||||||
) => {
|
) => {
|
||||||
if (error instanceof AppError) return error;
|
if (error instanceof AppError) return error;
|
||||||
return new AppError(message, statusCode, error);
|
return new AppError(message, statusCode, error);
|
||||||
};
|
};
|
Reference in New Issue
Block a user