Merge pull request #722 from ente-io/log-to-disk-for-electron
Log to disk for electron
This commit is contained in:
commit
68a2422476
|
@ -49,6 +49,7 @@ import {
|
||||||
} from 'utils/upload';
|
} from 'utils/upload';
|
||||||
import { getUserOwnedCollections } from 'utils/collection';
|
import { getUserOwnedCollections } from 'utils/collection';
|
||||||
import billingService from 'services/billingService';
|
import billingService from 'services/billingService';
|
||||||
|
import { addLogLine } from 'utils/logging';
|
||||||
|
|
||||||
const FIRST_ALBUM_NAME = 'My First Album';
|
const FIRST_ALBUM_NAME = 'My First Album';
|
||||||
|
|
||||||
|
@ -426,6 +427,7 @@ export default function Uploader(props: Props) {
|
||||||
|
|
||||||
const retryFailed = async () => {
|
const retryFailed = async () => {
|
||||||
try {
|
try {
|
||||||
|
addLogLine('user retrying failed upload');
|
||||||
const filesWithCollections =
|
const filesWithCollections =
|
||||||
await uploadManager.getFailedFilesWithCollections();
|
await uploadManager.getFailedFilesWithCollections();
|
||||||
await preUploadAction();
|
await preUploadAction();
|
||||||
|
|
|
@ -14,6 +14,12 @@ class ElectronService {
|
||||||
checkIsBundledApp() {
|
checkIsBundledApp() {
|
||||||
return isElectron() && this.isBundledApp;
|
return isElectron() && this.isBundledApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logToDisk(msg: string) {
|
||||||
|
if (this.electronAPIs?.logToDisk) {
|
||||||
|
this.electronAPIs?.logToDisk(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new ElectronService();
|
export default new ElectronService();
|
||||||
|
|
|
@ -141,8 +141,6 @@ class UploadManager {
|
||||||
this.metadataAndFileTypeInfoMap
|
this.metadataAndFileTypeInfoMap
|
||||||
);
|
);
|
||||||
|
|
||||||
addLogLine(`clusterLivePhotoFiles called`);
|
|
||||||
|
|
||||||
// filter out files whose metadata detection failed or those that have been skipped because the files are too large,
|
// filter out files whose metadata detection failed or those that have been skipped because the files are too large,
|
||||||
// as they will be rejected during upload and are not valid upload files which we need to clustering
|
// as they will be rejected during upload and are not valid upload files which we need to clustering
|
||||||
const rejectedFileLocalIDs = new Set(
|
const rejectedFileLocalIDs = new Set(
|
||||||
|
@ -167,11 +165,16 @@ class UploadManager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addLogLine(`clusterLivePhotoFiles started`);
|
||||||
|
|
||||||
const analysedMediaFiles =
|
const analysedMediaFiles =
|
||||||
UploadService.clusterLivePhotoFiles(filesWithMetadata);
|
UploadService.clusterLivePhotoFiles(filesWithMetadata);
|
||||||
|
|
||||||
|
addLogLine(`clusterLivePhotoFiles ended`);
|
||||||
const allFiles = [...rejectedFiles, ...analysedMediaFiles];
|
const allFiles = [...rejectedFiles, ...analysedMediaFiles];
|
||||||
|
addLogLine(
|
||||||
|
`got live photos: ${mediaFiles.length !== allFiles.length}`
|
||||||
|
);
|
||||||
uiService.setFilenames(
|
uiService.setFilenames(
|
||||||
new Map<number, string>(
|
new Map<number, string>(
|
||||||
allFiles.map((mediaFile) => [
|
allFiles.map((mediaFile) => [
|
||||||
|
@ -184,9 +187,6 @@ class UploadManager {
|
||||||
UIService.setHasLivePhoto(
|
UIService.setHasLivePhoto(
|
||||||
mediaFiles.length !== allFiles.length
|
mediaFiles.length !== allFiles.length
|
||||||
);
|
);
|
||||||
addLogLine(
|
|
||||||
`got live photos: ${mediaFiles.length !== allFiles.length}`
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.uploadMediaFiles(allFiles);
|
await this.uploadMediaFiles(allFiles);
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,6 @@ class UploadManager {
|
||||||
} else {
|
} else {
|
||||||
// and don't break for subsequent files just log and move on
|
// and don't break for subsequent files just log and move on
|
||||||
logError(e, 'parsing failed for a file');
|
logError(e, 'parsing failed for a file');
|
||||||
}
|
|
||||||
addLogLine(
|
addLogLine(
|
||||||
`failed to parse metadata json file ${getFileNameSize(
|
`failed to parse metadata json file ${getFileNameSize(
|
||||||
file
|
file
|
||||||
|
@ -269,6 +268,7 @@ class UploadManager {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.message !== CustomError.UPLOAD_CANCELLED) {
|
if (e.message !== CustomError.UPLOAD_CANCELLED) {
|
||||||
logError(e, 'error seeding MetadataMap');
|
logError(e, 'error seeding MetadataMap');
|
||||||
|
@ -311,13 +311,13 @@ class UploadManager {
|
||||||
} else {
|
} else {
|
||||||
// and don't break for subsequent files just log and move on
|
// and don't break for subsequent files just log and move on
|
||||||
logError(e, 'extractFileTypeAndMetadata failed');
|
logError(e, 'extractFileTypeAndMetadata failed');
|
||||||
}
|
|
||||||
addLogLine(
|
addLogLine(
|
||||||
`metadata extraction failed ${getFileNameSize(
|
`metadata extraction failed ${getFileNameSize(
|
||||||
file
|
file
|
||||||
)} error: ${e.message}`
|
)} error: ${e.message}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.metadataAndFileTypeInfoMap.set(localID, {
|
this.metadataAndFileTypeInfoMap.set(localID, {
|
||||||
fileTypeInfo: fileTypeInfo && { ...fileTypeInfo },
|
fileTypeInfo: fileTypeInfo && { ...fileTypeInfo },
|
||||||
metadata: metadata && { ...metadata },
|
metadata: metadata && { ...metadata },
|
||||||
|
@ -509,6 +509,7 @@ class UploadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public cancelRunningUpload() {
|
public cancelRunningUpload() {
|
||||||
|
addLogLine('user cancelled running upload');
|
||||||
UIService.setUploadStage(UPLOAD_STAGES.CANCELLING);
|
UIService.setUploadStage(UPLOAD_STAGES.CANCELLING);
|
||||||
uploadCancelService.requestUploadCancelation();
|
uploadCancelService.requestUploadCancelation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,6 @@ export default async function uploader(
|
||||||
backupedFile,
|
backupedFile,
|
||||||
encryptedFile.fileKey
|
encryptedFile.fileKey
|
||||||
);
|
);
|
||||||
addLogLine(`uploadFile ${fileNameSize}`);
|
|
||||||
|
|
||||||
const uploadedFile = await UploadHttpClient.uploadFile(uploadFile);
|
const uploadedFile = await UploadHttpClient.uploadFile(uploadFile);
|
||||||
|
|
||||||
|
|
|
@ -62,4 +62,5 @@ export interface ElectronAPIs {
|
||||||
getEncryptionKey: () => Promise<string>;
|
getEncryptionKey: () => Promise<string>;
|
||||||
openDiskCache: (cacheName: string) => Promise<Cache>;
|
openDiskCache: (cacheName: string) => Promise<Cache>;
|
||||||
deleteDiskCache: (cacheName: string) => Promise<boolean>;
|
deleteDiskCache: (cacheName: string) => Promise<boolean>;
|
||||||
|
logToDisk: (msg: string) => void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ import { convertBytesToHumanReadable } from 'utils/file/size';
|
||||||
import { formatDateTime } from 'utils/time';
|
import { formatDateTime } from 'utils/time';
|
||||||
import { saveLogLine, getLogs } from 'utils/storage';
|
import { saveLogLine, getLogs } from 'utils/storage';
|
||||||
import { isDEVSentryENV } from 'constants/sentry';
|
import { isDEVSentryENV } from 'constants/sentry';
|
||||||
|
import isElectron from 'is-electron';
|
||||||
|
import ElectronService from 'services/electron/common';
|
||||||
|
|
||||||
export function addLogLine(log: string) {
|
export function addLogLine(log: string) {
|
||||||
if (isDEVSentryENV()) {
|
if (isDEVSentryENV()) {
|
||||||
|
@ -12,6 +14,9 @@ export function addLogLine(log: string) {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
logLine: log,
|
logLine: log,
|
||||||
});
|
});
|
||||||
|
if (isElectron()) {
|
||||||
|
ElectronService.logToDisk(log);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addLocalLog = (getLog: () => string) => {
|
export const addLocalLog = (getLog: () => string) => {
|
||||||
|
|
Loading…
Reference in a new issue