refs #1467 Use /api/v2/media for upload in Pleroma
This commit is contained in:
parent
42a792fa93
commit
2653357bd5
|
@ -1281,7 +1281,10 @@ export default class Pleroma implements MegalodonInterface {
|
|||
// ======================================
|
||||
// statuses/media
|
||||
// ======================================
|
||||
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 | Entity.AsyncAttachment>> {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
if (options) {
|
||||
|
@ -1296,9 +1299,9 @@ export default class Pleroma implements MegalodonInterface {
|
|||
if (typeof formData.getHeaders === 'function') {
|
||||
headers = formData.getHeaders()
|
||||
}
|
||||
return this.client.post<PleromaAPI.Entity.Attachment>('/api/v1/media', formData, headers).then(res => {
|
||||
return this.client.post<PleromaAPI.Entity.AsyncAttachment>('/api/v2/media', formData, headers).then(res => {
|
||||
return Object.assign(res, {
|
||||
data: PleromaAPI.Converter.attachment(res.data)
|
||||
data: PleromaAPI.Converter.async_attachment(res.data)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace PleromaAPI {
|
|||
export type Account = PleromaEntity.Account
|
||||
export type Activity = PleromaEntity.Activity
|
||||
export type Application = PleromaEntity.Application
|
||||
export type AsyncAttachment = PleromaEntity.AsyncAttachment
|
||||
export type Attachment = PleromaEntity.Attachment
|
||||
export type Card = PleromaEntity.Card
|
||||
export type Context = PleromaEntity.Context
|
||||
|
@ -95,6 +96,23 @@ namespace PleromaAPI {
|
|||
export const activity = (a: Entity.Activity): MegalodonEntity.Activity => a
|
||||
export const application = (a: Entity.Application): MegalodonEntity.Application => a
|
||||
export const attachment = (a: Entity.Attachment): MegalodonEntity.Attachment => a
|
||||
export const async_attachment = (a: Entity.AsyncAttachment) => {
|
||||
if (a.url) {
|
||||
return {
|
||||
id: a.id,
|
||||
type: a.type,
|
||||
url: a.url!,
|
||||
remote_url: a.remote_url,
|
||||
preview_url: a.preview_url,
|
||||
text_url: a.text_url,
|
||||
meta: a.meta,
|
||||
description: a.description,
|
||||
blurhash: a.blurhash
|
||||
} as MegalodonEntity.Attachment
|
||||
} else {
|
||||
return a as MegalodonEntity.AsyncAttachment
|
||||
}
|
||||
}
|
||||
export const card = (c: Entity.Card): MegalodonEntity.Card => c
|
||||
export const context = (c: Entity.Context): MegalodonEntity.Context => ({
|
||||
ancestors: c.ancestors.map(a => status(a)),
|
||||
|
|
13
megalodon/src/pleroma/entities/async_attachment.ts
Normal file
13
megalodon/src/pleroma/entities/async_attachment.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace PleromaEntity {
|
||||
export type AsyncAttachment = {
|
||||
id: string
|
||||
type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio'
|
||||
url: string | null
|
||||
remote_url: string | null
|
||||
preview_url: string
|
||||
text_url: string | null
|
||||
meta: object | null
|
||||
description: string | null
|
||||
blurhash: string | null
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
/// <reference path="./entities/account.ts" />
|
||||
/// <reference path="./entities/activity.ts" />
|
||||
/// <reference path="./entities/application.ts" />
|
||||
/// <reference path="./entities/async_attachment.ts" />
|
||||
/// <reference path="./entities/attachment.ts" />
|
||||
/// <reference path="./entities/card.ts" />
|
||||
/// <reference path="./entities/context.ts" />
|
||||
|
|
Loading…
Reference in a new issue