mirror of
https://github.com/nolanlawson/pinafore
synced 2024-12-11 17:59:20 +01:00
0515133ece
* fix(a11y): fix NVDA crash on long aria-label fixes #694 * use the word truncated instead of ellipsis * fix test * really fix tests
30 lines
728 B
JavaScript
30 lines
728 B
JavaScript
import FormData from 'form-data'
|
|
import fs from 'fs'
|
|
import path from 'path'
|
|
import { auth } from '../routes/_api/utils'
|
|
|
|
export async function submitMedia (accessToken, filename, alt) {
|
|
let form = new FormData()
|
|
form.append('file', fs.createReadStream(path.join(__dirname, 'images', filename)))
|
|
form.append('description', alt)
|
|
return new Promise((resolve, reject) => {
|
|
form.submit({
|
|
host: 'localhost',
|
|
port: 3000,
|
|
path: '/api/v1/media',
|
|
headers: auth(accessToken)
|
|
}, (err, res) => {
|
|
if (err) {
|
|
return reject(err)
|
|
}
|
|
let data = ''
|
|
|
|
res.on('data', chunk => {
|
|
data += chunk
|
|
})
|
|
|
|
res.on('end', () => resolve(JSON.parse(data)))
|
|
})
|
|
})
|
|
}
|