Skip to content

Commit

Permalink
[web] Move exifRotate from input-state-container to media-utils
Browse files Browse the repository at this point in the history
Summary:
I needed to use `validateFile` outside of `input-state-container`, but saw that it took `exifRotate` as an argument.

I first considered moving `exifRotate` to `media-utils` and exporting it globally so I could access it from `input-state-container` and elsewhere. But upon reading the code further, it looks like we only ever use `exifRotate` in `processFile(file: File)`, so I just moved it right above without exporting.

---

Depends on D8363 (kind of)

Test Plan:
Logged value of `browser` and `exifRotate` in Safari/Chrome/FireFox:

{F611533}

{F611534}

{F611535}

Reviewers: ashoat, ginsu, rohan

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D8364
  • Loading branch information
atulsmadhugiri committed Jul 28, 2023
1 parent 3285a75 commit 3ddb5a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
7 changes: 1 addition & 6 deletions web/input/input-state-container.react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow

import { detect as detectBrowser } from 'detect-browser';
import invariant from 'invariant';
import _groupBy from 'lodash/fp/groupBy.js';
import _keyBy from 'lodash/fp/keyBy.js';
Expand Down Expand Up @@ -115,10 +114,6 @@ import { updateNavInfoActionType } from '../redux/action-types.js';
import { useSelector } from '../redux/redux-utils.js';
import { nonThreadCalendarQuery } from '../selectors/nav-selectors.js';

const browser = detectBrowser();
const exifRotate =
!browser || (browser.name !== 'safari' && browser.name !== 'chrome');

type BaseProps = {
+children: React.Node,
};
Expand Down Expand Up @@ -746,7 +741,7 @@ class InputStateContainer extends React.PureComponent<Props, State> {
let response;
const validationStart = Date.now();
try {
response = await validateFile(file, exifRotate);
response = await validateFile(file);
} catch (e) {
return {
steps,
Expand Down
18 changes: 9 additions & 9 deletions web/media/media-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow

import { detect as detectBrowser } from 'detect-browser';
import * as React from 'react';
import { thumbHashToDataURL } from 'thumbhash';

Expand Down Expand Up @@ -96,10 +97,12 @@ type ProcessFileSuccess = {
uri: string,
dimensions: ?Dimensions,
};
async function processFile(
file: File,
exifRotate: boolean,
): Promise<{

const browser = detectBrowser();
const exifRotate =
!browser || (browser.name !== 'safari' && browser.name !== 'chrome');

async function processFile(file: File): Promise<{
steps: $ReadOnlyArray<MediaMissionStep>,
result: MediaMissionFailure | ProcessFileSuccess,
}> {
Expand Down Expand Up @@ -201,16 +204,13 @@ type FileValidationSuccess = {
uri: string,
dimensions: ?Dimensions,
};
async function validateFile(
file: File,
exifRotate: boolean,
): Promise<{
async function validateFile(file: File): Promise<{
steps: $ReadOnlyArray<MediaMissionStep>,
result: MediaMissionFailure | FileValidationSuccess,
}> {
const [probeResponse, processResponse] = await Promise.all([
probeFile(file),
processFile(file, exifRotate),
processFile(file),
]);
const { steps: probeSteps, result: probeResult } = probeResponse;
const { steps: processSteps, result: processResult } = processResponse;
Expand Down

0 comments on commit 3ddb5a9

Please sign in to comment.