Replace picture with image

This commit is contained in:
Hongbo Wu 2023-04-12 12:15:53 +08:00
parent c5eb223c07
commit 4969391d4c
9 changed files with 32 additions and 17 deletions

View file

@ -62,6 +62,9 @@ export enum PageType {
Unknown = 'UNKNOWN',
Website = 'WEBSITE',
Highlights = 'HIGHLIGHTS',
TWEET = 'TWEET',
VIDEO = 'VIDEO',
IMAGE = 'IMAGE',
}
export enum ArticleSavingRequestStatus {

View file

@ -1683,7 +1683,7 @@ export enum PageType {
Book = 'BOOK',
File = 'FILE',
Highlights = 'HIGHLIGHTS',
Picture = 'PICTURE',
Image = 'IMAGE',
Profile = 'PROFILE',
Tweet = 'TWEET',
Unknown = 'UNKNOWN',

View file

@ -1219,7 +1219,7 @@ enum PageType {
BOOK
FILE
HIGHLIGHTS
PICTURE
IMAGE
PROFILE
TWEET
UNKNOWN

View file

@ -311,7 +311,7 @@ const schema = gql`
UNKNOWN
TWEET
VIDEO
PICTURE
IMAGE
}
type Page {

View file

@ -1,29 +1,29 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { preParseContent } from '@omnivore/content-handler'
import { Readability } from '@omnivore/readability'
import createDOMPurify, { SanitizeElementHookEvent } from 'dompurify'
import { PageType, PreparedDocumentInput } from '../generated/graphql'
import { buildLogger, LogRecord } from './logger'
import { createImageProxyUrl } from './imageproxy'
import addressparser from 'addressparser'
import axios from 'axios'
import createDOMPurify, { SanitizeElementHookEvent } from 'dompurify'
import * as hljs from 'highlightjs'
import { decode } from 'html-entities'
import * as jwt from 'jsonwebtoken'
import { parseHTML } from 'linkedom'
import { getRepository } from '../entity/utils'
import { User } from '../entity/user'
import { NodeHtmlMarkdown } from 'node-html-markdown'
import { ILike } from 'typeorm'
import { promisify } from 'util'
import { v4 as uuid } from 'uuid'
import addressparser from 'addressparser'
import { preParseContent } from '@omnivore/content-handler'
import { User } from '../entity/user'
import { getRepository } from '../entity/utils'
import { env } from '../env'
import { PageType, PreparedDocumentInput } from '../generated/graphql'
import {
EmbeddedHighlightData,
findEmbeddedHighlight,
} from './highlightGenerator'
import { NodeHtmlMarkdown } from 'node-html-markdown'
import { promisify } from 'util'
import * as jwt from 'jsonwebtoken'
import { env } from '../env'
import { createImageProxyUrl } from './imageproxy'
import { buildLogger, LogRecord } from './logger'
const logger = buildLogger('utils.parse')
const signToken = promisify(jwt.sign)
@ -118,12 +118,20 @@ const parseOriginalContent = (document: Document): PageType => {
return PageType.Profile
case 'website':
return PageType.Website
case 'tweet':
return PageType.Tweet
case 'image':
return PageType.Image
default:
if (content.toLowerCase().startsWith('video')) {
return PageType.Video
}
return PageType.Unknown
}
} catch (error) {
logger.error('Error extracting og:type from content', error)
return PageType.Unknown
}
return PageType.Unknown
}
const getPurifiedContent = (html: string): Document => {

View file

@ -19,6 +19,7 @@ export class ImageHandler extends ContentHandler {
<title>${title}</title>
<meta property="og:image" content="${url}" />
<meta property="og:title" content="${title}" />
<meta property="og:type" content="image" />
</head>
<body>
<div>

View file

@ -69,6 +69,7 @@ export class PipedVideoHandler extends ContentHandler {
<meta property="og:article:author" content="${authorName}" />
<meta property="og:site_name" content="Piped Video" />
<meta property="article:published_time" content="${metadata.uploadDate}" />
<meta property="og:type" content="video" />
</head>
<body>
<iframe width="${width}" height="${height}" src="${src}" title="${escapedTitle}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

View file

@ -376,6 +376,7 @@ export class TwitterHandler extends ContentHandler {
<meta property="og:description" content="${description}" />
<meta property="article:published_time" content="${tweetData.created_at}" />
<meta property="og:site_name" content="Twitter" />
<meta property="og:type" content="tweet" />
</head>
<body>
<div>

View file

@ -83,6 +83,7 @@ export class YoutubeHandler extends ContentHandler {
<meta property="og:description" content="" />
<meta property="og:article:author" content="${authorName}" />
<meta property="og:site_name" content="YouTube" />
<meta property="og:type" content="video" />
</head>
<body>
<iframe width="${width}" height="${height}" src="${src}" title="${escapedTitle}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>