Fix open group file uploads using incorrect server

pull/1384/head
Maxim Shishmarev 5 years ago
parent 22eebcd66d
commit 5ecf43c124

@ -9,6 +9,11 @@ interface UploadResponse {
id?: number;
}
interface DownloadResponse {
statucCode: number;
reponse: any;
}
export interface LokiAppDotNetServerInterface {
findOrCreateChannel(
api: LokiPublicChatFactoryAPI,
@ -19,6 +24,7 @@ export interface LokiAppDotNetServerInterface {
uploadAvatar(data: FormData): Promise<UploadResponse>;
putAttachment(data: ArrayBuffer): Promise<UploadResponse>;
putAvatar(data: ArrayBuffer): Promise<UploadResponse>;
downloadAttachment(url: String): Promise<DownloadResponse>; // todo: add return type
}
export interface LokiPublicChannelAPI {

@ -4,7 +4,31 @@ import _ from 'lodash';
import * as Data from '../../js/modules/data';
export async function downloadAttachment(attachment: any) {
const res = await window.lokiFileServerAPI.downloadAttachment(attachment.url);
const serverUrl = new URL(attachment.url).origin;
// The fileserver adds the `-static` part for some reason
const defaultFileserver = _.includes(
['https://file-static.lokinet.org', 'https://file.getsession.org'],
serverUrl
);
let res: any;
// TODO: we need attachments to remember which API should be used to retrieve them
if (!defaultFileserver) {
const serverAPI = await window.lokiPublicChatAPI.findOrCreateServer(
serverUrl
);
if (serverAPI) {
res = await serverAPI.downloadAttachment(attachment.url);
}
}
// Fallback to using the default fileserver
if (defaultFileserver || !res) {
res = await window.lokiFileServerAPI.downloadAttachment(attachment.url);
}
// The attachment id is actually just the absolute url of the attachment
let data = new Uint8Array(res.response.data).buffer;

Loading…
Cancel
Save