Set the file prefix in image_cache_manager (#2313)
This commit is contained in:
parent
76ed62b153
commit
1787a04f6e
9 changed files with 17 additions and 69 deletions
|
|
@ -82,14 +82,8 @@ export default class Emoji extends React.PureComponent {
|
|||
}
|
||||
|
||||
setImageUrl = (imageUrl) => {
|
||||
let prefix = '';
|
||||
if (Platform.OS === 'android') {
|
||||
prefix = 'file://';
|
||||
}
|
||||
|
||||
const uri = `${prefix}${imageUrl}`;
|
||||
this.setState({
|
||||
imageUrl: uri,
|
||||
imageUrl,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import React, {Component} from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import {
|
||||
Keyboard,
|
||||
Platform,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
TouchableOpacity,
|
||||
|
|
@ -101,12 +100,7 @@ export default class FileAttachmentList extends Component {
|
|||
}
|
||||
|
||||
if (cache) {
|
||||
let path = cache.path;
|
||||
if (Platform.OS === 'android') {
|
||||
path = `file://${path}`;
|
||||
}
|
||||
|
||||
uri = path;
|
||||
uri = cache.path;
|
||||
}
|
||||
|
||||
results.push({
|
||||
|
|
|
|||
|
|
@ -187,11 +187,7 @@ export default class MarkdownImage extends React.Component {
|
|||
};
|
||||
|
||||
setImageUrl = (imageURL) => {
|
||||
let uri = imageURL;
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
uri = `file://${imageURL}`;
|
||||
}
|
||||
const uri = imageURL;
|
||||
|
||||
this.setState({uri});
|
||||
this.loadImageSize(uri);
|
||||
|
|
|
|||
|
|
@ -267,13 +267,7 @@ export default class MessageAttachment extends PureComponent {
|
|||
}
|
||||
};
|
||||
|
||||
setImageUrl = (imageURL) => {
|
||||
let imageUri = imageURL;
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
imageUri = `file://${imageURL}`;
|
||||
}
|
||||
|
||||
setImageUrl = (imageUri) => {
|
||||
Image.getSize(imageUri, (width, height) => {
|
||||
const dimensions = calculateDimensions(height, width, this.maxImageWidth);
|
||||
if (this.mounted) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import PropTypes from 'prop-types';
|
|||
import {
|
||||
Image,
|
||||
Linking,
|
||||
Platform,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
TouchableWithoutFeedback,
|
||||
|
|
@ -112,14 +111,7 @@ export default class PostAttachmentOpenGraph extends PureComponent {
|
|||
};
|
||||
|
||||
getImageSize = (imageUrl) => {
|
||||
let prefix = '';
|
||||
if (Platform.OS === 'android') {
|
||||
prefix = 'file://';
|
||||
}
|
||||
|
||||
const uri = `${prefix}${imageUrl}`;
|
||||
|
||||
Image.getSize(uri, (width, height) => {
|
||||
Image.getSize(imageUrl, (width, height) => {
|
||||
const dimensions = calculateDimensions(height, width, this.getViewPostWidth());
|
||||
|
||||
if (this.mounted) {
|
||||
|
|
@ -127,7 +119,7 @@ export default class PostAttachmentOpenGraph extends PureComponent {
|
|||
...dimensions,
|
||||
originalHeight: height,
|
||||
originalWidth: width,
|
||||
imageUrl: uri,
|
||||
imageUrl,
|
||||
});
|
||||
}
|
||||
}, () => null);
|
||||
|
|
|
|||
|
|
@ -254,13 +254,7 @@ export default class PostBodyAdditionalContent extends PureComponent {
|
|||
const viewPortWidth = deviceSize - VIEWPORT_IMAGE_OFFSET - (isReplyPost ? VIEWPORT_IMAGE_REPLY_OFFSET : 0);
|
||||
|
||||
if (link && path) {
|
||||
let prefix = '';
|
||||
if (Platform.OS === 'android') {
|
||||
prefix = 'file://';
|
||||
}
|
||||
|
||||
const uri = `${prefix}${path}`;
|
||||
Image.getSize(uri, (width, height) => {
|
||||
Image.getSize(path, (width, height) => {
|
||||
if (!this.mounted) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -282,7 +276,7 @@ export default class PostBodyAdditionalContent extends PureComponent {
|
|||
originalHeight: height,
|
||||
originalWidth: width,
|
||||
linkLoaded: true,
|
||||
uri,
|
||||
uri: path,
|
||||
});
|
||||
}, () => this.setState({linkLoadError: true}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,26 +81,14 @@ export default class ProgressiveImage extends PureComponent {
|
|||
|
||||
setImage = (uri) => {
|
||||
if (this.subscribedToCache) {
|
||||
let path = uri;
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
path = `file://${uri}`;
|
||||
}
|
||||
|
||||
this.setState({uri: path});
|
||||
this.setState({uri});
|
||||
}
|
||||
};
|
||||
|
||||
setThumbnail = (thumb) => {
|
||||
if (this.subscribedToCache) {
|
||||
const {filename, imageUri} = this.props;
|
||||
let path = thumb;
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
path = `file://${thumb}`;
|
||||
}
|
||||
|
||||
this.setState({thumb: path}, () => {
|
||||
this.setState({thumb}, () => {
|
||||
setTimeout(() => {
|
||||
ImageCacheManager.cache(filename, imageUri, this.setImage);
|
||||
}, 300);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import PropTypes from 'prop-types';
|
|||
|
||||
import {
|
||||
Image,
|
||||
Platform,
|
||||
Text,
|
||||
View,
|
||||
} from 'react-native';
|
||||
|
|
@ -50,12 +49,7 @@ export default class TeamIcon extends React.PureComponent {
|
|||
}
|
||||
|
||||
setImageURL = (teamIcon) => {
|
||||
let prefix = '';
|
||||
if (Platform.OS === 'android') {
|
||||
prefix = 'file://';
|
||||
}
|
||||
|
||||
this.setState({teamIcon: `${prefix}${teamIcon}`});
|
||||
this.setState({teamIcon});
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
// Based on the work done by https://github.com/wcandillon/react-native-expo-image-cache/
|
||||
|
||||
import {Platform} from 'react-native';
|
||||
import RNFetchBlob from 'rn-fetch-blob';
|
||||
|
||||
import {DeviceTypes} from 'app/constants';
|
||||
|
|
@ -21,10 +22,11 @@ export default class ImageCacheManager {
|
|||
}
|
||||
|
||||
const {path, exists} = await getCacheFile(filename, uri);
|
||||
const prefix = Platform.OS === 'android' ? 'file://' : '';
|
||||
if (isDownloading(uri)) {
|
||||
addListener(uri, listener);
|
||||
} else if (exists) {
|
||||
listener(path);
|
||||
listener(`${prefix}${path}`);
|
||||
} else {
|
||||
addListener(uri, listener);
|
||||
if (uri.startsWith('http')) {
|
||||
|
|
@ -44,9 +46,9 @@ export default class ImageCacheManager {
|
|||
throw new Error();
|
||||
}
|
||||
|
||||
notifyAll(uri, path);
|
||||
notifyAll(uri, `${prefix}${path}`);
|
||||
} catch (e) {
|
||||
RNFetchBlob.fs.unlink(path);
|
||||
RNFetchBlob.fs.unlink(`${prefix}${path}`);
|
||||
notifyAll(uri, uri);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -62,7 +64,7 @@ export default class ImageCacheManager {
|
|||
export const getCacheFile = async (name, uri) => {
|
||||
const filename = name || uri.substring(uri.lastIndexOf('/'), uri.indexOf('?') === -1 ? uri.length : uri.indexOf('?'));
|
||||
const ext = filename.indexOf('.') === -1 ? '.png' : filename.substring(filename.lastIndexOf('.'));
|
||||
const path = `${IMAGES_PATH}/${hashCode(uri)}${ext}`;
|
||||
const path = `${IMAGES_PATH}/${Math.abs(hashCode(uri))}${ext}`;
|
||||
|
||||
try {
|
||||
const isDir = await RNFetchBlob.fs.isDir(IMAGES_PATH);
|
||||
|
|
|
|||
Loading…
Reference in a new issue