Member/Ecology revamp.
This commit is contained in:
parent
fc7ec52574
commit
59d6e97787
31 changed files with 1763 additions and 1010 deletions
|
|
@ -36,21 +36,22 @@ export async function fetchAllDocuments() {
|
|||
}
|
||||
|
||||
const documents = []
|
||||
let path = '/documents.list'
|
||||
let offset = 0
|
||||
const limit = 25
|
||||
|
||||
while (path) {
|
||||
const response = await fetch(`${OUTLINE_API_BASE}${path}`, {
|
||||
while (true) {
|
||||
const response = await fetch(`${OUTLINE_API_BASE}/documents.list`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`
|
||||
},
|
||||
body: JSON.stringify({ limit: 25 })
|
||||
body: JSON.stringify({ offset, limit })
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
console.error(`[outline] POST ${path} ${response.status} ${errorText}`)
|
||||
console.error(`[outline] POST /documents.list offset=${offset} ${response.status} ${errorText}`)
|
||||
throw createError({
|
||||
statusCode: response.status,
|
||||
statusMessage: 'Outline API error'
|
||||
|
|
@ -58,10 +59,46 @@ export async function fetchAllDocuments() {
|
|||
}
|
||||
|
||||
const data = await response.json()
|
||||
documents.push(...(data.data || []))
|
||||
const page = data.data || []
|
||||
documents.push(...page)
|
||||
|
||||
path = data.pagination?.nextPath || null
|
||||
if (page.length < limit) break
|
||||
offset += limit
|
||||
}
|
||||
|
||||
return documents
|
||||
}
|
||||
|
||||
export async function fetchCollections() {
|
||||
const config = useRuntimeConfig()
|
||||
const apiKey = config.outlineApiKey
|
||||
|
||||
if (!apiKey) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Outline API key not configured'
|
||||
})
|
||||
}
|
||||
|
||||
const response = await fetch(`${OUTLINE_API_BASE}/collections.list`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`
|
||||
},
|
||||
body: JSON.stringify({ limit: 100 })
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
console.error(`[outline] POST /collections.list ${response.status} ${errorText}`)
|
||||
throw createError({
|
||||
statusCode: response.status,
|
||||
statusMessage: 'Outline API error'
|
||||
})
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
const collections = data.data || []
|
||||
return new Map(collections.map(c => [c.id, c.name]))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue