Skip to content

Commit

Permalink
test api client library
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Mar 7, 2024
1 parent fd1cf02 commit a5d74a9
Show file tree
Hide file tree
Showing 4 changed files with 5,007 additions and 4,961 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"typescript": "4.7.4"
},
"dependencies": {
"@omnivore-app/api": "^1.0.0",
"diff-match-patch": "^1.0.5",
"lodash": "^4.17.21",
"luxon": "^3.1.1",
Expand Down
46 changes: 35 additions & 11 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Omnivore, PageType } from '@omnivore/api'
import {
Omnivore,
OmnivoreErrorCode,
PageType,
isOmnivoreError,
} from '@omnivore-app/api'
import { requestUrl } from 'obsidian'

export interface SearchResponse {
Expand Down Expand Up @@ -174,18 +179,37 @@ export const loadArticles = async (

// return [articles, jsonRes.data.search.pageInfo.hasNextPage]

const omnivore = new Omnivore(endpoint, apiKey)

const response = await omnivore.search({
after: `${after}`,
first,
query: `${updatedAt ? 'updated:' + updatedAt : ''} sort:saved-asc ${query}`,
includeContent,
format,
const omnivore = new Omnivore({
authToken: apiKey,
baseUrl: endpoint,
timeoutMs: 10000,
})

const articles = response.edges.map((e) => e.node)
return [articles, response.pageInfo.hasNextPage]
try {
const response = await omnivore.items.search({
after: `${after}`,
first,
query: `${updatedAt ? 'updated:' + updatedAt : ''} sort:saved-asc ${query}`,
includeContent,
format: format as 'html' | 'markdown',
})

const articles = response.edges.map((e) => e.node)
return [articles, response.pageInfo.hasNextPage]
} catch (error: unknown) {
if (isOmnivoreError(error)) {
switch (error.code) {
case OmnivoreErrorCode.GraphQLError:
console.error('GraphQL error:', error)
break
case OmnivoreErrorCode.NetworkError:
console.error('Network error:', error)
break
}
}
}

return [[], false]
}

export const deleteArticleById = async (
Expand Down
2 changes: 1 addition & 1 deletion src/settings/template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageType } from '@omnivore/api'
import { PageType } from '@omnivore-app/api'
import { truncate } from 'lodash'
import Mustache from 'mustache'
import { parseYaml, stringifyYaml } from 'obsidian'
Expand Down
Loading

0 comments on commit a5d74a9

Please sign in to comment.