Skip to content

Commit

Permalink
Created ATTACHMENT_ID regex
Browse files Browse the repository at this point in the history
  • Loading branch information
s77rt committed Jan 23, 2023
1 parent 0b4d0b6 commit 5cd5533
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ const CONST = {
EMOJI_SUGGESTIONS: /:[a-zA-Z0-9_+-]{1,40}$/,
AFTER_FIRST_LINE_BREAK: /\n.*/g,
CODE_2FA: /^\d{6}$/,

ATTACHMENT_ID: /chat-attachments\/(\d+)/,
},

PRONOUNS: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
propTypes as anchorForAttachmentsOnlyPropTypes,
defaultProps as anchorForAttachmentsOnlyDefaultProps,
} from './anchorForAttachmentsOnlyPropTypes';
import CONST from '../../CONST';
import ONYXKEYS from '../../ONYXKEYS';
import AttachmentView from '../AttachmentView';
import * as Download from '../../libs/actions/Download';
Expand Down Expand Up @@ -33,7 +34,7 @@ class BaseAnchorForAttachmentsOnly extends React.Component {
render() {
const sourceURL = this.props.source;
const sourceURLWithAuth = addEncryptedAuthTokenToURL(sourceURL);
const sourceID = (sourceURL.match(/chat-attachments\/(\d+)/) || [])[1];
const sourceID = (sourceURL.match(CONST.REGEX.ATTACHMENT_ID) || [])[1];
const fileName = this.props.displayName;

const isDownloading = this.props.download && this.props.download.isDownloading;
Expand Down Expand Up @@ -84,7 +85,7 @@ BaseAnchorForAttachmentsOnly.defaultProps = defaultProps;
export default withOnyx({
download: {
key: ({source}) => {
const sourceID = (source.match(/chat-attachments\/(\d+)/) || [])[1];
const sourceID = (source.match(CONST.REGEX.ATTACHMENT_ID) || [])[1];
return `${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`;
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default [
const attachmentDetails = getAttachmentDetails(html);
const {originalFileName, sourceURL} = attachmentDetails;
const sourceURLWithAuth = addEncryptedAuthTokenToURL(sourceURL);
const sourceID = (sourceURL.match(/chat-attachments\/(\d+)/) || [])[1];
const sourceID = (sourceURL.match(CONST.REGEX.ATTACHMENT_ID) || [])[1];
Download.setDownload(sourceID, true);
fileDownload(sourceURLWithAuth, originalFileName).then(() => Download.setDownload(sourceID, false));
if (closePopover) {
Expand Down

0 comments on commit 5cd5533

Please sign in to comment.