Merge branch 'uncategorised' of https://github.com/ente-io/photos-web into uncategorised

This commit is contained in:
Ananddubey01 2023-02-03 10:23:42 +05:30
commit 46b946f159
9 changed files with 83 additions and 75 deletions

View file

@ -276,6 +276,7 @@ const PhotoFrame = ({
}; };
document.addEventListener('keydown', handleKeyDown, false); document.addEventListener('keydown', handleKeyDown, false);
document.addEventListener('keyup', handleKeyUp, false); document.addEventListener('keyup', handleKeyUp, false);
router.events.on('hashChangeComplete', (url: string) => { router.events.on('hashChangeComplete', (url: string) => {
const start = url.indexOf('#'); const start = url.indexOf('#');
const hash = url.slice(start !== -1 ? start : url.length); const hash = url.slice(start !== -1 ? start : url.length);
@ -288,9 +289,10 @@ const PhotoFrame = ({
setOpen(false); setOpen(false);
} }
}); });
return () => { return () => {
document.addEventListener('keydown', handleKeyDown, false); document.removeEventListener('keydown', handleKeyDown, false);
document.addEventListener('keyup', handleKeyUp, false); document.removeEventListener('keyup', handleKeyUp, false);
}; };
}, []); }, []);

View file

@ -533,7 +533,7 @@ export default function Uploader(props: Props) {
} }
}; };
function showUserFacingError(err: CustomError) { function showUserFacingError(err: string) {
let notification: NotificationAttributes; let notification: NotificationAttributes;
switch (err) { switch (err) {
case CustomError.SESSION_EXPIRED: case CustomError.SESSION_EXPIRED:

View file

@ -15,6 +15,8 @@ export const FILE_TYPE_LIB_MISSED_FORMATS = [
{ fileType: FILE_TYPE.VIDEO, exactType: 'mp4', mimeType: 'video/mp4' }, { fileType: FILE_TYPE.VIDEO, exactType: 'mp4', mimeType: 'video/mp4' },
]; ];
export const KNOWN_NON_MEDIA_FORMATS = ['xmp'];
export const EXIFLESS_FORMATS = ['image/gif']; export const EXIFLESS_FORMATS = ['image/gif'];
export const EXIF_LIBRARY_UNSUPPORTED_FORMATS = ['image/webp']; export const EXIF_LIBRARY_UNSUPPORTED_FORMATS = ['image/webp'];

View file

@ -529,7 +529,7 @@ export const removeFromCollection = async (
continue; continue;
} }
await moveToCollection( await moveToCollection(
collectionsMap[toMoveCollectionID], collectionsMap.get(toMoveCollectionID),
collectionID, collectionID,
toMoveFiles toMoveFiles
); );

View file

@ -1,6 +1,9 @@
import { FILE_TYPE } from 'constants/file'; import { FILE_TYPE } from 'constants/file';
import { ElectronFile, FileTypeInfo } from 'types/upload'; import { ElectronFile, FileTypeInfo } from 'types/upload';
import { FILE_TYPE_LIB_MISSED_FORMATS } from 'constants/upload'; import {
FILE_TYPE_LIB_MISSED_FORMATS,
KNOWN_NON_MEDIA_FORMATS,
} from 'constants/upload';
import { CustomError } from 'utils/error'; import { CustomError } from 'utils/error';
import { getFileExtension } from 'utils/file'; import { getFileExtension } from 'utils/file';
import { logError } from 'utils/sentry'; import { logError } from 'utils/sentry';
@ -27,7 +30,7 @@ export async function getFileType(
const mimTypeParts: string[] = typeResult.mime?.split('/'); const mimTypeParts: string[] = typeResult.mime?.split('/');
if (mimTypeParts?.length !== 2) { if (mimTypeParts?.length !== 2) {
throw Error(CustomError.TYPE_DETECTION_FAILED); throw Error(CustomError.INVALID_MIME_TYPE(typeResult.mime));
} }
switch (mimTypeParts[0]) { switch (mimTypeParts[0]) {
case TYPE_IMAGE: case TYPE_IMAGE:
@ -37,7 +40,7 @@ export async function getFileType(
fileType = FILE_TYPE.VIDEO; fileType = FILE_TYPE.VIDEO;
break; break;
default: default:
fileType = FILE_TYPE.OTHERS; throw Error(CustomError.UNSUPPORTED_FILE_FORMAT);
} }
return { return {
fileType, fileType,
@ -45,6 +48,9 @@ export async function getFileType(
mimeType: typeResult.mime, mimeType: typeResult.mime,
}; };
} catch (e) { } catch (e) {
if (e.message === CustomError.UNSUPPORTED_FILE_FORMAT) {
throw e;
}
const fileFormat = getFileExtension(receivedFile.name); const fileFormat = getFileExtension(receivedFile.name);
const formatMissedByTypeDetection = FILE_TYPE_LIB_MISSED_FORMATS.find( const formatMissedByTypeDetection = FILE_TYPE_LIB_MISSED_FORMATS.find(
(a) => a.exactType === fileFormat (a) => a.exactType === fileFormat
@ -52,14 +58,13 @@ export async function getFileType(
if (formatMissedByTypeDetection) { if (formatMissedByTypeDetection) {
return formatMissedByTypeDetection; return formatMissedByTypeDetection;
} }
logError(e, CustomError.TYPE_DETECTION_FAILED, { if (KNOWN_NON_MEDIA_FORMATS.includes(fileFormat)) {
throw Error(CustomError.UNSUPPORTED_FILE_FORMAT);
}
logError(e, 'type detection failed', {
fileFormat, fileFormat,
}); });
return { throw Error(CustomError.TYPE_DETECTION_FAILED(fileFormat));
fileType: FILE_TYPE.OTHERS,
exactType: fileFormat,
mimeType: receivedFile instanceof File ? receivedFile.type : null,
};
} }
} }
@ -78,18 +83,15 @@ async function extractElectronFileType(file: ElectronFile) {
} }
async function getFileTypeFromBuffer(buffer: Uint8Array) { async function getFileTypeFromBuffer(buffer: Uint8Array) {
try {
const result = await FileType.fromBuffer(buffer); const result = await FileType.fromBuffer(buffer);
if (!result.mime) { if (!result?.mime) {
logError( let logableInfo = '';
Error('mimetype missing from file type result'), try {
CustomError.TYPE_DETECTION_FAILED, logableInfo = `result: ${JSON.stringify(result)}`;
{ result } } catch (e) {
); logableInfo = 'failed to stringify result';
throw Error(CustomError.TYPE_DETECTION_FAILED); }
throw Error(`mimetype missing from file type result - ${logableInfo}`);
} }
return result; return result;
} catch (e) {
throw Error(CustomError.TYPE_DETECTION_FAILED);
}
} }

View file

@ -51,10 +51,9 @@ export default async function uploader(
} }
addLogLine(`getting filetype for ${fileNameSize}`); addLogLine(`getting filetype for ${fileNameSize}`);
fileTypeInfo = await UploadService.getAssetFileType(uploadAsset); fileTypeInfo = await UploadService.getAssetFileType(uploadAsset);
addLogLine(`got filetype for ${fileNameSize}`); addLogLine(
if (fileTypeInfo.fileType === FILE_TYPE.OTHERS) { `got filetype for ${fileNameSize} - ${JSON.stringify(fileTypeInfo)}`
throw Error(CustomError.UNSUPPORTED_FILE_FORMAT); );
}
if (skipVideos && fileTypeInfo.fileType === FILE_TYPE.VIDEO) { if (skipVideos && fileTypeInfo.fileType === FILE_TYPE.VIDEO) {
addLogLine( addLogLine(
`skipped video upload for public upload ${fileNameSize}` `skipped video upload for public upload ${fileNameSize}`
@ -176,7 +175,10 @@ export default async function uploader(
}; };
} catch (e) { } catch (e) {
addLogLine(`upload failed for ${fileNameSize} ,error: ${e.message}`); addLogLine(`upload failed for ${fileNameSize} ,error: ${e.message}`);
if (e.message !== CustomError.UPLOAD_CANCELLED) { if (
e.message !== CustomError.UPLOAD_CANCELLED &&
e.message !== CustomError.UNSUPPORTED_FILE_FORMAT
) {
logError(e, 'file upload failed', { logError(e, 'file upload failed', {
fileFormat: fileTypeInfo?.exactType, fileFormat: fileTypeInfo?.exactType,
}); });

View file

@ -11,45 +11,49 @@ export const ServerErrorCodes = {
NOT_FOUND: '404', NOT_FOUND: '404',
}; };
export enum CustomError { export const CustomError = {
SUBSCRIPTION_VERIFICATION_ERROR = 'Subscription verification failed', SUBSCRIPTION_VERIFICATION_ERROR: 'Subscription verification failed',
THUMBNAIL_GENERATION_FAILED = 'thumbnail generation failed', THUMBNAIL_GENERATION_FAILED: 'thumbnail generation failed',
VIDEO_PLAYBACK_FAILED = 'video playback failed', VIDEO_PLAYBACK_FAILED: 'video playback failed',
ETAG_MISSING = 'no header/etag present in response body', ETAG_MISSING: 'no header/etag present in response body',
KEY_MISSING = 'encrypted key missing from localStorage', KEY_MISSING: 'encrypted key missing from localStorage',
FAILED_TO_LOAD_WEB_WORKER = 'failed to load web worker', FAILED_TO_LOAD_WEB_WORKER: 'failed to load web worker',
CHUNK_MORE_THAN_EXPECTED = 'chunks more than expected', CHUNK_MORE_THAN_EXPECTED: 'chunks more than expected',
CHUNK_LESS_THAN_EXPECTED = 'chunks less than expected', CHUNK_LESS_THAN_EXPECTED: 'chunks less than expected',
UNSUPPORTED_FILE_FORMAT = 'unsupported file formats', UNSUPPORTED_FILE_FORMAT: 'unsupported file format',
FILE_TOO_LARGE = 'file too large', FILE_TOO_LARGE: 'file too large',
SUBSCRIPTION_EXPIRED = 'subscription expired', SUBSCRIPTION_EXPIRED: 'subscription expired',
STORAGE_QUOTA_EXCEEDED = 'storage quota exceeded', STORAGE_QUOTA_EXCEEDED: 'storage quota exceeded',
SESSION_EXPIRED = 'session expired', SESSION_EXPIRED: 'session expired',
TYPE_DETECTION_FAILED = 'type detection failed', INVALID_MIME_TYPE: (type: string) => `invalid mime type -${type}`,
SIGNUP_FAILED = 'signup failed', SIGNUP_FAILED: 'signup failed',
FAV_COLLECTION_MISSING = 'favorite collection missing', FAV_COLLECTION_MISSING: 'favorite collection missing',
INVALID_COLLECTION_OPERATION = 'invalid collection operation', INVALID_COLLECTION_OPERATION: 'invalid collection operation',
WAIT_TIME_EXCEEDED = 'thumbnail generation wait time exceeded', WAIT_TIME_EXCEEDED: 'thumbnail generation wait time exceeded',
REQUEST_CANCELLED = 'request canceled', REQUEST_CANCELLED: 'request canceled',
REQUEST_FAILED = 'request failed', REQUEST_FAILED: 'request failed',
TOKEN_EXPIRED = 'token expired', TOKEN_EXPIRED: 'token expired',
TOKEN_MISSING = 'token missing', TOKEN_MISSING: 'token missing',
TOO_MANY_REQUESTS = 'too many requests', TOO_MANY_REQUESTS: 'too many requests',
BAD_REQUEST = 'bad request', BAD_REQUEST: 'bad request',
SUBSCRIPTION_NEEDED = 'subscription not present', SUBSCRIPTION_NEEDED: 'subscription not present',
NOT_FOUND = 'not found ', NOT_FOUND: 'not found ',
NO_METADATA = 'no metadata', NO_METADATA: 'no metadata',
TOO_LARGE_LIVE_PHOTO_ASSETS = 'too large live photo assets', TOO_LARGE_LIVE_PHOTO_ASSETS: 'too large live photo assets',
NOT_A_DATE = 'not a date', NOT_A_DATE: 'not a date',
FILE_ID_NOT_FOUND = 'file with id not found', FILE_ID_NOT_FOUND: 'file with id not found',
WEAK_DEVICE = 'password decryption failed on the device', WEAK_DEVICE: 'password decryption failed on the device',
INCORRECT_PASSWORD = 'incorrect password', INCORRECT_PASSWORD: 'incorrect password',
UPLOAD_CANCELLED = 'upload cancelled', UPLOAD_CANCELLED: 'upload cancelled',
REQUEST_TIMEOUT = 'request taking too long', REQUEST_TIMEOUT: 'request taking too long',
HIDDEN_COLLECTION_SYNC_FILE_ATTEMPTED = 'hidden collection sync file attempted', HIDDEN_COLLECTION_SYNC_FILE_ATTEMPTED:
UNKNOWN_ERROR = 'Something went wrong, please try again', 'hidden collection sync file attempted',
WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED = 'Windows native image processing is not supported', UNKNOWN_ERROR: 'Something went wrong, please try again',
} TYPE_DETECTION_FAILED: (fileFormat: string) =>
`type detection failed ${fileFormat}`,
WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED:
'Windows native image processing is not supported',
};
function parseUploadErrorCodes(error) { function parseUploadErrorCodes(error) {
let parsedMessage = null; let parsedMessage = null;

View file

@ -1,5 +1,4 @@
import * as Sentry from '@sentry/nextjs'; import * as Sentry from '@sentry/nextjs';
import { isDEVSentryENV } from 'constants/sentry';
import { addLogLine } from 'utils/logging'; import { addLogLine } from 'utils/logging';
import { getSentryUserID } from 'utils/user'; import { getSentryUserID } from 'utils/user';
@ -17,12 +16,9 @@ export const logError = async (
addLogLine( addLogLine(
`error: ${error?.name} ${error?.message} ${ `error: ${error?.name} ${error?.message} ${
error?.stack error?.stack
} msg: ${msg} info: ${JSON.stringify(info)}` } msg: ${msg} ${info ? `info: ${JSON.stringify(info)}` : ''}`
); );
} }
if (isDEVSentryENV()) {
console.log(error, { msg, info });
}
Sentry.captureException(err, { Sentry.captureException(err, {
level: Sentry.Severity.Info, level: Sentry.Severity.Info,
user: { id: await getSentryUserID() }, user: { id: await getSentryUserID() },

View file

@ -702,7 +702,7 @@ const englishConstants = {
LINK_EXPIRED_MESSAGE: 'This link has either expired or been disabled!', LINK_EXPIRED_MESSAGE: 'This link has either expired or been disabled!',
MANAGE_LINK: 'Manage link', MANAGE_LINK: 'Manage link',
LINK_TOO_MANY_REQUESTS: 'This album is too popular for us to handle!', LINK_TOO_MANY_REQUESTS: 'This album is too popular for us to handle!',
DISABLE_PUBLIC_SHARING: "'Disable public sharing", DISABLE_PUBLIC_SHARING: 'Disable public sharing',
DISABLE_PUBLIC_SHARING_MESSAGE: DISABLE_PUBLIC_SHARING_MESSAGE:
'Are you sure you want to disable public sharing?', 'Are you sure you want to disable public sharing?',
FILE_DOWNLOAD: 'Allow downloads', FILE_DOWNLOAD: 'Allow downloads',