Fix #606 Stop using v1 media endpoint
This commit is contained in:
parent
14287b476c
commit
9a0f56c36e
|
@ -376,16 +376,40 @@ export class MastodonService {
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadMediaAttachment(account: AccountInfo, file: File, description: string): Promise<Attachment> {
|
uploadMediaAttachment(account: AccountInfo, file: File, description: string): Promise<Attachment> {
|
||||||
let input = new FormData();
|
return new Promise((resolve, reject) => {
|
||||||
input.append('file', file);
|
let input = new FormData();
|
||||||
if (description !== null && description !== undefined) {
|
input.append('file', file);
|
||||||
input.append('description', description);
|
if (description !== null && description !== undefined) {
|
||||||
} else {
|
input.append('description', description);
|
||||||
input.append('description', '');
|
} else {
|
||||||
}
|
input.append('description', '');
|
||||||
const route = `https://${account.instance}${this.apiRoutes.uploadMediaAttachment}`;
|
}
|
||||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
const route = `https://${account.instance}${this.apiRoutes.uploadMediaAttachment}`;
|
||||||
return this.httpClient.post<Attachment>(route, input, { headers: headers }).toPromise();
|
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||||
|
|
||||||
|
this.httpClient.post<Attachment>(route, input, { headers: headers, observe: 'response' })
|
||||||
|
.subscribe(response => {
|
||||||
|
if (response.status === 202) {
|
||||||
|
const checkMediaStatus = () => {
|
||||||
|
this.httpClient.get<Attachment>(`https://${account.instance}${this.apiRoutes.updateMediaAttachment.replace('{0}', response.body.id)}`, { headers: headers })
|
||||||
|
.subscribe(mediaStatus => {
|
||||||
|
if (mediaStatus.url) {
|
||||||
|
resolve(mediaStatus);
|
||||||
|
} else {
|
||||||
|
setTimeout(checkMediaStatus, 1000);
|
||||||
|
}
|
||||||
|
}, error => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
checkMediaStatus();
|
||||||
|
} else {
|
||||||
|
resolve(response.body);
|
||||||
|
}
|
||||||
|
}, error => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: add focus support
|
//TODO: add focus support
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class ApiRoutes {
|
||||||
followRemote = '/api/v1/follows';
|
followRemote = '/api/v1/follows';
|
||||||
getInstance = '/api/v1/instance';
|
getInstance = '/api/v1/instance';
|
||||||
getInstancev2 = '/api/v2/instance';
|
getInstancev2 = '/api/v2/instance';
|
||||||
uploadMediaAttachment = '/api/v1/media';
|
uploadMediaAttachment = '/api/v2/media';
|
||||||
updateMediaAttachment = '/api/v1/media/{0}';
|
updateMediaAttachment = '/api/v1/media/{0}';
|
||||||
getMutes = '/api/v1/mutes';
|
getMutes = '/api/v1/mutes';
|
||||||
getNotifications = '/api/v1/notifications';
|
getNotifications = '/api/v1/notifications';
|
||||||
|
|
Loading…
Reference in New Issue