MM-20778 Remove caption as part of the file path (#3654)
This commit is contained in:
parent
66424a698b
commit
a730bec201
3 changed files with 34 additions and 4 deletions
|
|
@ -89,7 +89,7 @@ export default class Downloader extends PureComponent {
|
|||
ToastAndroid.show(started, ToastAndroid.SHORT);
|
||||
onDownloadStart();
|
||||
|
||||
let dest = `${RNFetchBlob.fs.dirs.DownloadDir}/${data.id}-${file.caption}`;
|
||||
let dest = `${RNFetchBlob.fs.dirs.DownloadDir}/${data.id}-${data.name}`;
|
||||
let downloadFile = true;
|
||||
|
||||
if (data.localPath) {
|
||||
|
|
|
|||
|
|
@ -230,8 +230,8 @@ function populateMaps() {
|
|||
}
|
||||
|
||||
export function getLocalFilePathFromFile(dir, file) {
|
||||
if (dir && file && file.caption && file.data && file.data.id) {
|
||||
return `${dir}/${file.data.id}-${decodeURIComponent(file.caption).replace(/\s+/g, '-')}`;
|
||||
if (dir && file && file.data && file.data.id && file.data.extension) {
|
||||
return `${dir}/${file.data.id}.${file.data.extension}`;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {getExtensionFromContentDisposition} from 'app/utils/file';
|
||||
import {generateId, getLocalFilePathFromFile, getExtensionFromContentDisposition} from 'app/utils/file';
|
||||
|
||||
describe('getExtensionFromContentDisposition', () => {
|
||||
it('should return the extracted the extension', () => {
|
||||
|
|
@ -44,4 +44,34 @@ describe('getExtensionFromContentDisposition', () => {
|
|||
expect(extension).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the path for the file', () => {
|
||||
const data = {
|
||||
id: generateId(),
|
||||
name: 'Some Video file.mp4',
|
||||
extension: 'mp4',
|
||||
};
|
||||
|
||||
const localFile = getLocalFilePathFromFile('Videos', {data});
|
||||
expect(localFile).toBe(`Videos/${data.id}.${data.extension}`);
|
||||
});
|
||||
|
||||
it('should return the null as the path if it does not have an id set', () => {
|
||||
const data = {
|
||||
name: 'Some Video file.mp4',
|
||||
extension: 'mp4',
|
||||
};
|
||||
|
||||
const localFile = getLocalFilePathFromFile('Videos', {data});
|
||||
expect(localFile).toBeNull();
|
||||
});
|
||||
|
||||
it('should return the null as the path if it does not have an extension set', () => {
|
||||
const data = {
|
||||
id: generateId(),
|
||||
name: 'Some Video file.mp4',
|
||||
};
|
||||
const localFile = getLocalFilePathFromFile('Videos', {data});
|
||||
expect(localFile).toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue