mirror of
https://github.com/immich-app/immich.git
synced 2025-07-03 21:40:00 +02:00
* Render when a new asset is uploaded from WebSocket notification * Update Readme
This commit is contained in:
parent
7cc7fc0a0c
commit
c234c95880
23 changed files with 11037 additions and 69 deletions
server/src/modules/image-optimize
|
@ -8,14 +8,16 @@ import { existsSync, mkdirSync, readFile } from 'fs';
|
|||
import { ConfigService } from '@nestjs/config';
|
||||
import ffmpeg from 'fluent-ffmpeg';
|
||||
import { APP_UPLOAD_LOCATION } from '../../constants/upload_location.constant';
|
||||
import { WebSocketServer } from '@nestjs/websockets';
|
||||
import { Socket, Server as SocketIoServer } from 'socket.io';
|
||||
import { CommunicationGateway } from '../../api-v1/communication/communication.gateway';
|
||||
|
||||
@Processor('optimize')
|
||||
export class ImageOptimizeProcessor {
|
||||
constructor(
|
||||
private wsCommunicateionGateway: CommunicationGateway,
|
||||
@InjectRepository(AssetEntity)
|
||||
private assetRepository: Repository<AssetEntity>,
|
||||
|
||||
private configService: ConfigService,
|
||||
) {}
|
||||
|
||||
@Process('resize-image')
|
||||
|
@ -55,7 +57,12 @@ export class ImageOptimizeProcessor {
|
|||
return;
|
||||
}
|
||||
|
||||
await this.assetRepository.update(savedAsset, { resizePath: desitnation });
|
||||
const res = await this.assetRepository.update(savedAsset, { resizePath: desitnation });
|
||||
if (res.affected) {
|
||||
this.wsCommunicateionGateway.server
|
||||
.to(savedAsset.userId)
|
||||
.emit('on_upload_success', JSON.stringify(savedAsset));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sharp(data)
|
||||
|
@ -66,7 +73,12 @@ export class ImageOptimizeProcessor {
|
|||
return;
|
||||
}
|
||||
|
||||
await this.assetRepository.update(savedAsset, { resizePath: resizePath });
|
||||
const res = await this.assetRepository.update(savedAsset, { resizePath: resizePath });
|
||||
if (res.affected) {
|
||||
this.wsCommunicateionGateway.server
|
||||
.to(savedAsset.userId)
|
||||
.emit('on_upload_success', JSON.stringify(savedAsset));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -95,7 +107,12 @@ export class ImageOptimizeProcessor {
|
|||
filename: `${filename}.png`,
|
||||
})
|
||||
.on('end', async (a) => {
|
||||
await this.assetRepository.update(savedAsset, { resizePath: `${resizeDir}/${filename}.png` });
|
||||
const res = await this.assetRepository.update(savedAsset, { resizePath: `${resizeDir}/${filename}.png` });
|
||||
if (res.affected) {
|
||||
this.wsCommunicateionGateway.server
|
||||
.to(savedAsset.userId)
|
||||
.emit('on_upload_success', JSON.stringify(savedAsset));
|
||||
}
|
||||
});
|
||||
|
||||
return 'ok';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue