Skip to content

Commit

Permalink
deal with path later
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed Mar 1, 2018
1 parent 029dbe5 commit 181b6db
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
rootFiles: [ 'index.js', 'index.jsx', 'main.js', 'main.jsx' ],
} ],
'wpcalypso/import-no-redux-combine-reducers': 2,
'import/no-nodejs-modules': [ 'error', { allow: [ 'querystring', 'url', 'events' ] } ],
'import/no-nodejs-modules': [ 'error', { allow: [ 'querystring', 'url', 'events', 'path' ] } ],
'import/no-extraneous-dependencies': [ 'error', { packageDir: './' } ],
}
};
5 changes: 3 additions & 2 deletions client/blocks/edit-gravatar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, { Component } from 'react';
import classnames from 'classnames';
import { connect } from 'react-redux';
import { localize } from 'i18n-calypso';
import path from 'path';
import Gridicon from 'gridicons';

/**
Expand All @@ -33,7 +34,6 @@ import ExternalLink from 'components/external-link';
import VerifyEmailDialog from 'components/email-verification/email-verification-dialog';
import DropZone from 'components/drop-zone';
import { recordTracksEvent, recordGoogleEvent, composeAnalytics } from 'state/analytics/actions';
import { extname } from 'lib/media/utils';

export class EditGravatar extends Component {
state = {
Expand All @@ -59,7 +59,8 @@ export class EditGravatar extends Component {
translate,
recordReceiveImageEvent,
} = this.props;
const extension = extname( files[ 0 ].name )
const extension = path
.extname( files[ 0 ].name )
.toLowerCase()
.substring( 1 );

Expand Down
5 changes: 3 additions & 2 deletions client/blocks/image-editor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { noop, isEqual, partial } from 'lodash';
import path from 'path';
import { localize } from 'i18n-calypso';
import classNames from 'classnames';

Expand All @@ -20,7 +21,7 @@ import Notice from 'components/notice';
import ImageEditorCanvas from './image-editor-canvas';
import ImageEditorToolbar from './image-editor-toolbar';
import ImageEditorButtons from './image-editor-buttons';
import { getMimeType, url, basename } from 'lib/media/utils';
import { getMimeType, url } from 'lib/media/utils';
import {
resetImageEditorState,
resetAllImageEditorState,
Expand Down Expand Up @@ -115,7 +116,7 @@ class ImageEditor extends React.Component {
photon: site && ! site.is_private,
} );

fileName = media.file || basename( src );
fileName = media.file || path.basename( src );

mimeType = getMimeType( media ) || mimeType;

Expand Down
22 changes: 6 additions & 16 deletions client/lib/media/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* External dependencies
*/
import urlLib from 'url';
import path from 'path';
import photon from 'photon';
import { includes, omitBy, startsWith, get } from 'lodash';
import { isUri } from 'valid-url';
Expand All @@ -25,17 +26,6 @@ import versionCompare from 'lib/version-compare';

const { uniqueId } = impureLodash;

/**
* Taken from the official browserify 'path' polyfill: https://github.com/substack/path-browserify/blob/master/index.js
*
* Split a filename into [root, dir, basename, ext], unix version
* 'root' is just a slash, or nothing.
*/
const splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
const splitPath = filename => splitPathRe.exec( filename ).slice( 1 );
export const extname = path => splitPath( path )[ 3 ];
export const basename = path => splitPath( path )[ 2 ];

/**
* Module variables
*/
Expand Down Expand Up @@ -118,14 +108,14 @@ export function getFileExtension( media ) {
filePath = media;
}

extension = extname( filePath ).slice( 1 );
extension = path.extname( filePath ).slice( 1 );
} else if ( isFileObject ) {
extension = extname( media.name ).slice( 1 );
extension = path.extname( media.name ).slice( 1 );
} else if ( media.extension ) {
extension = media.extension;
} else {
const pathname = urlLib.parse( media.URL || media.file || media.guid || '' ).pathname || '';
extension = extname( pathname ).slice( 1 );
extension = path.extname( pathname ).slice( 1 );
}

return extension;
Expand Down Expand Up @@ -548,7 +538,7 @@ export function createTransientMedia( file ) {
// Generate from string
Object.assign( transientMedia, {
file: file,
title: basename( file ),
title: path.basename( file ),
extension: getFileExtension( file ),
mime_type: getMimeType( file ),
} );
Expand Down Expand Up @@ -576,7 +566,7 @@ export function createTransientMedia( file ) {
URL: fileUrl,
guid: fileUrl,
file: fileName,
title: file.title || basename( fileName ),
title: file.title || path.basename( fileName ),
extension: getFileExtension( file.fileName || fileContents ),
mime_type: getMimeType( file.fileName || fileContents ),
// Size is not an API media property, though can be useful for
Expand Down
1 change: 0 additions & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"notifications-panel": "2.1.5",
"npm-run-all": "4.0.2",
"page": "1.6.4",
"path": "0.12.7",
"percentage-regex": "3.0.0",
"phone": "git+https://github.com/Automattic/node-phone.git#1.0.8",
"photon": "2.0.1",
Expand Down

0 comments on commit 181b6db

Please sign in to comment.