|
|
|
@ -2,10 +2,11 @@ const WebSocket = require('websocket').w3cwebsocket;
|
|
|
|
|
const fetch = require('node-fetch');
|
|
|
|
|
const ProxyAgent = require('proxy-agent');
|
|
|
|
|
const { Agent } = require('https');
|
|
|
|
|
const FormData = require('form-data');
|
|
|
|
|
|
|
|
|
|
const is = require('@sindresorhus/is');
|
|
|
|
|
|
|
|
|
|
/* global Buffer, setTimeout, log, _ */
|
|
|
|
|
/* global Buffer, setTimeout, log, _, lokiFileServerAPI */
|
|
|
|
|
|
|
|
|
|
/* eslint-disable more/no-then, no-bitwise, no-nested-ternary */
|
|
|
|
|
|
|
|
|
@ -843,41 +844,27 @@ function initialize({
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getAttachment(id) {
|
|
|
|
|
return _ajax({
|
|
|
|
|
call: 'attachment',
|
|
|
|
|
httpType: 'GET',
|
|
|
|
|
urlParameters: `/${id}`,
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
validateResponse: { location: 'string' },
|
|
|
|
|
}).then(response =>
|
|
|
|
|
// Using _outerAJAX, since it's not hardcoded to the Signal Server
|
|
|
|
|
_outerAjax(response.location, {
|
|
|
|
|
contentType: 'application/octet-stream',
|
|
|
|
|
proxyUrl,
|
|
|
|
|
responseType: 'arraybuffer',
|
|
|
|
|
timeout: 0,
|
|
|
|
|
type: 'GET',
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
function getAttachment(fileUrl) {
|
|
|
|
|
return _outerAjax(fileUrl, {
|
|
|
|
|
contentType: 'application/octet-stream',
|
|
|
|
|
proxyUrl,
|
|
|
|
|
responseType: 'arraybuffer',
|
|
|
|
|
timeout: 0,
|
|
|
|
|
type: 'GET',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function putAttachment(encryptedBin) {
|
|
|
|
|
return _ajax({
|
|
|
|
|
call: 'attachment',
|
|
|
|
|
httpType: 'GET',
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
}).then(response =>
|
|
|
|
|
// Using _outerAJAX, since it's not hardcoded to the Signal Server
|
|
|
|
|
_outerAjax(response.location, {
|
|
|
|
|
contentType: 'application/octet-stream',
|
|
|
|
|
data: encryptedBin,
|
|
|
|
|
processData: false,
|
|
|
|
|
proxyUrl,
|
|
|
|
|
timeout: 0,
|
|
|
|
|
type: 'PUT',
|
|
|
|
|
}).then(() => response.idString)
|
|
|
|
|
);
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
const buffer = Buffer.from(encryptedBin);
|
|
|
|
|
formData.append('type', 'network.loki');
|
|
|
|
|
formData.append('content', buffer, {
|
|
|
|
|
contentType: 'application/octet-stream',
|
|
|
|
|
name: 'content',
|
|
|
|
|
filename: 'attachment',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return lokiFileServerAPI.uploadData(formData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-shadow
|
|
|
|
|