|
|
|
@ -44,12 +44,9 @@ class LokiAppDotNetServerAPI {
|
|
|
|
if (!thisChannel) {
|
|
|
|
if (!thisChannel) {
|
|
|
|
// make sure we're subscribed
|
|
|
|
// make sure we're subscribed
|
|
|
|
// eventually we'll need to move to account registration/add server
|
|
|
|
// eventually we'll need to move to account registration/add server
|
|
|
|
await this.serverRequest(
|
|
|
|
await this.serverRequest(`channels/${channelId}/subscribe`, {
|
|
|
|
`channels/${channelId}/subscribe`,
|
|
|
|
method: 'POST',
|
|
|
|
{
|
|
|
|
});
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
thisChannel = new LokiPublicChannelAPI(
|
|
|
|
thisChannel = new LokiPublicChannelAPI(
|
|
|
|
chatAPI,
|
|
|
|
chatAPI,
|
|
|
|
this,
|
|
|
|
this,
|
|
|
|
@ -310,17 +307,15 @@ class LokiAppDotNetServerAPI {
|
|
|
|
(this.baseServerUrl === 'https://file-dev.lokinet.org' ||
|
|
|
|
(this.baseServerUrl === 'https://file-dev.lokinet.org' ||
|
|
|
|
this.baseServerUrl === 'https://file.lokinet.org')
|
|
|
|
this.baseServerUrl === 'https://file.lokinet.org')
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
const finalOptions = {...fetchOptions}
|
|
|
|
const finalOptions = { ...fetchOptions };
|
|
|
|
if (!fetchOptions.method) {
|
|
|
|
if (!fetchOptions.method) {
|
|
|
|
finalOptions.method = 'GET';
|
|
|
|
finalOptions.method = 'GET';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const urlStr = urlObj.toString();
|
|
|
|
const urlStr = urlObj.toString();
|
|
|
|
const endpoint = urlStr.replace(`${this.baseServerUrl}/`, '');
|
|
|
|
const endpoint = urlStr.replace(`${this.baseServerUrl}/`, '');
|
|
|
|
const { response, result } = await this._sendToProxy(
|
|
|
|
const { response, result } = await this._sendToProxy(
|
|
|
|
finalOptions,
|
|
|
|
endpoint,
|
|
|
|
finalOptions.method,
|
|
|
|
finalOptions
|
|
|
|
finalOptions.headers,
|
|
|
|
|
|
|
|
endpoint
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
// emulate nodeFetch response...
|
|
|
|
// emulate nodeFetch response...
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
@ -331,7 +326,7 @@ class LokiAppDotNetServerAPI {
|
|
|
|
return nodeFetch(urlObj, fetchOptions);
|
|
|
|
return nodeFetch(urlObj, fetchOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async _sendToProxy(fetchOptions, method, headers, endpoint) {
|
|
|
|
async _sendToProxy(endpoint, fetchOptions) {
|
|
|
|
const randSnode = await lokiSnodeAPI.getRandomSnodeAddress();
|
|
|
|
const randSnode = await lokiSnodeAPI.getRandomSnodeAddress();
|
|
|
|
const url = `https://${randSnode.ip}:${randSnode.port}/file_proxy`;
|
|
|
|
const url = `https://${randSnode.ip}:${randSnode.port}/file_proxy`;
|
|
|
|
|
|
|
|
|
|
|
|
@ -339,8 +334,8 @@ class LokiAppDotNetServerAPI {
|
|
|
|
// I think this is a stream, we may need to collect it all?
|
|
|
|
// I think this is a stream, we may need to collect it all?
|
|
|
|
body: fetchOptions.body, // might need to b64 if binary...
|
|
|
|
body: fetchOptions.body, // might need to b64 if binary...
|
|
|
|
endpoint,
|
|
|
|
endpoint,
|
|
|
|
method,
|
|
|
|
method: fetchOptions.method,
|
|
|
|
headers,
|
|
|
|
headers: fetchOptions.headers,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// from https://github.com/sindresorhus/is-stream/blob/master/index.js
|
|
|
|
// from https://github.com/sindresorhus/is-stream/blob/master/index.js
|
|
|
|
@ -478,12 +473,9 @@ class LokiAppDotNetServerAPI {
|
|
|
|
this.baseServerUrl === 'https://file.lokinet.org')
|
|
|
|
this.baseServerUrl === 'https://file.lokinet.org')
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
mode = '_sendToProxy';
|
|
|
|
mode = '_sendToProxy';
|
|
|
|
// have to send headers because fetchOptions.headers isn't readable
|
|
|
|
|
|
|
|
({ response, txtResponse, result } = await this._sendToProxy(
|
|
|
|
({ response, txtResponse, result } = await this._sendToProxy(
|
|
|
|
fetchOptions,
|
|
|
|
endpoint,
|
|
|
|
method,
|
|
|
|
fetchOptions
|
|
|
|
headers,
|
|
|
|
|
|
|
|
endpoint
|
|
|
|
|
|
|
|
));
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
result = await nodeFetch(url, fetchOptions);
|
|
|
|
result = await nodeFetch(url, fetchOptions);
|
|
|
|
|