HomePhabricator
Diffusion Comm c5e3e7ca5bc8

[keyserver] Use the internal-ip package in the dev environment to ensure…

Description

[keyserver] Use the internal-ip package in the dev environment to ensure physical device / emulators can access uploads

Summary:
The majority of the context is contained in the Linear task (https://linear.app/comm/issue/ENG-2924/use-the-internal-ip-package-in-the-dev-environment-to-ensure-physical). In short, the current shimUploadURI will detect what OS the user is on, and if it's iOS return localhost and if it's Android return 10.0.2.2. This works fine for the emulators, but makes testing uploads on physical devices difficult because we'd need to use a different method and get the accessing devices' IPv4 address to return in the upload url. By removing shimUploadURI and always using the IPv4 address (regardless of emulator or physical device), we keep the logic consistent between testing devices. Handling the logic to do this directly within getUploadURL allows all uploads when fetched to return to an address that is accessible across all dev environments.

Another note: I looked through D6266 prior to working on this, and while it looks like internal-ip version 7.0.0 worked fine within the keyserver, I chose to use version 4.3.0 in an effort to keep consistent. If we want to change to 7.0.0, there should only be four things that need to be done:

  1. Change the version in devDependencies
  2. Change the import from import ip from 'internal-ip to import { internalIpV4Sync } from 'internal-ip' to prevent SyntaxError: The requested module 'internal-ip' does not provide an export named 'default'
  3. Change the use of ip.v4.sync() to internalIpV4Sync() in getUploadURL.
  4. Run yarn dev in native and ensure that it still works (see @bartek's comment below)

Adding @ashoat as blocking since it involves a dependency

Depends on D6531

Test Plan:
Ran yarn cleaninstall, restarted keyserver and tested across each of the clients:

  1. Web client - media is at the url: http://{IPv4}:3000/comm/upload/84155/1f243e6ee9d4d2b8
  2. iOS Emulator - media is at the url: http://{IPv4}:3000/comm/upload/84155/1f243e6ee9d4d2b8
  3. Android Emulator - media is at the url: http://{IPv4}:3000/comm/upload/84155/1f243e6ee9d4d2b8
  4. Physical iPhone build - media is at the url: http://{IPv4}:3000/comm/upload/84155/1f243e6ee9d4d2b8
  5. Physical Android build - (I don't have access to an Android device so I won't be able to do this one)

Reviewers: ashoat, atul, bartek

Reviewed By: ashoat, bartek

Subscribers: tomek, ashoat

Differential Revision: https://phab.comm.dev/D6587