Split uploadData to public and private

pull/566/head
Beaudan Brown 6 years ago
parent c9b11814a6
commit f0c198c7b7

@ -138,7 +138,7 @@
</div>
<div class='choose-file'>
<button class='paperclip thumbnail' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></button>
<input type='file' class='file-input' multiple='multiple'>
<input type='file' class='file-input' multiple='multiple' accept='video/* image/*'>
</div>
</div>
</form>

@ -1,8 +1,9 @@
/* global log, textsecure, libloki, Signal, Whisper, Headers, ConversationController,
clearTimeout, MessageController, libsignal, StringView, window, _, dcodeIO */
clearTimeout, MessageController, libsignal, StringView, window, _, dcodeIO, Buffer */
const EventEmitter = require('events');
const nodeFetch = require('node-fetch');
const { URL, URLSearchParams } = require('url');
const FormData = require('form-data');
// Can't be less than 1200 if we have unauth'd requests
const PUBLICCHAT_MSG_POLL_EVERY = 1.5 * 1000; // 1.5s
@ -344,6 +345,43 @@ class LokiAppDotNetServerAPI {
return false;
}
async uploadData(data) {
const endpoint = 'files';
const options = {
method: 'POST',
rawBody: data,
};
const { statusCode, response } = await this.serverRequest(
endpoint,
options
);
if (statusCode !== 200) {
log.warn('Failed to upload data to fileserver');
return null;
}
const url = response.data && response.data.url;
const id = response.data && response.data.id;
return {
url,
id,
};
}
putAttachment(attachmentBin) {
const formData = new FormData();
const buffer = Buffer.from(attachmentBin);
formData.append('type', 'network.loki');
formData.append('content', buffer, {
contentType: 'application/octet-stream',
name: 'content',
filename: 'attachment',
});
return this.uploadData(formData);
}
}
class LokiPublicChannelAPI {

@ -38,28 +38,8 @@ class LokiFileServerAPI {
);
}
async uploadData(data) {
const endpoint = 'files';
const options = {
method: 'POST',
rawBody: data,
};
const { statusCode, response } = await this._server.serverRequest(
endpoint,
options
);
if (statusCode !== 200) {
log.warn('Failed to upload data to fileserver');
return null;
}
const url = response.data && response.data.url;
const id = response.data && response.data.id;
return {
url,
id,
};
uploadPrivateAttachment(data) {
return this._server.uploadData(data);
}
}

@ -864,7 +864,7 @@ function initialize({
filename: 'attachment',
});
return lokiFileServerAPI.uploadData(formData);
return lokiFileServerAPI.uploadPrivateAttachment(formData);
}
// eslint-disable-next-line no-shadow

@ -1438,21 +1438,23 @@ MessageReceiver.prototype.extend({
},
async downloadAttachment(attachment) {
// The attachment id is actually just the absolute url of the attachment
const encrypted = await this.server.getAttachment(attachment.url);
const { key, digest, size } = attachment;
const data = await textsecure.crypto.decryptAttachment(
encrypted,
window.Signal.Crypto.base64ToArrayBuffer(key),
window.Signal.Crypto.base64ToArrayBuffer(digest)
);
if (!size || size !== data.byteLength) {
throw new Error(
`downloadAttachment: Size ${size} did not match downloaded attachment size ${
data.byteLength
}`
let data = await this.server.getAttachment(attachment.url);
if (!attachment.isRaw) {
const { key, digest, size } = attachment;
data = await textsecure.crypto.decryptAttachment(
data,
window.Signal.Crypto.base64ToArrayBuffer(key),
window.Signal.Crypto.base64ToArrayBuffer(digest)
);
if (!size || size !== data.byteLength) {
throw new Error(
`downloadAttachment: Size ${size} did not match downloaded attachment size ${
data.byteLength
}`
);
}
}
return {

Loading…
Cancel
Save