Fix server crash on bad file operation and other optimizations (#291)

* Fixed issue with generating thumbnail for video with 0 length cause undefined file and crash the server
* Added all file error handling operation
* Temporarily disabled WebSocket on the web because receiving a new upload event doesn't put the new file in the correct place. 
* Cosmetic fixed on the info panel
This commit is contained in:
Alex 2022-07-01 12:00:12 -05:00 committed by GitHub
parent c071e64a7e
commit a45d6fdf57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 118 additions and 79 deletions

View file

@ -5,6 +5,8 @@
import CloudUploadOutline from 'svelte-material-icons/CloudUploadOutline.svelte';
import WindowMinimize from 'svelte-material-icons/WindowMinimize.svelte';
import type { UploadAsset } from '$lib/models/upload-asset';
import { getAssetsInfo } from '$lib/stores/assets';
import { session } from '$app/stores';
let showDetail = true;
@ -73,8 +75,15 @@
}
let isUploading = false;
uploadAssetsStore.isUploading.subscribe((value) => {
isUploading = value;
uploadAssetsStore.isUploading.subscribe((value) => (isUploading = value));
if (isUploading == false) {
if ($session.user) {
getAssetsInfo($session.user.accessToken);
}
}
});
</script>
{#if isUploading}

View file

@ -2,8 +2,8 @@ import { writable, derived } from 'svelte/store';
import { getRequest } from '$lib/api';
import type { ImmichAsset } from '$lib/models/immich-asset';
import lodash from 'lodash-es';
import _ from 'lodash';
import moment from 'moment';
export const assets = writable<ImmichAsset[]>([]);
export const assetsGroupByDate = derived(assets, ($assets) => {
@ -14,7 +14,6 @@ export const assetsGroupByDate = derived(assets, ($assets) => {
.sortBy((group) => $assets.indexOf(group[0]))
.value();
} catch (e) {
console.log('error deriving state assets', e);
return [];
}
});

View file

@ -1,12 +1,16 @@
import { Socket, io } from 'socket.io-client';
import { writable } from 'svelte/store';
import { serverEndpoint } from '../constants';
import type { ImmichAsset } from '../models/immich-asset';
import { assets } from './assets';
let websocket: Socket;
export const openWebsocketConnection = (accessToken: string) => {
const websocketEndpoint = serverEndpoint.replace('/api', '');
try {
const websocket = io(websocketEndpoint, {
websocket = io(websocketEndpoint, {
path: '/api/socket.io',
transports: ['polling'],
reconnection: true,
@ -26,11 +30,14 @@ export const openWebsocketConnection = (accessToken: string) => {
const listenToEvent = (socket: Socket) => {
socket.on('on_upload_success', (data) => {
const newUploadedAsset: ImmichAsset = JSON.parse(data);
assets.update((assets) => [...assets, newUploadedAsset]);
// assets.update((assets) => [...assets, newUploadedAsset]);
});
socket.on('error', (e) => {
console.log('Websocket Error', e);
});
};
export const closeWebsocketConnection = () => {
websocket?.close();
};

View file

@ -84,7 +84,7 @@ export async function fileUploader(asset: File, accessToken: string) {
request.upload.onload = () => {
setTimeout(() => {
uploadAssetsStore.removeUploadAsset(deviceAssetId);
}, 2500);
}, 1000);
};
// listen for `error` event