mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
Implemented getting correct disk info for the mounted directory (#72)
This commit is contained in:
parent
ce1ab1ed50
commit
e9acd21733
6 changed files with 52 additions and 28 deletions
|
|
@ -55,7 +55,7 @@ export class AssetController {
|
|||
@UploadedFiles() uploadFiles: { assetData: Express.Multer.File[]; thumbnailData?: Express.Multer.File[] },
|
||||
@Body(ValidationPipe) assetInfo: CreateAssetDto,
|
||||
) {
|
||||
uploadFiles.assetData.forEach(async (file) => {
|
||||
for (const file of uploadFiles.assetData) {
|
||||
const savedAsset = await this.assetService.createUserAsset(authUser, assetInfo, file.path, file.mimetype);
|
||||
|
||||
if (uploadFiles.thumbnailData != null) {
|
||||
|
|
@ -66,7 +66,7 @@ export class AssetController {
|
|||
await this.backgroundTaskService.extractExif(savedAsset, file.originalname, file.size);
|
||||
|
||||
this.wsCommunicateionGateway.server.to(savedAsset.userId).emit('on_upload_success', JSON.stringify(savedAsset));
|
||||
});
|
||||
}
|
||||
|
||||
return 'ok';
|
||||
}
|
||||
|
|
@ -125,10 +125,10 @@ export class AssetController {
|
|||
async deleteAssetById(@GetAuthUser() authUser: AuthUserDto, @Body(ValidationPipe) assetIds: DeleteAssetDto) {
|
||||
const deleteAssetList: AssetEntity[] = [];
|
||||
|
||||
assetIds.ids.forEach(async (id) => {
|
||||
for (const id of assetIds.ids) {
|
||||
const assets = await this.assetService.getAssetById(authUser, id);
|
||||
deleteAssetList.push(assets);
|
||||
});
|
||||
}
|
||||
|
||||
const result = await this.assetService.deleteAssetById(authUser, assetIds);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator';
|
||||
import { JwtAuthGuard } from '../../modules/immich-jwt/guards/jwt-auth.guard';
|
||||
import { ServerInfoService } from './server-info.service';
|
||||
import mapboxGeocoding, { GeocodeService } from '@mapbox/mapbox-sdk/services/geocoding';
|
||||
import { MapiResponse } from '@mapbox/mapbox-sdk/lib/classes/mapi-response';
|
||||
import { serverVersion } from '../../constants/server_version.constant';
|
||||
|
||||
@Controller('server-info')
|
||||
|
|
|
|||
|
|
@ -1,31 +1,27 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import systemInformation from 'systeminformation';
|
||||
import { ServerInfoDto } from './dto/server-info.dto';
|
||||
import diskusage from 'diskusage';
|
||||
|
||||
@Injectable()
|
||||
export class ServerInfoService {
|
||||
constructor() {}
|
||||
async getServerInfo() {
|
||||
const res = await systemInformation.fsSize();
|
||||
const diskInfo = await diskusage.check('./upload');
|
||||
|
||||
const size = res[0].size;
|
||||
const used = res[0].used;
|
||||
const available = res[0].available;
|
||||
const percentageUsage = res[0].use;
|
||||
const usagePercentage = (((diskInfo.total - diskInfo.free) / diskInfo.total) * 100).toFixed(2);
|
||||
|
||||
const serverInfo = new ServerInfoDto();
|
||||
serverInfo.diskAvailable = this.getHumanReadableString(available);
|
||||
serverInfo.diskSize = this.getHumanReadableString(size);
|
||||
serverInfo.diskUse = this.getHumanReadableString(used);
|
||||
serverInfo.diskAvailableRaw = available;
|
||||
serverInfo.diskSizeRaw = size;
|
||||
serverInfo.diskUseRaw = used;
|
||||
serverInfo.diskUsagePercentage = percentageUsage;
|
||||
serverInfo.diskAvailable = ServerInfoService.getHumanReadableString(diskInfo.available);
|
||||
serverInfo.diskSize = ServerInfoService.getHumanReadableString(diskInfo.total);
|
||||
serverInfo.diskUse = ServerInfoService.getHumanReadableString(diskInfo.total - diskInfo.free);
|
||||
serverInfo.diskAvailableRaw = diskInfo.available;
|
||||
serverInfo.diskSizeRaw = diskInfo.total;
|
||||
serverInfo.diskUseRaw = diskInfo.total - diskInfo.free;
|
||||
serverInfo.diskUsagePercentage = parseFloat(usagePercentage);
|
||||
|
||||
return serverInfo;
|
||||
}
|
||||
|
||||
private getHumanReadableString(sizeInByte: number) {
|
||||
private static getHumanReadableString(sizeInByte: number) {
|
||||
const pepibyte = 1.126 * Math.pow(10, 15);
|
||||
const tebibyte = 1.1 * Math.pow(10, 12);
|
||||
const gibibyte = 1.074 * Math.pow(10, 9);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue