* updating react-native * swapping to new arch enabled image library * fixing store styling + padding issues * using legacy file system api for compatibility * fixed dimensions * fixing back handler on homepage * fixed non awaited promise * standardized seed language * updating firebase dependency versions * removing uneeded maven
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import {getLocalStorageItem, setLocalStorageItem} from './localStorage';
|
|
import {Platform} from 'react-native';
|
|
import customUUID from './customUUID';
|
|
import {getInfoAsync, makeDirectoryAsync} from 'expo-file-system/legacy';
|
|
|
|
export async function getOrCreateDirectory(uuidKey, workingDir) {
|
|
try {
|
|
let savedUUID = await getLocalStorageItem(uuidKey);
|
|
if (!savedUUID) {
|
|
savedUUID = customUUID();
|
|
await setLocalStorageItem(uuidKey, savedUUID);
|
|
}
|
|
|
|
const directoryPath = `${workingDir}/${savedUUID}`;
|
|
// On Android, we need the file:// prefix for the getInfoAsync check
|
|
const checkPath =
|
|
Platform.OS === 'android' ? `file://${directoryPath}` : directoryPath;
|
|
|
|
const dirInfo = await getInfoAsync(checkPath);
|
|
console.log('Directory Info:', dirInfo);
|
|
|
|
if (!dirInfo.exists) {
|
|
await makeDirectoryAsync(checkPath, {intermediates: true});
|
|
console.log(`Directory created: ${checkPath}`);
|
|
await new Promise(resolve => setTimeout(resolve, 8000)); //adds buffer
|
|
} else {
|
|
console.log(`Directory already exists: ${checkPath}`);
|
|
}
|
|
|
|
return directoryPath;
|
|
} catch (err) {
|
|
console.error('Error ensuring directory:', err);
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
export function unit8ArrayConverter(unitArray) {
|
|
return Array.from(
|
|
unitArray.filter(num => Number.isInteger(num) && num >= 0 && num <= 255),
|
|
);
|
|
}
|