Skip to content

Commit 5facd94

Browse files
authored
Merge pull request #21996 from code-dot-org/assets_fix_overwrite_same_filename
Fix overwriting the same asset filename
2 parents 53a6321 + b230ea5 commit 5facd94

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

apps/src/applab/redux/screens.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ export function importIntoProject(projectId, screens, assets) {
203203
importFuncs.importScreensAndAssets(projectId, screens, assets).then(
204204
() => {
205205
dispatch({type: IMPORT.SCREENS.FINISHED_IMPORTING});
206-
const lastScreen = screens[screens.length - 1];
207-
dispatch(changeScreen(lastScreen.id));
206+
if (screens.length > 0) {
207+
const lastScreen = screens[screens.length - 1];
208+
dispatch(changeScreen(lastScreen.id));
209+
}
208210
},
209211
() => dispatch({type: IMPORT.SCREENS.FAILED_IMPORTING})
210212
);

apps/src/code-studio/assets/assetListStore.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
},
77

88
add: function (asset) {
9+
assets = this.remove(asset.filename);
910
assets.push(asset);
1011
return assets.slice();
1112
},

apps/src/code-studio/components/AssetManager.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export default class AssetManager extends React.Component {
168168
<AssetRow
169169
key={asset.filename}
170170
name={asset.filename}
171+
timestamp={asset.timestamp}
171172
type={asset.category}
172173
size={asset.size}
173174
useFilesApi={this.props.useFilesApi}

apps/src/code-studio/components/AssetRow.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import AssetThumbnail from './AssetThumbnail';
88
export default class AssetRow extends React.Component {
99
static propTypes = {
1010
name: PropTypes.string.isRequired,
11+
timestamp: PropTypes.string,
1112
type: PropTypes.oneOf(['image', 'audio', 'video', 'pdf', 'doc']).isRequired,
1213
size: PropTypes.number,
1314
useFilesApi: PropTypes.bool.isRequired,
@@ -111,6 +112,7 @@ export default class AssetRow extends React.Component {
111112
<AssetThumbnail
112113
type={this.props.type}
113114
name={this.props.name}
115+
timestamp={this.props.timestamp}
114116
useFilesApi={this.props.useFilesApi}
115117
/>
116118
</td>

apps/src/code-studio/components/AssetThumbnail.jsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const styles = {
4141
class AssetThumbnail extends React.Component {
4242
static propTypes = {
4343
name: PropTypes.string.isRequired,
44+
timestamp: PropTypes.string,
4445
type: PropTypes.oneOf(['image', 'audio', 'video', 'pdf', 'doc']).isRequired,
4546
style: PropTypes.object,
4647
iconStyle: PropTypes.object,
@@ -49,19 +50,34 @@ class AssetThumbnail extends React.Component {
4950
};
5051

5152
render() {
52-
const {type, name} = this.props;
53-
let api = this.props.useFilesApi ? filesApi : assetsApi;
54-
if (this.props.projectId) {
55-
api = api.withProjectId(this.props.projectId);
53+
const {
54+
timestamp,
55+
type,
56+
name,
57+
useFilesApi,
58+
projectId,
59+
iconStyle,
60+
style
61+
} = this.props;
62+
let api = useFilesApi ? filesApi : assetsApi;
63+
if (projectId) {
64+
api = api.withProjectId(projectId);
5665
}
66+
const basePath = api.basePath(name);
67+
let cacheBustSuffix = '';
68+
if (timestamp) {
69+
const date = new Date(timestamp);
70+
cacheBustSuffix = `?t=${date.valueOf()}`;
71+
}
72+
const srcPath = `${basePath}${cacheBustSuffix}`;
5773

5874
return (
59-
<div className="assetThumbnail" style={[styles.wrapper, this.props.style]}>
75+
<div className="assetThumbnail" style={[styles.wrapper, style]}>
6076
{type === 'image' ?
61-
<img src={api.basePath(name)} style={assetThumbnailStyle} /> :
77+
<img src={srcPath} style={assetThumbnailStyle} /> :
6278
<i
6379
className={defaultIcons[type] || defaultIcons.unknown}
64-
style={[assetIconStyle, this.props.iconStyle]}
80+
style={[assetIconStyle, iconStyle]}
6581
/>
6682
}
6783
</div>

shared/middleware/helpers/bucket_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def list(encrypted_channel_id)
8080
filename = %r{#{prefix}(.+)$}.match(fileinfo.key)[1]
8181
category = category_from_file_type(File.extname(filename))
8282

83-
{filename: filename, category: category, size: fileinfo.size}
83+
{filename: filename, category: category, size: fileinfo.size, timestamp: fileinfo.last_modified}
8484
end
8585
end
8686

0 commit comments

Comments
 (0)