diff --git a/keyserver/package.json b/keyserver/package.json --- a/keyserver/package.json +++ b/keyserver/package.json @@ -35,6 +35,7 @@ "concurrently": "^5.3.0", "flow-bin": "^0.182.0", "flow-typed": "^3.2.1", + "internal-ip": "4.3.0", "jest": "^26.6.3", "nodemon": "^2.0.4" }, diff --git a/keyserver/src/creators/upload-creator.js b/keyserver/src/creators/upload-creator.js --- a/keyserver/src/creators/upload-creator.js +++ b/keyserver/src/creators/upload-creator.js @@ -2,7 +2,6 @@ import crypto from 'crypto'; -import { shimUploadURI } from 'lib/media/media-utils'; import type { MediaType, UploadMultimediaResult, @@ -39,7 +38,7 @@ return { uploadResult: { id, - uri: shimUploadURI(getUploadURL(id, secret), viewer.platformDetails), + uri: getUploadURL(id, secret), dimensions, mediaType, loop, diff --git a/keyserver/src/fetchers/upload-fetchers.js b/keyserver/src/fetchers/upload-fetchers.js --- a/keyserver/src/fetchers/upload-fetchers.js +++ b/keyserver/src/fetchers/upload-fetchers.js @@ -1,10 +1,12 @@ // @flow +import ip from 'internal-ip'; import _keyBy from 'lodash/fp/keyBy'; import type { Media } from 'lib/types/media-types'; import type { MediaMessageServerDBContent } from 'lib/types/messages/media.js'; import { getUploadIDsFromMediaMessageServerDBContents } from 'lib/types/messages/media.js'; +import { isDev } from 'lib/utils/dev-utils'; import { ServerError } from 'lib/utils/errors'; import { dbQuery, SQL } from '../database/database'; @@ -80,6 +82,11 @@ function getUploadURL(id: string, secret: string): string { const { baseDomain, basePath } = getAndAssertCommAppURLFacts(); + if (isDev) { + const ipV4 = ip.v4.sync() || 'localhost'; + const port = parseInt(process.env.PORT, 10) || 3000; + return `http://${ipV4}:${port}${basePath}upload/${id}/${secret}`; + } return `${baseDomain}${basePath}upload/${id}/${secret}`; } diff --git a/lib/media/media-utils.js b/lib/media/media-utils.js --- a/lib/media/media-utils.js +++ b/lib/media/media-utils.js @@ -2,7 +2,6 @@ import invariant from 'invariant'; -import type { PlatformDetails } from '../types/device-types'; import type { Media } from '../types/media-types'; import type { MultimediaMessageInfo, @@ -11,15 +10,6 @@ const maxDimensions = Object.freeze({ width: 1920, height: 1920 }); -const localhostRegex = /^http:\/\/localhost/; -function shimUploadURI(uri: string, platformDetails: ?PlatformDetails): string { - if (!platformDetails || platformDetails.platform !== 'android') { - return uri; - } - // We do this for testing in the Android emulator - return uri.replace(localhostRegex, 'http://10.0.2.2'); -} - function contentStringForMediaArray(media: $ReadOnlyArray): string { if (media.length === 0) { return 'corrupted media'; @@ -64,7 +54,6 @@ export { maxDimensions, - shimUploadURI, contentStringForMediaArray, multimediaMessagePreview, isLocalUploadID, diff --git a/lib/shared/messages/multimedia-message-spec.js b/lib/shared/messages/multimedia-message-spec.js --- a/lib/shared/messages/multimedia-message-spec.js +++ b/lib/shared/messages/multimedia-message-spec.js @@ -5,7 +5,6 @@ import { contentStringForMediaArray, multimediaMessagePreview, - shimUploadURI, } from '../../media/media-utils'; import type { PlatformDetails } from '../../types/device-types'; import type { Media, Video, Image } from '../../types/media-types'; @@ -212,16 +211,10 @@ platformDetails: ?PlatformDetails, ): RawMediaMessageInfo | RawImagesMessageInfo | RawUnsupportedMessageInfo { if (rawMessageInfo.type === messageTypes.IMAGES) { - const shimmedRawMessageInfo = shimMediaMessageInfo( - rawMessageInfo, - platformDetails, - ); + const shimmedRawMessageInfo = shimMediaMessageInfo(rawMessageInfo); return shimmedRawMessageInfo; } else { - const shimmedRawMessageInfo = shimMediaMessageInfo( - rawMessageInfo, - platformDetails, - ); + const shimmedRawMessageInfo = shimMediaMessageInfo(rawMessageInfo); // TODO figure out first native codeVersion supporting video playback if (hasMinCodeVersion(platformDetails, 158)) { return shimmedRawMessageInfo; @@ -326,13 +319,12 @@ function shimMediaMessageInfo( rawMessageInfo: RawMultimediaMessageInfo, - platformDetails: ?PlatformDetails, ): RawMultimediaMessageInfo { if (rawMessageInfo.type === messageTypes.IMAGES) { let uriChanged = false; const newMedia: Image[] = []; for (const singleMedia of rawMessageInfo.media) { - const shimmedURI = shimUploadURI(singleMedia.uri, platformDetails); + const shimmedURI = singleMedia.uri; if (shimmedURI === singleMedia.uri) { newMedia.push(singleMedia); } else { @@ -351,7 +343,7 @@ let uriChanged = false; const newMedia: Media[] = []; for (const singleMedia of rawMessageInfo.media) { - const shimmedURI = shimUploadURI(singleMedia.uri, platformDetails); + const shimmedURI = singleMedia.uri; if (shimmedURI === singleMedia.uri) { newMedia.push(singleMedia); } else if (singleMedia.type === 'photo') {