Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3339294
D6587.id22143.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D6587.id22143.diff
View Options
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,11 +1,13 @@
// @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 type { ThreadFetchMediaResult } from 'lib/types/thread-types';
+import { isDev } from 'lib/utils/dev-utils';
import { ServerError } from 'lib/utils/errors';
import { dbQuery, SQL } from '../database/database';
@@ -81,7 +83,13 @@
function getUploadURL(id: string, secret: string): string {
const { baseDomain, basePath } = getAndAssertCommAppURLFacts();
- return `${baseDomain}${basePath}upload/${id}/${secret}`;
+ const uploadPath = `${basePath}upload/${id}/${secret}`;
+ if (isDev) {
+ const ipV4 = ip.v4.sync() || 'localhost';
+ const port = parseInt(process.env.PORT, 10) || 3000;
+ return `http://${ipV4}:${port}${uploadPath}`;
+ }
+ return `${baseDomain}${uploadPath}`;
}
function mediaFromRow(row: Object): Media {
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<Media>): 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,10 +5,8 @@
import {
contentStringForMediaArray,
multimediaMessagePreview,
- shimUploadURI,
} from '../../media/media-utils';
import type { PlatformDetails } from '../../types/device-types';
-import type { Media, Video, Image } from '../../types/media-types';
import {
messageTypes,
assertMessageType,
@@ -17,7 +15,6 @@
import type {
MessageInfo,
RawMessageInfo,
- RawMultimediaMessageInfo,
ClientDBMessageInfo,
} from '../../types/message-types';
import type {
@@ -202,30 +199,22 @@
platformDetails: ?PlatformDetails,
): RawMediaMessageInfo | RawImagesMessageInfo | RawUnsupportedMessageInfo {
if (rawMessageInfo.type === messageTypes.IMAGES) {
- const shimmedRawMessageInfo = shimMediaMessageInfo(
- rawMessageInfo,
- platformDetails,
- );
- return shimmedRawMessageInfo;
+ return rawMessageInfo;
} else {
- const shimmedRawMessageInfo = shimMediaMessageInfo(
- rawMessageInfo,
- platformDetails,
- );
// TODO figure out first native codeVersion supporting video playback
if (hasMinCodeVersion(platformDetails, 158)) {
- return shimmedRawMessageInfo;
+ return rawMessageInfo;
}
- const { id } = shimmedRawMessageInfo;
+ const { id } = rawMessageInfo;
invariant(id !== null && id !== undefined, 'id should be set on server');
return {
type: messageTypes.UNSUPPORTED,
id,
- threadID: shimmedRawMessageInfo.threadID,
- creatorID: shimmedRawMessageInfo.creatorID,
- time: shimmedRawMessageInfo.time,
- robotext: multimediaMessagePreview(shimmedRawMessageInfo),
- unsupportedMessageInfo: shimmedRawMessageInfo,
+ threadID: rawMessageInfo.threadID,
+ creatorID: rawMessageInfo.creatorID,
+ time: rawMessageInfo.time,
+ robotext: multimediaMessagePreview(rawMessageInfo),
+ unsupportedMessageInfo: rawMessageInfo,
};
}
},
@@ -313,54 +302,6 @@
includedInRepliesCount: true,
});
-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);
- if (shimmedURI === singleMedia.uri) {
- newMedia.push(singleMedia);
- } else {
- newMedia.push(({ ...singleMedia, uri: shimmedURI }: Image));
- uriChanged = true;
- }
- }
- if (!uriChanged) {
- return rawMessageInfo;
- }
- return ({
- ...rawMessageInfo,
- media: newMedia,
- }: RawImagesMessageInfo);
- } else {
- let uriChanged = false;
- const newMedia: Media[] = [];
- for (const singleMedia of rawMessageInfo.media) {
- const shimmedURI = shimUploadURI(singleMedia.uri, platformDetails);
- if (shimmedURI === singleMedia.uri) {
- newMedia.push(singleMedia);
- } else if (singleMedia.type === 'photo') {
- newMedia.push(({ ...singleMedia, uri: shimmedURI }: Image));
- uriChanged = true;
- } else {
- newMedia.push(({ ...singleMedia, uri: shimmedURI }: Video));
- uriChanged = true;
- }
- }
- if (!uriChanged) {
- return rawMessageInfo;
- }
- return ({
- ...rawMessageInfo,
- media: newMedia,
- }: RawMediaMessageInfo);
- }
-}
-
// Four photos were uploaded before dimensions were calculated server-side,
// and delivered to clients without dimensions in the MultimediaMessageInfo.
const preDimensionUploads = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 7:34 PM (15 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2564385
Default Alt Text
D6587.id22143.diff (7 KB)
Attached To
Mode
D6587: [keyserver] Use the internal-ip package in the dev environment to ensure physical device / emulators can access uploads
Attached
Detach File
Event Timeline
Log In to Comment