fileUtils.ts (ab55f125072c3b77549324c638fbca1fe4561337) fileUtils.ts (483fe5856044df91771f8cf65aeb02b7e2f61fad)
1import pathConst from '@/constants/pathConst';
2import FastImage from 'react-native-fast-image';
3import {
4 copyFile,
5 downloadFile,
6 exists,
7 mkdir,
8 PicturesDirectoryPath,
9 readDir,
10 unlink,
11 writeFile,
12} from 'react-native-fs';
13import {errorLog} from './log';
1import pathConst from '@/constants/pathConst';
2import FastImage from 'react-native-fast-image';
3import {
4 copyFile,
5 downloadFile,
6 exists,
7 mkdir,
8 PicturesDirectoryPath,
9 readDir,
10 unlink,
11 writeFile,
12} from 'react-native-fs';
13import {errorLog} from './log';
14import path from 'path-browserify';
14
15export const galleryBasePath = `${PicturesDirectoryPath}/MusicFree/`;
16
17export async function saveToGallery(src: string) {
18 const fileName = `${galleryBasePath}${Date.now()}.png`;
19 if (!(await exists(galleryBasePath))) {
20 await mkdir(galleryBasePath);
21 }

--- 113 unchanged lines hidden (view full) ---

135
136export function getDirectory(path: string) {
137 const lastSlash = path.lastIndexOf('/');
138 if (lastSlash === -1) {
139 return path;
140 }
141 return path.slice(0, lastSlash);
142}
15
16export const galleryBasePath = `${PicturesDirectoryPath}/MusicFree/`;
17
18export async function saveToGallery(src: string) {
19 const fileName = `${galleryBasePath}${Date.now()}.png`;
20 if (!(await exists(galleryBasePath))) {
21 await mkdir(galleryBasePath);
22 }

--- 113 unchanged lines hidden (view full) ---

136
137export function getDirectory(path: string) {
138 const lastSlash = path.lastIndexOf('/');
139 if (lastSlash === -1) {
140 return path;
141 }
142 return path.slice(0, lastSlash);
143}
144
145export async function mkdirR(directory: string) {
146 let folder = directory;
147 const checkStack = [];
148 while (folder.length > 15) {
149 checkStack.push(folder);
150 folder = path.dirname(folder);
151 }
152 let existPos = 0;
153 for (let i = 0; i < checkStack.length; ++i) {
154 const isExist = await exists(checkStack[i]);
155 if (isExist) {
156 existPos = i;
157 break;
158 }
159 }
160
161 for (let j = existPos - 1; j >= 0; --j) {
162 try {
163 await mkdir(checkStack[j]);
164 } catch (e) {
165 console.log('error', e);
166 }
167 }
168}