make sure fileserver v1 is not supported and not used anymore

pull/1624/head
Audric Ackermann 4 years ago
parent a2ee3ac98f
commit 637e092a00
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -760,7 +760,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
let attachmentPromise;
let linkPreviewPromise;
let quotePromise;
const { AttachmentUtils } = Utils;
const { AttachmentFsV2Utils } = Utils;
// we want to go for the v1, if this is an OpenGroupV1 or not an open group at all
if (conversation?.isOpenGroupV2()) {
@ -773,12 +773,15 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
// because there is a fallback invoked on uploadV1() for attachments for not open groups attachments
const openGroupV1 = conversation?.isOpenGroupV1() ? conversation?.toOpenGroupV1() : undefined;
attachmentPromise = AttachmentUtils.uploadAttachmentsV1(
attachmentPromise = AttachmentFsV2Utils.uploadAttachmentsToFsV2(
filenameOverridenAttachments,
openGroupV1
);
linkPreviewPromise = AttachmentUtils.uploadLinkPreviewsV1(previewWithData, openGroupV1);
quotePromise = AttachmentUtils.uploadQuoteThumbnailsV1(quoteWithData, openGroupV1);
linkPreviewPromise = AttachmentFsV2Utils.uploadLinkPreviewsToFsV2(
previewWithData,
openGroupV1
);
quotePromise = AttachmentFsV2Utils.uploadQuoteThumbnailsToFsV2(quoteWithData, openGroupV1);
}
const [attachments, preview, quote] = await Promise.all([

@ -3,7 +3,7 @@ import _ from 'lodash';
import { MessageModel } from '../models/message';
import { saveMessage } from '../../ts/data/data';
import { fromBase64ToArrayBuffer } from '../session/utils/String';
import { AttachmentDownloads, AttachmentUtils } from '../session/utils';
import { AttachmentDownloads } from '../session/utils';
import { ConversationModel } from '../models/conversation';
import {
downloadFileOpenGroupV2,
@ -17,11 +17,6 @@ export async function downloadAttachment(attachment: any) {
const asURL = new URL(attachment.url);
const serverUrl = asURL.origin;
// The fileserver adds the `-static` part for some reason
const defaultFileserver = _.includes(
['https://file-static.lokinet.org', 'https://file.getsession.org'],
serverUrl
);
// is it an attachment hosted on the file server v2 ?
const defaultFsOldV2 = _.startsWith(serverUrl, FSv2.oldFileServerV2URL);
const defaultFsV2 = _.startsWith(serverUrl, FSv2.fileServerV2URL);

@ -204,13 +204,14 @@ export class ConversationController {
window?.log?.info('leaving open group v2', conversation.id);
const roomInfos = await getV2OpenGroupRoom(conversation.id);
if (roomInfos) {
OpenGroupManagerV2.getInstance().removeRoomFromPolledRooms(roomInfos);
// leave the group on the remote server
try {
await deleteAuthToken(_.pick(roomInfos, 'serverUrl', 'roomId'));
} catch (e) {
window?.log?.info('deleteAuthToken failed:', e);
}
OpenGroupManagerV2.getInstance().removeRoomFromPolledRooms(roomInfos);
// remove the roomInfos locally for this open group room
try {
await removeV2OpenGroupRoom(conversation.id);

@ -23,8 +23,8 @@ let onionPaths: Array<SnodePath> = [];
export const TEST_getTestOnionPath = () => {
return _.cloneDeep(onionPaths);
};
// tslint:disable-next-line: variable-name
// tslint:disable-next-line: variable-name
export const TEST_getTestguardNodes = () => {
return _.cloneDeep(guardNodes);
};

@ -39,11 +39,11 @@ interface RawQuote {
}
// tslint:disable-next-line: no-unnecessary-class
export class AttachmentUtils {
export class AttachmentFsV2Utils {
private constructor() {}
public static async uploadV1(params: UploadParams): Promise<AttachmentPointer> {
const { attachment, openGroup, isAvatar = false, isRaw = false, shouldPad = false } = params;
public static async uploadToFsV2(params: UploadParams): Promise<AttachmentPointer> {
const { attachment, openGroup, isRaw = false, shouldPad = false } = params;
if (typeof attachment !== 'object' || attachment == null) {
throw new Error('Invalid attachment passed.');
}
@ -53,15 +53,9 @@ export class AttachmentUtils {
`\`attachment.data\` must be an \`ArrayBuffer\`; got: ${typeof attachment.data}`
);
}
let server = window.tokenlessFileServerAdnAPI;
// this can only be an opengroupv1
if (openGroup) {
const openGroupServer = await window.lokiPublicChatAPI.findOrCreateServer(openGroup.server);
if (!openGroupServer) {
throw new Error(`Failed to get open group server: ${openGroup.server}.`);
}
server = openGroupServer;
throw new Error('opengroupv1 attachments are not supported anymore');
}
const pointer: AttachmentPointer = {
contentType: attachment.contentType || undefined,
@ -77,7 +71,6 @@ export class AttachmentUtils {
if (isRaw || openGroup) {
attachmentData = attachment.data;
} else {
server = window.tokenlessFileServerAdnAPI;
pointer.key = new Uint8Array(crypto.randomBytes(64));
const iv = new Uint8Array(crypto.randomBytes(16));
@ -95,7 +88,6 @@ export class AttachmentUtils {
}
// use file server v2
if (FSv2.useFileServerAPIV2Sending) {
const uploadToV2Result = await FSv2.uploadFileToFsV2(attachmentData);
if (uploadToV2Result) {
@ -104,39 +96,18 @@ export class AttachmentUtils {
} else {
window?.log?.warn('upload to file server v2 failed');
}
return pointer;
} else {
const result = isAvatar
? await server.putAvatar(attachmentData)
: await server.putAttachment(attachmentData);
pointer.id = result.id;
pointer.url = result.url;
}
return pointer;
}
public static async uploadAvatarV1(
attachment?: Attachment
): Promise<AttachmentPointer | undefined> {
if (!attachment) {
return undefined;
throw new Error('Only v2 fileserver upload is supported');
}
// isRaw is true since the data is already encrypted
// and doesn't need to be encrypted again
return this.uploadV1({
attachment,
isAvatar: true,
isRaw: true,
});
}
public static async uploadAttachmentsV1(
public static async uploadAttachmentsToFsV2(
attachments: Array<Attachment>,
openGroup?: OpenGroup
): Promise<Array<AttachmentPointer>> {
const promises = (attachments || []).map(async attachment =>
this.uploadV1({
this.uploadToFsV2({
attachment,
openGroup,
shouldPad: true,
@ -146,7 +117,7 @@ export class AttachmentUtils {
return Promise.all(promises);
}
public static async uploadLinkPreviewsV1(
public static async uploadLinkPreviewsToFsV2(
previews: Array<RawPreview>,
openGroup?: OpenGroup
): Promise<Array<Preview>> {
@ -157,7 +128,7 @@ export class AttachmentUtils {
}
return {
...item,
image: await this.uploadV1({
image: await this.uploadToFsV2({
attachment: item.image,
openGroup,
}),
@ -166,7 +137,7 @@ export class AttachmentUtils {
return Promise.all(promises);
}
public static async uploadQuoteThumbnailsV1(
public static async uploadQuoteThumbnailsToFsV2(
quote?: RawQuote,
openGroup?: OpenGroup
): Promise<Quote | undefined> {
@ -177,7 +148,7 @@ export class AttachmentUtils {
const promises = (quote.attachments ?? []).map(async attachment => {
let thumbnail: AttachmentPointer | undefined;
if (attachment.thumbnail) {
thumbnail = await this.uploadV1({
thumbnail = await this.uploadToFsV2({
attachment: attachment.thumbnail,
openGroup,
});

@ -8,7 +8,6 @@ import {
Quote,
QuotedAttachment,
} from '../messages/outgoing/visibleMessage/VisibleMessage';
import { AttachmentUtils } from './Attachments';
import { uploadFileOpenGroupV2 } from '../../opengroup/opengroupV2/OpenGroupAPIV2';
import { addAttachmentPadding } from '../crypto/BufferPadding';

Loading…
Cancel
Save