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);
|
const data = await client.uploadMedia(multipartData);
|
||||||
reply.send(convertAttachment(data.data as Entity.Attachment));
|
reply.send(convertAttachment(data.data as Entity.Attachment));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
/* console.error(e); */
|
||||||
reply.code(401).send(e.response.data);
|
reply.code(401).send(e.response.data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -161,7 +161,7 @@ export class MastodonApiServerService {
|
||||||
const data = await client.uploadMedia(multipartData, _request.body!);
|
const data = await client.uploadMedia(multipartData, _request.body!);
|
||||||
reply.send(convertAttachment(data.data as Entity.Attachment));
|
reply.send(convertAttachment(data.data as Entity.Attachment));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
/* console.error(e); */
|
||||||
reply.code(401).send(e.response.data);
|
reply.code(401).send(e.response.data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import FormData from 'form-data'
|
import FormData from 'form-data'
|
||||||
|
import fs from 'fs';
|
||||||
import MisskeyAPI from './misskey/api_client'
|
import MisskeyAPI from './misskey/api_client'
|
||||||
import { DEFAULT_UA } from './default'
|
import { DEFAULT_UA } from './default'
|
||||||
import { ProxyConfig } from './proxy_config'
|
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>> {
|
public async uploadMedia(file: any, _options?: { description?: string; focus?: string }): Promise<Response<Entity.Attachment>> {
|
||||||
const formData = new FormData()
|
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 } = {}
|
let headers: { [key: string]: string } = {}
|
||||||
if (typeof formData.getHeaders === 'function') {
|
if (typeof formData.getHeaders === 'function') {
|
||||||
headers = formData.getHeaders()
|
headers = formData.getHeaders()
|
||||||
|
|
Loading…
Reference in a new issue