mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
Add LokiFileServerAPI
This commit is contained in:
parent
dc6d3b5ca2
commit
e07f81c150
|
@ -31,5 +31,6 @@
|
|||
"-----BEGIN CERTIFICATE-----\nMIID7zCCAtegAwIBAgIJAIm6LatK5PNiMA0GCSqGSIb3DQEBBQUAMIGNMQswCQYD\nVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5j\naXNjbzEdMBsGA1UECgwUT3BlbiBXaGlzcGVyIFN5c3RlbXMxHTAbBgNVBAsMFE9w\nZW4gV2hpc3BlciBTeXN0ZW1zMRMwEQYDVQQDDApUZXh0U2VjdXJlMB4XDTEzMDMy\nNTIyMTgzNVoXDTIzMDMyMzIyMTgzNVowgY0xCzAJBgNVBAYTAlVTMRMwEQYDVQQI\nDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNpc2NvMR0wGwYDVQQKDBRP\ncGVuIFdoaXNwZXIgU3lzdGVtczEdMBsGA1UECwwUT3BlbiBXaGlzcGVyIFN5c3Rl\nbXMxEzARBgNVBAMMClRleHRTZWN1cmUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw\nggEKAoIBAQDBSWBpOCBDF0i4q2d4jAXkSXUGpbeWugVPQCjaL6qD9QDOxeW1afvf\nPo863i6Crq1KDxHpB36EwzVcjwLkFTIMeo7t9s1FQolAt3mErV2U0vie6Ves+yj6\ngrSfxwIDAcdsKmI0a1SQCZlr3Q1tcHAkAKFRxYNawADyps5B+Zmqcgf653TXS5/0\nIPPQLocLn8GWLwOYNnYfBvILKDMItmZTtEbucdigxEA9mfIvvHADEbteLtVgwBm9\nR5vVvtwrD6CCxI3pgH7EH7kMP0Od93wLisvn1yhHY7FuYlrkYqdkMvWUrKoASVw4\njb69vaeJCUdU+HCoXOSP1PQcL6WenNCHAgMBAAGjUDBOMB0GA1UdDgQWBBQBixjx\nP/s5GURuhYa+lGUypzI8kDAfBgNVHSMEGDAWgBQBixjxP/s5GURuhYa+lGUypzI8\nkDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQB+Hr4hC56m0LvJAu1R\nK6NuPDbTMEN7/jMojFHxH4P3XPFfupjR+bkDq0pPOU6JjIxnrD1XD/EVmTTaTVY5\niOheyv7UzJOefb2pLOc9qsuvI4fnaESh9bhzln+LXxtCrRPGhkxA1IMIo3J/s2WF\n/KVYZyciu6b4ubJ91XPAuBNZwImug7/srWvbpk0hq6A6z140WTVSKtJG7EP41kJe\n/oF4usY5J7LPkxK3LWzMJnb5EIJDmRvyH8pyRwWg6Qm6qiGFaI4nL8QU4La1x2en\n4DGXRaLMPRwjELNgQPodR38zoCMuA8gHZfZYYoZ7D7Q1wNUiVHcxuFrEeBaYJbLE\nrwLV\n-----END CERTIFICATE-----\n",
|
||||
"import": false,
|
||||
"serverTrustRoot": "BbqY1DzohE4NUZoVF+L18oUPrK3kILllLEJh2UnPSsEx",
|
||||
"defaultPublicChatServer": "https://chat.lokinet.org/"
|
||||
"defaultPublicChatServer": "https://chat.lokinet.org/",
|
||||
"defaultFileServer": "https://file.lokinet.org"
|
||||
}
|
||||
|
|
|
@ -229,7 +229,10 @@
|
|||
const ourKey = textsecure.storage.user.getNumber();
|
||||
window.feeds = [];
|
||||
window.lokiMessageAPI = new window.LokiMessageAPI(ourKey);
|
||||
// singleton to relay events to libtextsecure/message_receiver
|
||||
window.lokiPublicChatAPI = new window.LokiPublicChatAPI(ourKey);
|
||||
// singleton to interface the File server
|
||||
window.lokiFileServerAPI = new window.LokiFileServerAPI(ourKey);
|
||||
window.lokiP2pAPI = new window.LokiP2pAPI(ourKey);
|
||||
window.lokiP2pAPI.on('pingContact', pubKey => {
|
||||
const isPing = true;
|
||||
|
|
40
js/modules/loki_file_server_api.js
Normal file
40
js/modules/loki_file_server_api.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* global storage: false */
|
||||
/* global libloki: false */
|
||||
/* global Signal: false */
|
||||
|
||||
const LokiAppDotNetAPI = require('./loki_app_dot_net_api');
|
||||
|
||||
const DEVICE_MAPPING_ANNOTATION_KEY = 'network.loki.messenger.devicemapping';
|
||||
|
||||
// returns the LokiFileServerAPI constructor with the serverUrl already consumed
|
||||
function LokiFileServerAPIWrapper(serverUrl) {
|
||||
return LokiFileServerAPI.bind(null, serverUrl);
|
||||
}
|
||||
|
||||
class LokiFileServerAPI {
|
||||
constructor(serverUrl, ourKey) {
|
||||
this.ourKey = ourKey;
|
||||
this._adnApi = new LokiAppDotNetAPI(ourKey);
|
||||
this._server = this._adnApi.findOrCreateServer(serverUrl);
|
||||
}
|
||||
|
||||
async getUserDeviceMapping(pubKey) {
|
||||
const annotations = await this._server.getUserAnnotations(pubKey);
|
||||
return annotations.find(
|
||||
annotation => annotation.type === DEVICE_MAPPING_ANNOTATION_KEY
|
||||
);
|
||||
}
|
||||
|
||||
setOurDeviceMapping(authorisations, isPrimary) {
|
||||
const content = {
|
||||
isPrimary: isPrimary ? '1' : '0',
|
||||
authorisations,
|
||||
};
|
||||
return this._server.setSelfAnnotation(
|
||||
DEVICE_MAPPING_ANNOTATION_KEY,
|
||||
content
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LokiFileServerAPIWrapper;
|
1
main.js
1
main.js
|
@ -166,6 +166,7 @@ function prepareURL(pathSegments, moreKeys) {
|
|||
contentProxyUrl: config.contentProxyUrl,
|
||||
importMode: importMode ? true : undefined, // for stringify()
|
||||
serverTrustRoot: config.get('serverTrustRoot'),
|
||||
defaultFileServer: config.get('defaultFileServer'),
|
||||
...moreKeys,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -326,6 +326,11 @@ window.LokiMessageAPI = require('./js/modules/loki_message_api');
|
|||
|
||||
window.LokiPublicChatAPI = require('./js/modules/loki_public_chat_api');
|
||||
|
||||
const LokiFileServerAPIWrapper = require('./js/modules/loki_file_server_api');
|
||||
|
||||
// bind first argument as we have it here already
|
||||
window.LokiFileServerAPI = LokiFileServerAPIWrapper(config.defaultFileServer);
|
||||
|
||||
window.LokiRssAPI = require('./js/modules/loki_rss_api');
|
||||
|
||||
window.LocalLokiServer = require('./libloki/modules/local_loki_server');
|
||||
|
|
Loading…
Reference in a new issue