Merge branch 'add-electron-types' into watch
This commit is contained in:
commit
7f11029bd3
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -1,4 +1,4 @@
|
|||
[submodule "bada-frame"]
|
||||
path = ui
|
||||
url = https://github.com/ente-io/bada-frame
|
||||
branch = main
|
||||
branch = add-electron-types
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { ipcRenderer } from 'electron/renderer';
|
||||
import { logError } from '../utils/logging';
|
||||
|
||||
export const selectRootDirectory = async () => {
|
||||
export const selectRootDirectory = async (): Promise<string> => {
|
||||
try {
|
||||
return await ipcRenderer.invoke('select-dir');
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,21 +1,14 @@
|
|||
import {
|
||||
createDirectory,
|
||||
doesPathExists,
|
||||
readTextFile,
|
||||
renameDirectory,
|
||||
writeFile,
|
||||
writeStream,
|
||||
} from './../services/fs';
|
||||
import { readTextFile, writeStream } from './../services/fs';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import { logError } from '../utils/logging';
|
||||
import * as fs from 'promise-fs';
|
||||
|
||||
export const exists = (path: string) => {
|
||||
return doesPathExists(path);
|
||||
return fs.existsSync(path);
|
||||
};
|
||||
|
||||
export const checkExistsAndCreateCollectionDir = async (dirPath: string) => {
|
||||
if (!doesPathExists(dirPath)) {
|
||||
await createDirectory(dirPath);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
await fs.mkdir(dirPath);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -23,8 +16,8 @@ export const checkExistsAndRename = async (
|
|||
oldDirPath: string,
|
||||
newDirPath: string
|
||||
) => {
|
||||
if (doesPathExists(oldDirPath)) {
|
||||
await renameDirectory(oldDirPath, newDirPath);
|
||||
if (fs.existsSync(oldDirPath)) {
|
||||
await fs.rename(oldDirPath, newDirPath);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -36,24 +29,19 @@ export const saveStreamToDisk = (
|
|||
};
|
||||
|
||||
export const saveFileToDisk = async (path: string, fileData: any) => {
|
||||
await writeFile(path, fileData);
|
||||
await fs.writeFile(path, fileData);
|
||||
};
|
||||
|
||||
export const getExportRecord = async (filePath: string) => {
|
||||
try {
|
||||
if (!(await doesPathExists(filePath))) {
|
||||
return null;
|
||||
}
|
||||
const recordFile = await readTextFile(filePath);
|
||||
return recordFile;
|
||||
} catch (e) {
|
||||
// ignore exportFile missing
|
||||
logError(e, 'error while selecting files');
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return null;
|
||||
}
|
||||
const recordFile = await readTextFile(filePath);
|
||||
return recordFile;
|
||||
};
|
||||
|
||||
export const setExportRecord = async (filePath: string, data: string) => {
|
||||
await writeFile(filePath, data);
|
||||
await fs.writeFile(filePath, data);
|
||||
};
|
||||
|
||||
export const registerResumeExportListener = (resumeExport: () => void) => {
|
||||
|
|
|
@ -16,7 +16,7 @@ export async function setEncryptionKey(encryptionKey: string) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getEncryptionKey() {
|
||||
export async function getEncryptionKey(): Promise<string> {
|
||||
try {
|
||||
const b64EncryptedKey = safeStorageStore.get('encryptionKey');
|
||||
if (b64EncryptedKey) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import path from 'path';
|
|||
import StreamZip from 'node-stream-zip';
|
||||
import { uploadStatusStore } from '../stores/upload.store';
|
||||
import { ElectronFile, FILE_PATH_KEYS, FILE_PATH_TYPE } from '../types';
|
||||
import { logError } from '../utils/logging';
|
||||
import { ipcRenderer } from 'electron';
|
||||
|
||||
async function getZipEntryAsElectronFile(
|
||||
|
@ -90,48 +89,36 @@ export const getElectronFilesFromGoogleZip = async (filePath: string) => {
|
|||
return files;
|
||||
};
|
||||
|
||||
export const showUploadDirsDialog = async () => {
|
||||
try {
|
||||
const filePaths: string[] = await ipcRenderer.invoke(
|
||||
'show-upload-dirs-dialog'
|
||||
);
|
||||
const files = await Promise.all(filePaths.map(getElectronFile));
|
||||
return files;
|
||||
} catch (e) {
|
||||
logError(e, 'error while selecting folders');
|
||||
}
|
||||
export const showUploadFilesDialog = async () => {
|
||||
const filePaths: string[] = await ipcRenderer.invoke(
|
||||
'show-upload-files-dialog'
|
||||
);
|
||||
const files = await Promise.all(filePaths.map(getElectronFile));
|
||||
return files;
|
||||
};
|
||||
|
||||
export const showUploadFilesDialog = async () => {
|
||||
try {
|
||||
const filePaths: string[] = await ipcRenderer.invoke(
|
||||
'show-upload-files-dialog'
|
||||
);
|
||||
const files = await Promise.all(filePaths.map(getElectronFile));
|
||||
return files;
|
||||
} catch (e) {
|
||||
logError(e, 'error while selecting files');
|
||||
}
|
||||
export const showUploadDirsDialog = async () => {
|
||||
const filePaths: string[] = await ipcRenderer.invoke(
|
||||
'show-upload-dirs-dialog'
|
||||
);
|
||||
const files = await Promise.all(filePaths.map(getElectronFile));
|
||||
return files;
|
||||
};
|
||||
|
||||
export const showUploadZipDialog = async () => {
|
||||
try {
|
||||
const filePaths: string[] = await ipcRenderer.invoke(
|
||||
'show-upload-zip-dialog'
|
||||
);
|
||||
const files: ElectronFile[] = [];
|
||||
const filePaths: string[] = await ipcRenderer.invoke(
|
||||
'show-upload-zip-dialog'
|
||||
);
|
||||
|
||||
for (const filePath of filePaths) {
|
||||
files.push(...(await getElectronFilesFromGoogleZip(filePath)));
|
||||
}
|
||||
|
||||
return {
|
||||
zipPaths: filePaths,
|
||||
files,
|
||||
};
|
||||
} catch (e) {
|
||||
logError(e, 'error while selecting zips');
|
||||
const files: ElectronFile[] = [];
|
||||
for (const filePath of filePaths) {
|
||||
files.push(...(await getElectronFilesFromGoogleZip(filePath)));
|
||||
}
|
||||
|
||||
return {
|
||||
zipPaths: filePaths,
|
||||
files,
|
||||
};
|
||||
};
|
||||
|
||||
const getSavedPaths = (type: FILE_PATH_TYPE) => {
|
||||
|
|
|
@ -30,7 +30,6 @@ export const getFileStream = async (filePath: string) => {
|
|||
async pull(controller) {
|
||||
try {
|
||||
const buff = new Uint8Array(FILE_STREAM_CHUNK_SIZE);
|
||||
|
||||
// original types were not working correctly
|
||||
const bytesRead = (await fs.read(
|
||||
file,
|
||||
|
@ -161,15 +160,6 @@ export async function doesFolderExists(dirPath: string) {
|
|||
.catch(() => false);
|
||||
}
|
||||
|
||||
export async function doesPathExists(dirPath: string) {
|
||||
return await fs
|
||||
.stat(dirPath)
|
||||
.then((stats: fs.Stats) => {
|
||||
return stats.isFile() || stats.isDirectory();
|
||||
})
|
||||
.catch(() => false);
|
||||
}
|
||||
|
||||
export const convertBrowserStreamToNode = (fileStream: any) => {
|
||||
const reader = fileStream.getReader();
|
||||
const rs = new Readable();
|
||||
|
@ -188,19 +178,7 @@ export const convertBrowserStreamToNode = (fileStream: any) => {
|
|||
return rs;
|
||||
};
|
||||
|
||||
export async function createDirectory(dirPath: string) {
|
||||
await fs.mkdir(dirPath);
|
||||
}
|
||||
|
||||
export async function renameDirectory(oldDirPath: string, newDirPath: string) {
|
||||
await fs.rename(oldDirPath, newDirPath);
|
||||
}
|
||||
|
||||
export async function writeFile(filePath: string, fileData: any) {
|
||||
await fs.writeFile(filePath, fileData);
|
||||
}
|
||||
|
||||
export function writeStream(filePath: string, fileStream: any) {
|
||||
export function writeStream(filePath: string, fileStream: ReadableStream<any>) {
|
||||
const writeable = fs.createWriteStream(filePath);
|
||||
const readable = convertBrowserStreamToNode(fileStream);
|
||||
readable.pipe(writeable);
|
||||
|
|
Loading…
Reference in a new issue