Skip to content

Commit

Permalink
fix(web): show trash indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed Sep 9, 2024
1 parent 8c3c335 commit 524a807
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 24 deletions.
19 changes: 18 additions & 1 deletion mobile/openapi/lib/model/asset_bulk_upload_check_result.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions open-api/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7928,6 +7928,9 @@
"id": {
"type": "string"
},
"isTrashed": {
"type": "boolean"
},
"reason": {
"enum": [
"duplicate",
Expand Down
1 change: 1 addition & 0 deletions open-api/typescript-sdk/src/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ export type AssetBulkUploadCheckResult = {
action: Action;
assetId?: string;
id: string;
isTrashed?: boolean;
reason?: Reason;
};
export type AssetBulkUploadCheckResponseDto = {
Expand Down
1 change: 1 addition & 0 deletions server/src/dtos/asset-media-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class AssetBulkUploadCheckResult {
action!: AssetUploadAction;
reason?: AssetRejectReason;
assetId?: string;
isTrashed?: boolean;
}

export class AssetBulkUploadCheckResponseDto {
Expand Down
1 change: 1 addition & 0 deletions server/src/queries/asset.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ LIMIT
-- AssetRepository.getByChecksums
SELECT
"AssetEntity"."id" AS "AssetEntity_id",
"AssetEntity"."deletedAt" AS "AssetEntity_deletedAt",
"AssetEntity"."checksum" AS "AssetEntity_checksum"
FROM
"assets" "AssetEntity"
Expand Down
10 changes: 5 additions & 5 deletions server/src/queries/metadata.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM
LEFT JOIN "assets" "asset" ON "asset"."id" = "exif"."assetId"
AND ("asset"."deletedAt" IS NULL)
WHERE
"asset"."ownerId" = $1
"asset"."ownerId" IN ($1)

-- MetadataRepository.getStates
SELECT DISTINCT
Expand All @@ -18,7 +18,7 @@ FROM
LEFT JOIN "assets" "asset" ON "asset"."id" = "exif"."assetId"
AND ("asset"."deletedAt" IS NULL)
WHERE
"asset"."ownerId" = $1
"asset"."ownerId" IN ($1)
AND "exif"."country" = $2

-- MetadataRepository.getCities
Expand All @@ -29,7 +29,7 @@ FROM
LEFT JOIN "assets" "asset" ON "asset"."id" = "exif"."assetId"
AND ("asset"."deletedAt" IS NULL)
WHERE
"asset"."ownerId" = $1
"asset"."ownerId" IN ($1)
AND "exif"."country" = $2
AND "exif"."state" = $3

Expand All @@ -41,7 +41,7 @@ FROM
LEFT JOIN "assets" "asset" ON "asset"."id" = "exif"."assetId"
AND ("asset"."deletedAt" IS NULL)
WHERE
"asset"."ownerId" = $1
"asset"."ownerId" IN ($1)
AND "exif"."model" = $2

-- MetadataRepository.getCameraModels
Expand All @@ -52,5 +52,5 @@ FROM
LEFT JOIN "assets" "asset" ON "asset"."id" = "exif"."assetId"
AND ("asset"."deletedAt" IS NULL)
WHERE
"asset"."ownerId" = $1
"asset"."ownerId" IN ($1)
AND "exif"."make" = $2
1 change: 1 addition & 0 deletions server/src/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export class AssetRepository implements IAssetRepository {
select: {
id: true,
checksum: true,
deletedAt: true,
},
where: {
ownerId,
Expand Down
10 changes: 5 additions & 5 deletions server/src/repositories/metadata.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class MetadataRepository implements IMetadataRepository {
}
}

@GenerateSql({ params: [DummyValue.UUID] })
@GenerateSql({ params: [[DummyValue.UUID]] })
async getCountries(userIds: string[]): Promise<string[]> {
const results = await this.exifRepository
.createQueryBuilder('exif')
Expand All @@ -68,7 +68,7 @@ export class MetadataRepository implements IMetadataRepository {
return results.map(({ country }) => country).filter((item) => item !== '');
}

@GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING] })
@GenerateSql({ params: [[DummyValue.UUID], DummyValue.STRING] })
async getStates(userIds: string[], country: string | undefined): Promise<string[]> {
const query = this.exifRepository
.createQueryBuilder('exif')
Expand All @@ -86,7 +86,7 @@ export class MetadataRepository implements IMetadataRepository {
return result.map(({ state }) => state).filter((item) => item !== '');
}

@GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING, DummyValue.STRING] })
@GenerateSql({ params: [[DummyValue.UUID], DummyValue.STRING, DummyValue.STRING] })
async getCities(userIds: string[], country: string | undefined, state: string | undefined): Promise<string[]> {
const query = this.exifRepository
.createQueryBuilder('exif')
Expand All @@ -108,7 +108,7 @@ export class MetadataRepository implements IMetadataRepository {
return results.map(({ city }) => city).filter((item) => item !== '');
}

@GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING] })
@GenerateSql({ params: [[DummyValue.UUID], DummyValue.STRING] })
async getCameraMakes(userIds: string[], model: string | undefined): Promise<string[]> {
const query = this.exifRepository
.createQueryBuilder('exif')
Expand All @@ -125,7 +125,7 @@ export class MetadataRepository implements IMetadataRepository {
return results.map(({ make }) => make).filter((item) => item !== '');
}

@GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING] })
@GenerateSql({ params: [[DummyValue.UUID], DummyValue.STRING] })
async getCameraModels(userIds: string[], make: string | undefined): Promise<string[]> {
const query = this.exifRepository
.createQueryBuilder('exif')
Expand Down
16 changes: 14 additions & 2 deletions server/src/services/asset-media.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,20 @@ describe(AssetMediaService.name, () => {
}),
).resolves.toEqual({
results: [
{ id: '1', assetId: 'asset-1', action: AssetUploadAction.REJECT, reason: AssetRejectReason.DUPLICATE },
{ id: '2', assetId: 'asset-2', action: AssetUploadAction.REJECT, reason: AssetRejectReason.DUPLICATE },
{
id: '1',
assetId: 'asset-1',
action: AssetUploadAction.REJECT,
reason: AssetRejectReason.DUPLICATE,
isTrashed: false,
},
{
id: '2',
assetId: 'asset-2',
action: AssetUploadAction.REJECT,
reason: AssetRejectReason.DUPLICATE,
isTrashed: false,
},
],
});

Expand Down
11 changes: 5 additions & 6 deletions server/src/services/asset-media.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ export class AssetMediaService {
async bulkUploadCheck(auth: AuthDto, dto: AssetBulkUploadCheckDto): Promise<AssetBulkUploadCheckResponseDto> {
const checksums: Buffer[] = dto.assets.map((asset) => fromChecksum(asset.checksum));
const results = await this.assetRepository.getByChecksums(auth.user.id, checksums);
const checksumMap: Record<string, string> = {};
const checksumMap: Record<string, { id: string; isTrashed: boolean }> = {};

for (const { id, checksum } of results) {
checksumMap[checksum.toString('hex')] = id;
for (const { id, deletedAt, checksum } of results) {
checksumMap[checksum.toString('hex')] = { id, isTrashed: !!deletedAt };
}

return {
Expand All @@ -301,14 +301,13 @@ export class AssetMediaService {
if (duplicate) {
return {
id,
assetId: duplicate,
action: AssetUploadAction.REJECT,
reason: AssetRejectReason.DUPLICATE,
assetId: duplicate.id,
isTrashed: duplicate.isTrashed,
};
}

// TODO mime-check

return {
id,
action: AssetUploadAction.ACCEPT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
mdiLoading,
mdiOpenInNew,
mdiRestart,
mdiTrashCan,
} from '@mdi/js';
import { t } from 'svelte-i18n';
import { fade } from 'svelte/transition';
Expand All @@ -29,6 +30,10 @@
uploadAssetsStore.removeItem(uploadAsset.id);
await fileUploadHandler([uploadAsset.file], uploadAsset.albumId);
};
const asLink = (asset: UploadAsset) => {
return asset.isTrashed ? `${AppRoute.TRASH}/${asset.assetId}` : `${AppRoute.PHOTOS}/${uploadAsset.assetId}`;
};
</script>

<div
Expand All @@ -45,7 +50,11 @@
{:else if uploadAsset.state === UploadState.ERROR}
<Icon path={mdiAlertCircle} size="24" class="text-immich-error" title={$t('error')} />
{:else if uploadAsset.state === UploadState.DUPLICATED}
<Icon path={mdiAlertCircle} size="24" class="text-immich-warning" title={$t('asset_skipped')} />
{#if uploadAsset.isTrashed}
<Icon path={mdiTrashCan} size="24" class="text-gray-500" title={$t('asset_skipped_in_trash')} />
{:else}
<Icon path={mdiAlertCircle} size="24" class="text-immich-warning" title={$t('asset_skipped')} />
{/if}
{:else if uploadAsset.state === UploadState.DONE}
<Icon path={mdiCheckCircle} size="24" class="text-immich-success" title={$t('asset_uploaded')} />
{/if}
Expand All @@ -56,7 +65,7 @@
{#if uploadAsset.state === UploadState.DUPLICATED && uploadAsset.assetId}
<div class="flex items-center justify-between gap-1">
<a
href="{AppRoute.PHOTOS}/{uploadAsset.assetId}"
href={asLink(uploadAsset)}
target="_blank"
rel="noopener noreferrer"
class=""
Expand Down
1 change: 1 addition & 0 deletions web/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
"asset_offline": "Asset offline",
"asset_offline_description": "This asset is offline. Immich can not access its file location. Please ensure the asset is available and then rescan the library.",
"asset_skipped": "Skipped",
"asset_skipped_in_trash": "In trash",
"asset_uploaded": "Uploaded",
"asset_uploading": "Uploading...",
"assets": "Assets",
Expand Down
1 change: 1 addition & 0 deletions web/src/lib/models/upload-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type UploadAsset = {
id: string;
file: File;
assetId?: string;
isTrashed?: boolean;
albumId?: string;
progress?: number;
state?: UploadState;
Expand Down
13 changes: 10 additions & 3 deletions web/src/lib/utils/file-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export const addDummyItems = () => {
uploadAssetsStore.addItem({ id: 'asset-3', file: { name: 'asset3.jpg', size: 123_456 } as File });
uploadAssetsStore.updateItem('asset-3', { state: UploadState.DUPLICATED, assetId: 'asset-2' });
uploadAssetsStore.addItem({ id: 'asset-4', file: { name: 'asset3.jpg', size: 123_456 } as File });
uploadAssetsStore.updateItem('asset-4', { state: UploadState.DONE });
uploadAssetsStore.updateItem('asset-4', { state: UploadState.DUPLICATED, assetId: 'asset-2', isTrashed: true });
uploadAssetsStore.addItem({ id: 'asset-10', file: { name: 'asset3.jpg', size: 123_456 } as File });
uploadAssetsStore.updateItem('asset-10', { state: UploadState.DONE });
uploadAssetsStore.track('error');
uploadAssetsStore.track('success');
uploadAssetsStore.track('duplicate');
Expand Down Expand Up @@ -122,7 +124,7 @@ async function fileUploader(assetFile: File, albumId?: string, replaceAssetId?:
formData.append(key, value);
}

let responseData: AssetMediaResponseDto | undefined;
let responseData: { id: string; status: AssetMediaStatus; isTrashed?: boolean } | undefined;
const key = getKey();
if (crypto?.subtle?.digest && !key) {
uploadAssetsStore.updateItem(deviceAssetId, { message: $t('asset_hashing') });
Expand All @@ -138,7 +140,11 @@ async function fileUploader(assetFile: File, albumId?: string, replaceAssetId?:
results: [checkUploadResult],
} = await checkBulkUpload({ assetBulkUploadCheckDto: { assets: [{ id: assetFile.name, checksum }] } });
if (checkUploadResult.action === Action.Reject && checkUploadResult.assetId) {
responseData = { status: AssetMediaStatus.Duplicate, id: checkUploadResult.assetId };
responseData = {
status: AssetMediaStatus.Duplicate,
id: checkUploadResult.assetId,
isTrashed: checkUploadResult.isTrashed,
};
}
} catch (error) {
console.error(`Error calculating sha1 file=${assetFile.name})`, error);
Expand Down Expand Up @@ -185,6 +191,7 @@ async function fileUploader(assetFile: File, albumId?: string, replaceAssetId?:
uploadAssetsStore.updateItem(deviceAssetId, {
state: responseData.status === AssetMediaStatus.Duplicate ? UploadState.DUPLICATED : UploadState.DONE,
assetId: responseData.id,
isTrashed: responseData.isTrashed,
});

if (responseData.status !== AssetMediaStatus.Duplicate) {
Expand Down

0 comments on commit 524a807

Please sign in to comment.