remove unused code

This commit is contained in:
Hongbo Wu
2023-11-10 23:03:01 +08:00
parent 59bbc5562b
commit 2ade0698c5
5 changed files with 14 additions and 161 deletions

View File

@ -1,55 +1,7 @@
import axios from 'axios'
import { LibraryItemState } from '../../entity/library_item'
import { env } from '../../env'
import { logger } from '../../utils/logger'
import {
IntegrationClient,
RetrievedResult,
RetrieveRequest,
} from './integration'
interface PocketResponse {
status: number // 1 if success
complete: number // 1 if all items have been returned
list: {
[key: string]: PocketItem
}
since: number // unix timestamp in seconds
search_meta: {
search_type: string
}
error: string
}
interface PocketItem {
item_id: string
resolved_id: string
given_url: string
resolved_url: string
given_title: string
resolved_title: string
favorite: string
status: string
excerpt: string
word_count: string
tags?: {
[key: string]: Tag
}
authors?: {
[key: string]: Author
}
}
interface Tag {
item_id: string
tag: string
}
interface Author {
item_id: string
author_id: string
name: string
}
import { IntegrationClient } from './integration'
export class PocketClient implements IntegrationClient {
name = 'POCKET'
@ -83,82 +35,4 @@ export class PocketClient implements IntegrationClient {
return null
}
}
retrievePocketData = async (
accessToken: string,
since: number, // unix timestamp in seconds
count = 100,
offset = 0
): Promise<PocketResponse | null> => {
const url = `${this.apiUrl}/get`
try {
const response = await axios.post<PocketResponse>(
url,
{
consumer_key: env.pocket.consumerKey,
access_token: accessToken,
state: 'all',
detailType: 'complete',
since,
sort: 'oldest',
count,
offset,
},
{
headers: this.headers,
timeout: 10000, // 10 seconds
}
)
return response.data
} catch (error) {
if (axios.isAxiosError(error)) {
logger.error(error.response)
} else {
logger.error(error)
}
return null
}
}
retrieve = async ({
token,
since = 0,
count = 100,
offset = 0,
}: RetrieveRequest): Promise<RetrievedResult> => {
const pocketData = await this.retrievePocketData(
token,
since / 1000,
count,
offset
)
if (!pocketData) {
throw new Error('Error retrieving pocket data')
}
const pocketItems = Object.values(pocketData.list)
const statusToState: Record<string, LibraryItemState> = {
'0': LibraryItemState.Succeeded,
'1': LibraryItemState.Archived,
'2': LibraryItemState.Deleted,
}
const data = pocketItems.map((item) => ({
url: item.given_url,
labels: item.tags
? Object.values(item.tags).map((tag) => tag.tag)
: undefined,
state: statusToState[item.status],
}))
if (pocketData.error) {
throw new Error(`Error retrieving pocket data: ${pocketData.error}`)
}
return {
data,
since: pocketData.since * 1000,
}
}
}

View File

@ -2,33 +2,6 @@ import axios from 'axios'
import { logger } from '../../utils/logger'
import { IntegrationClient } from './integration'
interface ReadwiseHighlight {
// The highlight text, (technically the only field required in a highlight object)
text: string
// The title of the page the highlight is on
title?: string
// The author of the page the highlight is on
author?: string
// The URL of the page image
image_url?: string
// The URL of the page
source_url?: string
// A meaningful unique identifier for your app
source_type?: string
// One of: books, articles, tweets or podcasts
category?: string
// Annotation note attached to the specific highlight
note?: string
// Highlight's location in the source text. Used to order the highlights
location?: number
// One of: page, order or time_offset
location_type?: string
// A datetime representing when the highlight was taken in the ISO 8601 format
highlighted_at?: string
// Unique url of the specific highlight
highlight_url?: string
}
export class ReadwiseClient implements IntegrationClient {
name = 'READWISE'
apiUrl = 'https://readwise.io/api/v2'

View File

@ -223,9 +223,7 @@ const buildWhereClause = (
}
if (!args.includePending) {
queryBuilder.andWhere('library_item.state <> :state', {
state: LibraryItemState.Processing,
})
queryBuilder.andWhere("library_item.state <> 'PROCESSING'")
}
if (!args.includeDeleted && args.inFilter !== InFilter.TRASH) {

View File

@ -1,7 +1,12 @@
import { LibraryItemState } from '../entity/library_item'
import { User } from '../entity/user'
import { homePageURL } from '../env'
import { SaveErrorCode, SaveFileInput, SaveResult } from '../generated/graphql'
import {
ArticleSavingRequestStatus,
SaveErrorCode,
SaveFileInput,
SaveResult,
} from '../generated/graphql'
import { getStorageFileDetails } from '../utils/uploads'
import { findOrCreateLabels, saveLabelsInLibraryItem } from './labels'
import { updateLibraryItem } from './library_item'
@ -32,9 +37,11 @@ export const saveFile = async (
await updateLibraryItem(
input.clientRequestId,
{
state: input.state
? (input.state as unknown as LibraryItemState)
: LibraryItemState.Succeeded,
state: LibraryItemState.Succeeded,
folder:
input.state === ArticleSavingRequestStatus.Archived
? 'archive'
: 'inbox',
},
user.id
)

View File

@ -270,5 +270,6 @@ export const parsedContentToLibraryItem = ({
contentReader: contentReaderForLibraryItem(itemType, uploadFileId),
subscription: rssFeedUrl,
folder: state === ArticleSavingRequestStatus.Archived ? 'archive' : 'inbox',
state: LibraryItemState.Succeeded,
}
}