mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
change item_type to text
This commit is contained in:
parent
7c56973fad
commit
4ff5484d8e
16 changed files with 56 additions and 91 deletions
|
|
@ -26,18 +26,6 @@ export enum LibraryItemState {
|
|||
Archived = 'ARCHIVED',
|
||||
}
|
||||
|
||||
export enum LibraryItemType {
|
||||
Article = 'ARTICLE',
|
||||
Book = 'BOOK',
|
||||
File = 'FILE',
|
||||
Profile = 'PROFILE',
|
||||
Website = 'WEBSITE',
|
||||
Tweet = 'TWEET',
|
||||
Video = 'VIDEO',
|
||||
Image = 'IMAGE',
|
||||
Unknown = 'UNKNOWN',
|
||||
}
|
||||
|
||||
export enum ContentReaderType {
|
||||
WEB = 'WEB',
|
||||
PDF = 'PDF',
|
||||
|
|
@ -134,8 +122,8 @@ export class LibraryItem {
|
|||
@Column('text', { nullable: true })
|
||||
thumbnail?: string | null
|
||||
|
||||
@Column('enum', { enum: LibraryItemType, default: LibraryItemType.Unknown })
|
||||
itemType!: LibraryItemType
|
||||
@Column('text')
|
||||
itemType!: string
|
||||
|
||||
@OneToOne(() => UploadFile, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'upload_file_id' })
|
||||
|
|
|
|||
|
|
@ -6,11 +6,7 @@
|
|||
import { Readability } from '@omnivore/readability'
|
||||
import graphqlFields from 'graphql-fields'
|
||||
import { DeepPartial } from 'typeorm'
|
||||
import {
|
||||
LibraryItem,
|
||||
LibraryItemState,
|
||||
LibraryItemType,
|
||||
} from '../../entity/library_item'
|
||||
import { LibraryItem, LibraryItemState } from '../../entity/library_item'
|
||||
import { env } from '../../env'
|
||||
import {
|
||||
ArticleError,
|
||||
|
|
@ -194,7 +190,7 @@ export const createArticleResolver = authorized<
|
|||
let canonicalUrl
|
||||
let uploadFileHash = null
|
||||
let domContent = null
|
||||
let itemType = LibraryItemType.Unknown
|
||||
let itemType = PageType.Unknown
|
||||
|
||||
const DUMMY_RESPONSE = {
|
||||
user,
|
||||
|
|
@ -207,7 +203,7 @@ export const createArticleResolver = authorized<
|
|||
content: '',
|
||||
description: '',
|
||||
title: '',
|
||||
pageType: itemType as unknown as PageType,
|
||||
pageType: itemType,
|
||||
contentReader: ContentReader.Web,
|
||||
author: '',
|
||||
url,
|
||||
|
|
@ -263,7 +259,7 @@ export const createArticleResolver = authorized<
|
|||
parsedContent = parseResults.parsedContent
|
||||
canonicalUrl = parseResults.canonicalUrl
|
||||
domContent = parseResults.domContent
|
||||
itemType = parseResults.pageType as unknown as LibraryItemType
|
||||
itemType = parseResults.pageType
|
||||
} else if (!preparedDocument?.document) {
|
||||
// We have a URL but no document, so we try to send this to puppeteer
|
||||
// and return a dummy response.
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import normalizeUrl from 'normalize-url'
|
||||
import path from 'path'
|
||||
import { LibraryItemState, LibraryItemType } from '../../entity/library_item'
|
||||
import { LibraryItemState } from '../../entity/library_item'
|
||||
import { UploadFile } from '../../entity/upload_file'
|
||||
import { env } from '../../env'
|
||||
import {
|
||||
MutationUploadFileRequestArgs,
|
||||
PageType,
|
||||
UploadFileRequestError,
|
||||
UploadFileRequestErrorCode,
|
||||
UploadFileRequestSuccess,
|
||||
|
|
@ -31,13 +32,11 @@ const isFileUrl = (url: string): boolean => {
|
|||
return parsedUrl.protocol == 'file:'
|
||||
}
|
||||
|
||||
export const itemTypeForContentType = (
|
||||
contentType: string
|
||||
): LibraryItemType => {
|
||||
export const itemTypeForContentType = (contentType: string) => {
|
||||
if (contentType == 'application/epub+zip') {
|
||||
return LibraryItemType.Book
|
||||
return PageType.Book
|
||||
}
|
||||
return LibraryItemType.File
|
||||
return PageType.File
|
||||
}
|
||||
|
||||
export const uploadFileRequestResolver = authorized<
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
import cors from 'cors'
|
||||
import express from 'express'
|
||||
import * as jwt from 'jsonwebtoken'
|
||||
import { LibraryItemState, LibraryItemType } from '../entity/library_item'
|
||||
import { LibraryItemState } from '../entity/library_item'
|
||||
import { Recommendation } from '../entity/recommendation'
|
||||
import { UploadFile } from '../entity/upload_file'
|
||||
import { env } from '../env'
|
||||
import { UploadFileStatus } from '../generated/graphql'
|
||||
import { PageType, UploadFileStatus } from '../generated/graphql'
|
||||
import { authTrx } from '../repository'
|
||||
import { Claims } from '../resolvers/types'
|
||||
import {
|
||||
|
|
@ -124,7 +124,7 @@ export function pageRouter() {
|
|||
user: { id: claims.uid },
|
||||
title,
|
||||
originalContent: '',
|
||||
itemType: LibraryItemType.File,
|
||||
itemType: PageType.File,
|
||||
uploadFile: { id: uploadFileData.id },
|
||||
slug: generateSlug(uploadFilePathName),
|
||||
state: LibraryItemState.Processing,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
import express from 'express'
|
||||
import { DeepPartial } from 'typeorm'
|
||||
import {
|
||||
LibraryItem,
|
||||
LibraryItemState,
|
||||
LibraryItemType,
|
||||
} from '../../entity/library_item'
|
||||
import { LibraryItem, LibraryItemState } from '../../entity/library_item'
|
||||
import { UploadFile } from '../../entity/upload_file'
|
||||
import { env } from '../../env'
|
||||
import { UploadFileStatus } from '../../generated/graphql'
|
||||
import { PageType, UploadFileStatus } from '../../generated/graphql'
|
||||
import { authTrx } from '../../repository'
|
||||
import { createLibraryItem } from '../../services/library_item'
|
||||
import { findNewsletterEmailByAddress } from '../../services/newsletters'
|
||||
|
|
@ -151,8 +147,8 @@ export function emailAttachmentRouter() {
|
|||
const uploadFileHash = uploadFileDetails.md5Hash
|
||||
const itemType =
|
||||
uploadFile.contentType === 'application/pdf'
|
||||
? LibraryItemType.File
|
||||
: LibraryItemType.Book
|
||||
? PageType.File
|
||||
: PageType.Book
|
||||
const title = subject || uploadFileData.fileName
|
||||
const articleToSave: DeepPartial<LibraryItem> = {
|
||||
originalUrl: uploadFileUrlOverride,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import * as privateIpLib from 'private-ip'
|
||||
import { LibraryItemState, LibraryItemType } from '../entity/library_item'
|
||||
import { LibraryItemState } from '../entity/library_item'
|
||||
import {
|
||||
ArticleSavingRequest,
|
||||
ArticleSavingRequestStatus,
|
||||
CreateArticleSavingRequestErrorCode,
|
||||
CreateLabelInput,
|
||||
PageType,
|
||||
} from '../generated/graphql'
|
||||
import { createPubSubClient, PubsubClient } from '../pubsub'
|
||||
import { userRepository } from '../repository/user'
|
||||
|
|
@ -118,7 +119,7 @@ export const createPageSaveRequest = async ({
|
|||
id: articleSavingRequestId,
|
||||
user: { id: userId },
|
||||
readableContent: SAVING_CONTENT,
|
||||
itemType: LibraryItemType.Unknown,
|
||||
itemType: PageType.Unknown,
|
||||
slug: generateSlug(url),
|
||||
title: url,
|
||||
originalUrl: url,
|
||||
|
|
|
|||
|
|
@ -3,11 +3,7 @@ import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity
|
|||
import { EntityLabel } from '../entity/entity_label'
|
||||
import { Highlight } from '../entity/highlight'
|
||||
import { Label } from '../entity/label'
|
||||
import {
|
||||
LibraryItem,
|
||||
LibraryItemState,
|
||||
LibraryItemType,
|
||||
} from '../entity/library_item'
|
||||
import { LibraryItem, LibraryItemState } from '../entity/library_item'
|
||||
import { BulkActionType } from '../generated/graphql'
|
||||
import { createPubSubClient, EntityType } from '../pubsub'
|
||||
import { authTrx } from '../repository'
|
||||
|
|
@ -34,7 +30,7 @@ export interface SearchArgs {
|
|||
query?: string
|
||||
inFilter?: InFilter
|
||||
readFilter?: ReadFilter
|
||||
typeFilter?: LibraryItemType
|
||||
typeFilter?: string
|
||||
labelFilters?: LabelFilter[]
|
||||
hasFilters?: HasFilter[]
|
||||
dateFilters?: DateFilter[]
|
||||
|
|
@ -58,7 +54,7 @@ export interface SearchResultItem {
|
|||
id: string
|
||||
image?: string | null
|
||||
pageId?: string
|
||||
pageType: LibraryItemType
|
||||
pageType: string
|
||||
publishedAt?: Date
|
||||
quote?: string | null
|
||||
shortId?: string | null
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import * as httpContext from 'express-http-context2'
|
|||
import { readFileSync } from 'fs'
|
||||
import path from 'path'
|
||||
import { DeepPartial, EntityManager } from 'typeorm'
|
||||
import { LibraryItem, LibraryItemType } from '../entity/library_item'
|
||||
import { LibraryItem } from '../entity/library_item'
|
||||
import { PageType } from '../generated/graphql'
|
||||
import { authTrx, entityManager } from '../repository'
|
||||
import { libraryItemRepository } from '../repository/library_item'
|
||||
import { generateSlug, stringToHash, wordsCount } from '../utils/helpers'
|
||||
|
|
@ -69,7 +70,7 @@ const popularReadToLibraryItem = (
|
|||
title: pr.title,
|
||||
author: pr.author,
|
||||
originalUrl: pr.url,
|
||||
itemType: LibraryItemType.Article,
|
||||
itemType: PageType.Article,
|
||||
textContentHash: stringToHash(pr.content),
|
||||
thumbnail: pr.previewImage,
|
||||
publishedAt: pr.publishedAt,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
import {
|
||||
LibraryItem,
|
||||
LibraryItemState,
|
||||
LibraryItemType,
|
||||
} from '../entity/library_item'
|
||||
import { LibraryItem, LibraryItemState } from '../entity/library_item'
|
||||
import { getInternalLabelWithColor } from '../repository/label'
|
||||
import { enqueueThumbnailTask } from '../utils/createTask'
|
||||
import {
|
||||
|
|
@ -102,7 +98,7 @@ export const saveEmail = async (
|
|||
title: input.title,
|
||||
author: input.author,
|
||||
originalUrl: cleanedUrl,
|
||||
itemType: parseResult.pageType as unknown as LibraryItemType,
|
||||
itemType: parseResult.pageType,
|
||||
textContentHash: stringToHash(content),
|
||||
thumbnail:
|
||||
metadata?.previewImage ||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
import { Readability } from '@omnivore/readability'
|
||||
import { DeepPartial } from 'typeorm'
|
||||
import {
|
||||
LibraryItem,
|
||||
LibraryItemState,
|
||||
LibraryItemType,
|
||||
} from '../entity/library_item'
|
||||
import { LibraryItem, LibraryItemState } from '../entity/library_item'
|
||||
import { User } from '../entity/user'
|
||||
import { homePageURL } from '../env'
|
||||
import {
|
||||
|
|
@ -86,7 +82,7 @@ export const savePage = async (
|
|||
slug,
|
||||
croppedPathname,
|
||||
parsedContent: parseResult.parsedContent,
|
||||
itemType: parseResult.pageType as unknown as LibraryItemType,
|
||||
itemType: parseResult.pageType,
|
||||
originalHtml: parseResult.domContent,
|
||||
canonicalUrl: parseResult.canonicalUrl,
|
||||
saveTime: input.savedAt ? new Date(input.savedAt) : undefined,
|
||||
|
|
@ -210,7 +206,7 @@ export const parsedContentToLibraryItem = ({
|
|||
userId: string
|
||||
slug: string
|
||||
croppedPathname: string
|
||||
itemType: LibraryItemType
|
||||
itemType: string
|
||||
parsedContent: Readability.ParseResult | null
|
||||
originalHtml?: string | null
|
||||
itemId?: string | null
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ import {
|
|||
SearchParserKeyWordOffset,
|
||||
SearchParserTextOffset,
|
||||
} from 'search-query-parser'
|
||||
import { LibraryItemType } from '../entity/library_item'
|
||||
import { InputMaybe, SortParams } from '../generated/graphql'
|
||||
import { InputMaybe, PageType, SortParams } from '../generated/graphql'
|
||||
|
||||
export enum ReadFilter {
|
||||
ALL,
|
||||
|
|
@ -31,7 +30,7 @@ export interface SearchFilter {
|
|||
query: string | undefined
|
||||
inFilter: InFilter
|
||||
readFilter: ReadFilter
|
||||
typeFilter?: LibraryItemType
|
||||
typeFilter?: string
|
||||
labelFilters: LabelFilter[]
|
||||
sort?: Sort
|
||||
hasFilters: HasFilter[]
|
||||
|
|
@ -134,27 +133,25 @@ const parseInFilter = (
|
|||
return query ? InFilter.ALL : InFilter.INBOX
|
||||
}
|
||||
|
||||
const parseTypeFilter = (
|
||||
str: string | undefined
|
||||
): LibraryItemType | undefined => {
|
||||
const parseTypeFilter = (str: string | undefined): string | undefined => {
|
||||
if (str === undefined) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
switch (str.toLowerCase()) {
|
||||
case 'article':
|
||||
return LibraryItemType.Article
|
||||
return PageType.Article
|
||||
case 'book':
|
||||
return LibraryItemType.Book
|
||||
return PageType.Book
|
||||
case 'pdf':
|
||||
case 'file':
|
||||
return LibraryItemType.File
|
||||
return PageType.File
|
||||
case 'profile':
|
||||
return LibraryItemType.Profile
|
||||
return PageType.Profile
|
||||
case 'website':
|
||||
return LibraryItemType.Website
|
||||
return PageType.Website
|
||||
case 'unknown':
|
||||
return LibraryItemType.Unknown
|
||||
return PageType.Unknown
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,22 @@
|
|||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
import { File, GetSignedUrlConfig, Storage } from '@google-cloud/storage'
|
||||
import { ContentReaderType, LibraryItemType } from '../entity/library_item'
|
||||
import { ContentReaderType } from '../entity/library_item'
|
||||
import { env } from '../env'
|
||||
import { PageType } from '../generated/graphql'
|
||||
import { logger } from './logger'
|
||||
|
||||
export const contentReaderForLibraryItem = (
|
||||
itemType: LibraryItemType,
|
||||
itemType: string,
|
||||
uploadFileId: string | null | undefined
|
||||
) => {
|
||||
if (!uploadFileId) {
|
||||
return ContentReaderType.WEB
|
||||
}
|
||||
switch (itemType) {
|
||||
case LibraryItemType.Book:
|
||||
case PageType.Book:
|
||||
return ContentReaderType.EPUB
|
||||
case LibraryItemType.File:
|
||||
case PageType.File:
|
||||
return ContentReaderType.PDF
|
||||
default:
|
||||
return ContentReaderType.WEB
|
||||
|
|
|
|||
|
|
@ -5,15 +5,16 @@ import 'mocha'
|
|||
import sinon from 'sinon'
|
||||
import { DeepPartial } from 'typeorm'
|
||||
import { Highlight } from '../../src/entity/highlight'
|
||||
import { LibraryItem, LibraryItemState, LibraryItemType } from '../../src/entity/library_item'
|
||||
import { LibraryItem, LibraryItemState } from '../../src/entity/library_item'
|
||||
import { UploadFile } from '../../src/entity/upload_file'
|
||||
import { User } from '../../src/entity/user'
|
||||
import {
|
||||
ArticleSavingRequestStatus,
|
||||
BulkActionType,
|
||||
PageType,
|
||||
SyncUpdatedItemEdge,
|
||||
UpdateReason,
|
||||
UploadFileStatus
|
||||
UploadFileStatus,
|
||||
} from '../../src/generated/graphql'
|
||||
import { getRepository } from '../../src/repository'
|
||||
import { createHighlight } from '../../src/services/highlights'
|
||||
|
|
@ -1070,7 +1071,7 @@ describe('Article API', () => {
|
|||
await createLibraryItem(
|
||||
{
|
||||
user,
|
||||
itemType: i == 0 ? LibraryItemType.Article : LibraryItemType.File,
|
||||
itemType: i == 0 ? PageType.Article : PageType.File,
|
||||
title: 'test page',
|
||||
readableContent: '<p>test</p>',
|
||||
slug: '',
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
import { expect } from 'chai'
|
||||
import 'mocha'
|
||||
import { LibraryItemType } from '../../src/entity/library_item'
|
||||
import { ContentReader } from '../../src/generated/graphql'
|
||||
import { ContentReader, PageType } from '../../src/generated/graphql'
|
||||
import { contentReaderForLibraryItem } from '../../src/utils/uploads'
|
||||
|
||||
describe('contentReaderForPage', () => {
|
||||
it('returns web if there is no uploadFileId', () => {
|
||||
const result = contentReaderForLibraryItem(LibraryItemType.Book, undefined)
|
||||
const result = contentReaderForLibraryItem(PageType.Book, undefined)
|
||||
expect(result).to.eq(ContentReader.Web)
|
||||
})
|
||||
it('returns Epub if there is an uploadFileId and type is book', () => {
|
||||
const result = contentReaderForLibraryItem(
|
||||
LibraryItemType.Book,
|
||||
PageType.Book,
|
||||
'fakeUploadFileId'
|
||||
)
|
||||
expect(result).to.eq(ContentReader.Epub)
|
||||
})
|
||||
it('returns PDF if there is an uploadFileId and type is File', () => {
|
||||
const result = contentReaderForLibraryItem(
|
||||
LibraryItemType.File,
|
||||
PageType.File,
|
||||
'fakeUploadFileId'
|
||||
)
|
||||
expect(result).to.eq(ContentReader.Pdf)
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@
|
|||
|
||||
BEGIN;
|
||||
|
||||
CREATE EXTENSION vector;
|
||||
CREATE EXTENSION IF NOT EXISTS vector;
|
||||
|
||||
CREATE TYPE library_item_state AS ENUM ('SUCCEEDED', 'FAILED', 'PROCESSING', 'ARCHIVED', 'DELETED');
|
||||
CREATE TYPE content_reader_type AS ENUM ('WEB', 'PDF', 'EPUB');
|
||||
CREATE TYPE library_item_type AS ENUM ('ARTICLE', 'BOOK', 'FILE', 'PROFILE', 'WEBSITE', 'TWEET', 'VIDEO', 'IMAGE', 'UNKNOWN');
|
||||
CREATE TYPE directionality_type AS ENUM ('LTR', 'RTL');
|
||||
|
||||
CREATE TABLE omnivore.library_item (
|
||||
|
|
@ -38,7 +37,7 @@ CREATE TABLE omnivore.library_item (
|
|||
reading_progress_top_percent real NOT NULL DEFAULT 0,
|
||||
reading_progress_bottom_percent real NOT NULL DEFAULT 0,
|
||||
thumbnail text,
|
||||
item_type library_item_type NOT NULL DEFAULT 'UNKNOWN',
|
||||
item_type text NOT NULL DEFAULT 'UNKNOWN',
|
||||
upload_file_id uuid REFERENCES omnivore.upload_files ON DELETE CASCADE,
|
||||
content_reader content_reader_type NOT NULL DEFAULT 'WEB',
|
||||
original_content text,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ DROP INDEX omnivore.library_item_content_tsv_idx;
|
|||
DROP TRIGGER update_library_item_modtime ON omnivore.library_item;
|
||||
DROP TABLE omnivore.library_item;
|
||||
DROP TYPE directionality_type;
|
||||
DROP TYPE library_item_type;
|
||||
DROP TYPE content_reader_type;
|
||||
DROP TYPE library_item_state;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue