mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
* 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
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
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 {
|
|
websocket = io(websocketEndpoint, {
|
|
path: '/api/socket.io',
|
|
transports: ['polling'],
|
|
reconnection: true,
|
|
forceNew: true,
|
|
autoConnect: true,
|
|
extraHeaders: {
|
|
Authorization: 'Bearer ' + accessToken,
|
|
},
|
|
});
|
|
|
|
listenToEvent(websocket);
|
|
} catch (e) {
|
|
console.log('Cannot connect to websocket ', e);
|
|
}
|
|
};
|
|
|
|
const listenToEvent = (socket: Socket) => {
|
|
socket.on('on_upload_success', (data) => {
|
|
const newUploadedAsset: ImmichAsset = JSON.parse(data);
|
|
// assets.update((assets) => [...assets, newUploadedAsset]);
|
|
});
|
|
|
|
socket.on('error', (e) => {
|
|
console.log('Websocket Error', e);
|
|
});
|
|
};
|
|
|
|
export const closeWebsocketConnection = () => {
|
|
websocket?.close();
|
|
};
|