kopia lustrzana https://github.com/cloudflare/wildebeest
MOW-116: handle status list with invalid max_id
rodzic
f2bddedabc
commit
145c0038e2
|
@ -38,8 +38,8 @@ export function internalServerError(): Response {
|
|||
return generateErrorResponse('Internal Server Error', 500)
|
||||
}
|
||||
|
||||
export function statusNotFound(): Response {
|
||||
return generateErrorResponse('Status not found', 404)
|
||||
export function statusNotFound(id: string): Response {
|
||||
return generateErrorResponse('Resource not found', 404, `Status "${id}" not found`)
|
||||
}
|
||||
|
||||
export function exceededLimit(detail: string): Response {
|
||||
|
|
|
@ -355,8 +355,6 @@ describe('Mastodon APIs', () => {
|
|||
const data = await res.json<Array<any>>()
|
||||
assert.equal(data.length, 2)
|
||||
|
||||
console.log({ data })
|
||||
|
||||
assert(isUUID(data[0].id))
|
||||
assert.equal(data[0].content, 'my second status')
|
||||
assert.equal(data[0].account.acct, 'sven@' + domain)
|
||||
|
@ -472,6 +470,13 @@ describe('Mastodon APIs', () => {
|
|||
}
|
||||
})
|
||||
|
||||
test('get local actor statuses with max_id poiting to unknown id', async () => {
|
||||
const db = await makeDB()
|
||||
const req = new Request('https://' + domain + '?max_id=object1')
|
||||
const res = await accounts_statuses.handleRequest(req, db, 'sven@' + domain)
|
||||
assert.equal(res.status, 404)
|
||||
})
|
||||
|
||||
test('get remote actor statuses', async () => {
|
||||
const db = await makeDB()
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import type { Env } from 'wildebeest/backend/src/types/env'
|
||||
import { PUBLIC_GROUP } from 'wildebeest/backend/src/activitypub/activities'
|
||||
import * as errors from 'wildebeest/backend/src/errors'
|
||||
import { cors } from 'wildebeest/backend/src/utils/cors'
|
||||
import type { Activity } from 'wildebeest/backend/src/activitypub/activities'
|
||||
import type { Note } from 'wildebeest/backend/src/activitypub/objects/note'
|
||||
|
@ -154,9 +155,12 @@ LIMIT ?3
|
|||
// Client asked to retrieve statuses after the max_id
|
||||
// As opposed to Mastodon we don't use incremental ID but UUID, we need
|
||||
// to retrieve the cdate of the max_id row and only show the newer statuses.
|
||||
const maxId = url.searchParams.get('max_id')
|
||||
const maxId = url.searchParams.get('max_id')!
|
||||
|
||||
const row: any = await db.prepare('SELECT cdate FROM outbox_objects WHERE object_id=?').bind(maxId).first()
|
||||
if (!row) {
|
||||
return errors.statusNotFound(maxId)
|
||||
}
|
||||
afterCdate = row.cdate
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,6 @@ export async function handleRequest(
|
|||
if (request.method !== 'POST') {
|
||||
return new Response('', { status: 400 })
|
||||
}
|
||||
const contentType = request.headers.get('content-type')
|
||||
console.log({ contentType })
|
||||
|
||||
const body = await readBody<StatusCreate>(request)
|
||||
console.log(body)
|
||||
|
@ -79,7 +77,7 @@ export async function handleRequest(
|
|||
if (body.in_reply_to_id) {
|
||||
inReplyToObject = await getObjectByMastodonId(db, body.in_reply_to_id)
|
||||
if (inReplyToObject === null) {
|
||||
return errors.statusNotFound()
|
||||
return errors.statusNotFound(body.in_reply_to_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue