Merge pull request #1379 from Bilb/fetch-attachments-onion

make attachment download use onion routing
pull/1384/head
Audric Ackermann 5 years ago committed by GitHub
commit a0633a1f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1240,6 +1240,14 @@ class LokiAppDotNetServerAPI {
}); });
return this.uploadAvatar(formData); return this.uploadAvatar(formData);
} }
async downloadAttachment(url) {
const endpoint = new URL(url).pathname;
return this.serverRequest(`loki/v1${endpoint}`, {
method: 'GET',
});
}
} }
// functions to a specific ADN channel on an ADN server // functions to a specific ADN channel on an ADN server

@ -13,4 +13,5 @@ interface DeviceMappingAnnotation {
interface LokiFileServerInstance { interface LokiFileServerInstance {
getUserDeviceMapping(pubKey: string): Promise<DeviceMappingAnnotation | null>; getUserDeviceMapping(pubKey: string): Promise<DeviceMappingAnnotation | null>;
clearOurDeviceMappingAnnotations(): Promise<void>; clearOurDeviceMappingAnnotations(): Promise<void>;
downloadAttachment(url: string): Promise<any>;
} }

@ -198,6 +198,11 @@ class LokiFileServerInstance {
result.slaveMap = newSlavePrimaryMap; result.slaveMap = newSlavePrimaryMap;
return result; return result;
} }
// for files
async downloadAttachment(url) {
return this._server.downloadAttachment(url);
}
} }
// extends LokiFileServerInstance with functions we'd only perform on our own home server // extends LokiFileServerInstance with functions we'd only perform on our own home server

@ -185,8 +185,8 @@ Message.prototype = {
}; };
function MessageSender() { function MessageSender() {
// Currently only used for getProxiedSize() and makeProxiedRequest(), which are only used for fetching previews
this.server = WebAPI.connect(); this.server = WebAPI.connect();
this.pendingMessages = {};
} }
MessageSender.prototype = { MessageSender.prototype = {

@ -47,8 +47,8 @@ window.getCommitHash = () => config.commitHash;
window.getNodeVersion = () => config.node_version; window.getNodeVersion = () => config.node_version;
window.getHostName = () => config.hostname; window.getHostName = () => config.hostname;
window.getServerTrustRoot = () => config.serverTrustRoot; window.getServerTrustRoot = () => config.serverTrustRoot;
window.isBehindProxy = () => Boolean(config.proxyUrl);
window.JobQueue = JobQueue; window.JobQueue = JobQueue;
window.isBehindProxy = () => Boolean(config.proxyUrl);
window.getStoragePubKey = key => window.getStoragePubKey = key =>
window.isDev() ? key.substring(0, key.length - 2) : key; window.isDev() ? key.substring(0, key.length - 2) : key;
window.getDefaultFileServer = () => config.defaultFileServer; window.getDefaultFileServer = () => config.defaultFileServer;

@ -3,16 +3,11 @@ import _ from 'lodash';
import * as Data from '../../js/modules/data'; import * as Data from '../../js/modules/data';
// TODO: Might convert it to a class later
let webAPI: any;
export async function downloadAttachment(attachment: any) { export async function downloadAttachment(attachment: any) {
if (!webAPI) { const res = await window.lokiFileServerAPI.downloadAttachment(attachment.url);
webAPI = window.WebAPI.connect();
}
// The attachment id is actually just the absolute url of the attachment // The attachment id is actually just the absolute url of the attachment
let data = await webAPI.getAttachment(attachment.url); let data = new Uint8Array(res.response.data).buffer;
if (!attachment.isRaw) { if (!attachment.isRaw) {
const { key, digest, size } = attachment; const { key, digest, size } = attachment;

Loading…
Cancel
Save