Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make private attachments use generic token #829

Merged
merged 4 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions js/expire.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
'', // no pubkey needed
window.getDefaultFileServer()
);
// use the anonymous access token
window.tokenlessFileServerAdnAPI.token = 'loki';
window.tokenlessFileServerAdnAPI.pubKey = window.Signal.Crypto.base64ToArrayBuffer(
LokiFileServerAPI.secureRpcPubKey
);
Expand Down
4 changes: 2 additions & 2 deletions js/modules/loki_app_dot_net_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,14 @@ class LokiAppDotNetServerAPI {
`serverRequest ${mode} error`,
e.code,
e.message,
`json: ${txtResponse}`
`json: ${txtResponse}`, 'attempting connection to', url
);
} else {
log.info(
`serverRequest ${mode} error`,
e.code,
e.message,
'atttempting connection to',
'attempting connection to',
url
);
}
Expand Down
11 changes: 9 additions & 2 deletions js/modules/loki_file_server_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ class LokiHomeServerInstance extends LokiFileServerInstance {
isPrimary: isPrimary ? '1' : '0',
authorisations,
};
if (!this.token) {
log.warn('_setOurDeviceMapping no token yet');
}
return this._server.setSelfAnnotation(
DEVICE_MAPPING_USER_ANNOTATION_TYPE,
content
Expand All @@ -269,11 +272,14 @@ class LokiHomeServerInstance extends LokiFileServerInstance {
// you only upload to your own home server
// you can download from any server...
uploadAvatar(data) {
if (!this.token) {
log.warn('uploadAvatar no token yet');
}
return this._server.uploadAvatar(data);
}

uploadPrivateAttachment(data) {
return this._server.uploadData(data);
static uploadPrivateAttachment(data) {
return window.tokenlessFileServerAdnAPI.uploadData(data);
}

clearOurDeviceMappingAnnotations() {
Expand All @@ -298,6 +304,7 @@ class LokiFileServerFactoryAPI {
if (!thisServer) {
thisServer = new LokiHomeServerInstance(this.ourKey);
log.info(`Registering HomeServer ${serverUrl}`);
// not await, so a failure or slow connection doesn't hinder loading of the app
thisServer.establishConnection(serverUrl);
this.servers.push(thisServer);
}
Expand Down
2 changes: 1 addition & 1 deletion js/modules/web_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ function initialize({
filename: 'attachment',
});

return lokiFileServerAPI.uploadPrivateAttachment(formData);
return lokiFileServerAPI.constructor.uploadPrivateAttachment(formData);
}

function putAvatar(bin) {
Expand Down