mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-23 22:23:10 +02:00
fix: upload media on masto api
This commit is contained in:
parent
3e91abe3b3
commit
ead0667320
2 changed files with 10 additions and 4 deletions
|
@ -143,7 +143,7 @@ export class MastodonApiServerService {
|
|||
const data = await client.uploadMedia(multipartData);
|
||||
reply.send(convertAttachment(data.data as Entity.Attachment));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
/* console.error(e); */
|
||||
reply.code(401).send(e.response.data);
|
||||
}
|
||||
});
|
||||
|
@ -161,7 +161,7 @@ export class MastodonApiServerService {
|
|||
const data = await client.uploadMedia(multipartData, _request.body!);
|
||||
reply.send(convertAttachment(data.data as Entity.Attachment));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
/* console.error(e); */
|
||||
reply.code(401).send(e.response.data);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import FormData from 'form-data'
|
||||
|
||||
import fs from 'fs';
|
||||
import MisskeyAPI from './misskey/api_client'
|
||||
import { DEFAULT_UA } from './default'
|
||||
import { ProxyConfig } from './proxy_config'
|
||||
|
@ -1311,7 +1311,13 @@ export default class Misskey implements MegalodonInterface {
|
|||
*/
|
||||
public async uploadMedia(file: any, _options?: { description?: string; focus?: string }): Promise<Response<Entity.Attachment>> {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
formData.append('file', fs.createReadStream(file.path), {
|
||||
contentType: file.mimetype,
|
||||
});
|
||||
|
||||
if (file.originalname != null && file.originalname !== "file") formData.append("name", file.originalname);
|
||||
|
||||
if (_options?.description != null) formData.append("comment", _options.description);
|
||||
let headers: { [key: string]: string } = {}
|
||||
if (typeof formData.getHeaders === 'function') {
|
||||
headers = formData.getHeaders()
|
||||
|
|
Loading…
Reference in a new issue