Merge pull request #138 from cloudflare/sven/fix-status

Fix post status formdata
pull/139/head
Sven Sauleau 2023-01-18 15:43:51 +01:00 zatwierdzone przez GitHub
commit 346b0a19dc
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 42 dodań i 1 usunięć

Wyświetl plik

@ -43,6 +43,10 @@ export async function deliverFollowers(
queue: Queue<DeliverMessageBody>
) {
const followers = await getFollowers(db, from)
if (followers.length === 0) {
// No one is following the user so no updates to send. Sad.
return
}
const messages: Array<MessageSendRequest<DeliverMessageBody>> = await Promise.all(
followers.map(async (id) => {

Wyświetl plik

@ -22,7 +22,17 @@ export async function readBody<T>(request: Request): Promise<T> {
const out: any = {}
for (const [key, value] of form) {
out[key] = value
if (key.endsWith('[]')) {
// The `key[]` notiation is used when sending an array of values.
const key2 = key.replace('[]', '')
if (out[key2] === undefined) {
out[key2] = []
}
out[key2].push(value)
} else {
out[key] = value
}
}
return out as T
}

Wyświetl plik

@ -627,6 +627,33 @@ describe('Mastodon APIs', () => {
const res = await statuses.handleRequest(req, db, actor, userKEK, queue, kv_cache)
assert.equal(res.status, 400)
const data = await res.json<any>()
assert(data.error.includes('Limit exceeded'))
})
test('create new status sending multipart and too many image', async () => {
const db = await makeDB()
const queue = makeQueue()
const actor = await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
const body = new FormData()
body.append('status', 'my status')
body.append('visibility', 'public')
body.append('media_ids[]', 'id')
body.append('media_ids[]', 'id')
body.append('media_ids[]', 'id')
body.append('media_ids[]', 'id')
body.append('media_ids[]', 'id')
const req = new Request('https://example.com', {
method: 'POST',
body,
})
const res = await statuses.handleRequest(req, db, actor, userKEK, queue, kv_cache)
assert.equal(res.status, 400)
const data = await res.json<any>()
assert(data.error.includes('Limit exceeded'))
})
})
})