mirror of
https://github.com/balzack/databag.git
synced 2025-04-20 16:45:25 +00:00
Merge branch 'main' into fdroid
This commit is contained in:
commit
b28aa9edb7
@ -26,6 +26,17 @@ export function AudioAsset({ asset, dismiss }) {
|
||||
<Icons name="play-circle-outline" size={92} color={Colors.text} />
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
{ state.showDownloaded && (
|
||||
<View style={styles.downloaded}>
|
||||
<MatIcons name="folder-download-outline" size={22} color={Colors.white} />
|
||||
{ Platform.OS === 'ios' && (
|
||||
<Text style={styles.downloadedLabel}>Documents</Text>
|
||||
)}
|
||||
{ Platform.OS !== 'ios' && (
|
||||
<Text style={styles.downloadedLabel}>Download</Text>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
{ state.playing && state.loaded && (
|
||||
<TouchableOpacity style={styles.control} onPress={actions.pause}>
|
||||
<Icons name="pause-circle-outline" size={92} color={Colors.text} />
|
||||
@ -33,7 +44,12 @@ export function AudioAsset({ asset, dismiss }) {
|
||||
)}
|
||||
{ state.url && (
|
||||
<TouchableOpacity style={styles.share} onPress={actions.download}>
|
||||
<MatIcons name="share-variant-outline" size={32} color={Colors.text} />
|
||||
{ state.downloaded && (
|
||||
<MatIcons name="download-outline" size={32} color={Colors.white} />
|
||||
)}
|
||||
{ !state.downloaded && (
|
||||
<MatIcons name="download" size={32} color={Colors.white} />
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
<TouchableOpacity style={styles.close} onPress={dismiss}>
|
||||
|
@ -59,5 +59,23 @@ export const styles = StyleSheet.create({
|
||||
fontSize: 12,
|
||||
color: '#888888',
|
||||
},
|
||||
downloaded: {
|
||||
top: 0,
|
||||
position: 'absolute',
|
||||
marginTop: 8,
|
||||
display: 'flex',
|
||||
backgroundColor: Colors.grey,
|
||||
borderRadius: 4,
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
paddingLeft: 8,
|
||||
paddingRight: 8,
|
||||
paddingTop: 2,
|
||||
paddingBottom: 2,
|
||||
},
|
||||
downloadedLabel: {
|
||||
color: Colors.white,
|
||||
paddingLeft: 8,
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { useState, useRef, useEffect, useContext } from 'react';
|
||||
import { ConversationContext } from 'context/ConversationContext';
|
||||
import { Image } from 'react-native';
|
||||
import { useWindowDimensions } from 'react-native';
|
||||
import Share from 'react-native-share';
|
||||
import RNFS from "react-native-fs";
|
||||
|
||||
export function useAudioAsset(asset) {
|
||||
|
||||
@ -12,6 +12,8 @@ export function useAudioAsset(asset) {
|
||||
url: null,
|
||||
playing: false,
|
||||
loaded: false,
|
||||
downloaded: false,
|
||||
showDownloaded: false,
|
||||
});
|
||||
|
||||
const closing = useRef(null);
|
||||
@ -48,8 +50,21 @@ export function useAudioAsset(asset) {
|
||||
}, [asset]);
|
||||
|
||||
const actions = {
|
||||
download: () => {
|
||||
Share.open({ url: state.url });
|
||||
download: async () => {
|
||||
if (!state.downloaded) {
|
||||
updateState({ downloaded: true });
|
||||
const epoch = Math.ceil(Date.now() / 1000);
|
||||
const dir = Platform.OS === 'ios' ? RNFS.DocumentDirectoryPath : RNFS.DownloadDirectoryPath;
|
||||
const path = `${dir}/databag_${epoch}.mp3`
|
||||
if (state.url.substring(0, 7) === 'file://') {
|
||||
await RNFS.copyFile(state.url.substring(7).split('?')[0], path);
|
||||
}
|
||||
else {
|
||||
await RNFS.downloadFile({ fromUrl: state.url, toFile: path }).promise;
|
||||
}
|
||||
updateState({ showDownloaded: true });
|
||||
setTimeout(() => { updateState({ showDownloaded: false }) }, 2000);
|
||||
}
|
||||
},
|
||||
play: () => {
|
||||
updateState({ playing: true });
|
||||
|
@ -19,12 +19,19 @@ export function ImageAsset({ asset, dismiss }) {
|
||||
style={{ ...styles.main, width: state.imageWidth, height: state.imageHeight }}
|
||||
resizeMode={FastImage.resizeMode.contain} />
|
||||
)}
|
||||
{ state.loaded && state.controls && Platform.OS === 'ios' && (
|
||||
<TouchableOpacity style={styles.share} onPress={actions.share}>
|
||||
<MatIcons name="share-variant-outline" size={32} color={Colors.white} />
|
||||
</TouchableOpacity>
|
||||
{ state.showDownloaded && (
|
||||
<View style={styles.downloaded}>
|
||||
<MatIcons name="folder-download-outline" size={22} color={Colors.white} />
|
||||
{ Platform.OS === 'ios' && (
|
||||
<Text style={styles.downloadedLabel}>Documents</Text>
|
||||
)}
|
||||
{ Platform.OS !== 'ios' && (
|
||||
<Text style={styles.downloadedLabel}>Download</Text>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
{ state.loaded && state.controls && Platform.OS !== 'ios' && (
|
||||
|
||||
{ state.loaded && state.controls && (
|
||||
<TouchableOpacity style={styles.share} onPress={actions.download}>
|
||||
{ state.downloaded && (
|
||||
<MatIcons name="download-outline" size={32} color={Colors.white} />
|
||||
|
@ -60,6 +60,24 @@ export const styles = StyleSheet.create({
|
||||
padding: 4,
|
||||
borderRadius: 4,
|
||||
backgroundColor: Colors.grey,
|
||||
}
|
||||
},
|
||||
downloaded: {
|
||||
top: 0,
|
||||
position: 'absolute',
|
||||
marginTop: 8,
|
||||
display: 'flex',
|
||||
backgroundColor: Colors.grey,
|
||||
borderRadius: 4,
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
paddingLeft: 8,
|
||||
paddingRight: 8,
|
||||
paddingTop: 2,
|
||||
paddingBottom: 2,
|
||||
},
|
||||
downloadedLabel: {
|
||||
color: Colors.white,
|
||||
paddingLeft: 8,
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -2,8 +2,6 @@ import { useState, useRef, useEffect, useContext } from 'react';
|
||||
import { ConversationContext } from 'context/ConversationContext';
|
||||
import { Image, Platform } from 'react-native';
|
||||
import { useWindowDimensions } from 'react-native';
|
||||
import Share from 'react-native-share';
|
||||
import RNFetchBlob from "rn-fetch-blob";
|
||||
import RNFS from "react-native-fs";
|
||||
|
||||
export function useImageAsset(asset) {
|
||||
@ -19,6 +17,7 @@ export function useImageAsset(asset) {
|
||||
failed: false,
|
||||
controls: false,
|
||||
downloaded: false,
|
||||
showDownloaded: false,
|
||||
});
|
||||
|
||||
const conversation = useContext(ConversationContext);
|
||||
@ -71,25 +70,41 @@ export function useImageAsset(asset) {
|
||||
const { width, height } = e.nativeEvent;
|
||||
updateState({ imageRatio: width / height });
|
||||
},
|
||||
share: () => {
|
||||
Share.open({ url: state.url })
|
||||
},
|
||||
download: async () => {
|
||||
if (!state.downloaded) {
|
||||
updateState({ downloaded: true });
|
||||
const epoch = Math.ceil(Date.now() / 1000);
|
||||
const dir = Platform.OS === 'ios' ? RNFetchBlob.fs.dirs.DocumentDir : RNFetchBlob.fs.dirs.PictureDir;
|
||||
const path = `${dir}/databag_${epoch}.jpg`
|
||||
const dir = Platform.OS === 'ios' ? RNFS.DocumentDirectoryPath : RNFS.DownloadDirectoryPath;
|
||||
const path = `${dir}/databag_${epoch}`
|
||||
if (state.url.substring(0, 7) === 'file://') {
|
||||
await RNFS.copyFile(state.url.substring(7).split('?')[0], path);
|
||||
}
|
||||
else {
|
||||
const res = await RNFetchBlob.config({path: path}).fetch("GET", state.url, {});
|
||||
await RNFS.downloadFile({ fromUrl: state.url, toFile: path }).promise;
|
||||
}
|
||||
let ext = 'dat';
|
||||
const block = await RNFS.read(path, 8, 0, 'base64');
|
||||
if (block === '/9j/4AAQSkY=') {
|
||||
await RNFS.scanFile(jpg);
|
||||
ext = 'jpg';
|
||||
}
|
||||
if (block === 'iVBORw0KGgo=') {
|
||||
ext = 'png';
|
||||
}
|
||||
if (block === 'UklGRphXAQA=') {
|
||||
ext = 'webp';
|
||||
}
|
||||
if (block === 'R0lGODlhIAM=') {
|
||||
ext = 'gif';
|
||||
}
|
||||
else if (block.startsWith('Qk')) {
|
||||
ext = 'bmp';
|
||||
}
|
||||
await RNFS.moveFile(path, `${path}.${ext}`);
|
||||
if (Platform.OS !== 'ios') {
|
||||
await RNFS.scanFile(`${path}.${ext}`);
|
||||
}
|
||||
updateState({ showDownloaded: true });
|
||||
setTimeout(() => { updateState({ showDownloaded: false }) }, 2000);
|
||||
}
|
||||
},
|
||||
loaded: () => {
|
||||
|
@ -27,6 +27,17 @@ export function VideoAsset({ asset, dismiss }) {
|
||||
{ (!state.playing || state.controls) && (
|
||||
<View style={styles.overlay} />
|
||||
)}
|
||||
{ state.showDownloaded && (
|
||||
<View style={styles.downloaded}>
|
||||
<MatIcons name="folder-download-outline" size={22} color={Colors.white} />
|
||||
{ Platform.OS === 'ios' && (
|
||||
<Text style={styles.downloadedLabel}>Documents</Text>
|
||||
)}
|
||||
{ Platform.OS !== 'ios' && (
|
||||
<Text style={styles.downloadedLabel}>Download</Text>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
{ !state.playing && state.videoLoaded && (
|
||||
<TouchableOpacity style={styles.control} onPress={actions.play}>
|
||||
<Icons name="play-circle-outline" size={92} color={Colors.white} />
|
||||
@ -39,7 +50,12 @@ export function VideoAsset({ asset, dismiss }) {
|
||||
)}
|
||||
{ (state.controls || !state.playing) && state.videoLoaded && (
|
||||
<TouchableOpacity style={styles.share} onPress={actions.download}>
|
||||
<MatIcons name="share-variant-outline" size={32} color={Colors.white} />
|
||||
{ state.downloaded && (
|
||||
<MatIcons name="download-outline" size={32} color={Colors.white} />
|
||||
)}
|
||||
{ !state.downloaded && (
|
||||
<MatIcons name="download" size={32} color={Colors.white} />
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
{ (state.controls || !state.playing) && state.videoLoaded && (
|
||||
|
@ -67,5 +67,23 @@ export const styles = StyleSheet.create({
|
||||
fontSize: 12,
|
||||
color: '#dddddd',
|
||||
},
|
||||
downloaded: {
|
||||
top: 0,
|
||||
position: 'absolute',
|
||||
marginTop: 8,
|
||||
display: 'flex',
|
||||
backgroundColor: Colors.grey,
|
||||
borderRadius: 4,
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
paddingLeft: 8,
|
||||
paddingRight: 8,
|
||||
paddingTop: 2,
|
||||
paddingBottom: 2,
|
||||
},
|
||||
downloadedLabel: {
|
||||
color: Colors.white,
|
||||
paddingLeft: 8,
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { useState, useRef, useEffect, useContext } from 'react';
|
||||
import { ConversationContext } from 'context/ConversationContext';
|
||||
import { Image } from 'react-native';
|
||||
import { useWindowDimensions } from 'react-native';
|
||||
import Share from 'react-native-share';
|
||||
import RNFS from "react-native-fs";
|
||||
|
||||
export function useVideoAsset(asset) {
|
||||
|
||||
@ -20,6 +20,7 @@ export function useVideoAsset(asset) {
|
||||
thumbLoaded: false,
|
||||
videoLoaded: false,
|
||||
controls: false,
|
||||
downloaded: false,
|
||||
});
|
||||
|
||||
const controls = useRef(null);
|
||||
@ -72,8 +73,24 @@ export function useVideoAsset(asset) {
|
||||
}, [asset]);
|
||||
|
||||
const actions = {
|
||||
download: () => {
|
||||
Share.open({ url: state.url });
|
||||
download: async () => {
|
||||
if (!state.downloaded) {
|
||||
updateState({ downloaded: true });
|
||||
const epoch = Math.ceil(Date.now() / 1000);
|
||||
const dir = Platform.OS === 'ios' ? RNFS.DocumentDirectoryPath : RNFS.DownloadDirectoryPath;
|
||||
const path = `${dir}/databag_${epoch}.mp4`
|
||||
if (state.url.substring(0, 7) === 'file://') {
|
||||
await RNFS.copyFile(state.url.substring(7).split('?')[0], path);
|
||||
}
|
||||
else {
|
||||
await RNFS.downloadFile({ fromUrl: state.url, toFile: path }).promise;
|
||||
}
|
||||
if (Platform.OS !== 'ios') {
|
||||
await RNFS.scanFile(`${path}`);
|
||||
}
|
||||
updateState({ showDownloaded: true });
|
||||
setTimeout(() => { updateState({ showDownloaded: false }) }, 2000);
|
||||
}
|
||||
},
|
||||
setThumbSize: (e) => {
|
||||
const { width, height } = e.nativeEvent || {};
|
||||
|
@ -83,6 +83,7 @@ func AddAccount(w http.ResponseWriter, r *http.Request) {
|
||||
// create new account
|
||||
account := store.Account{
|
||||
Username: username,
|
||||
Searchable: true,
|
||||
Handle: strings.ToLower(username),
|
||||
Password: password,
|
||||
GUID: fingerprint,
|
||||
|
@ -659,6 +659,13 @@ func addTestAccount(username string) (guid string, token string, err error) {
|
||||
}
|
||||
token = access.AppToken
|
||||
|
||||
// set to searchable
|
||||
searchable := false
|
||||
if r, w, err = NewRequest("PUT", "/account/searchable?agent="+token, &searchable); err != nil {
|
||||
return
|
||||
}
|
||||
SetAccountSearchable(w, r);
|
||||
|
||||
// authorize claim
|
||||
if r, w, err = NewRequest("PUT", "/authorize?agent="+token, "1234abcd"); err != nil {
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user