1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-23 23:09:37 +02:00

feat: enhance Immich integration with local copy option and validation for image handling

This commit is contained in:
Sean Morley 2025-06-01 19:55:12 -04:00
parent f95afdc35c
commit 06787bccf6
12 changed files with 214 additions and 37 deletions

View file

@ -13,6 +13,7 @@
let loading = false;
export let adventure: Adventure | null = null;
export let copyImmichLocally: boolean = false;
const dispatch = createEventDispatcher();
@ -45,6 +46,36 @@
return fetchAssets(immichNextURL, true);
}
async function saveImmichRemoteUrl(imageId: string) {
if (!adventure) {
console.error('No adventure provided to save the image URL');
return;
}
let res = await fetch('/api/images', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
immich_id: imageId,
adventure: adventure.id
})
});
if (res.ok) {
let data = await res.json();
if (!data.image) {
console.error('No image data returned from the server');
immichError = $t('immich.error_saving_image');
return;
}
dispatch('remoteImmichSaved', data);
} else {
let errorData = await res.json();
console.error('Error saving image URL:', errorData);
immichError = $t(errorData.message || 'immich.error_saving_image');
}
}
async function fetchAssets(url: string, usingNext = false) {
loading = true;
try {
@ -191,7 +222,11 @@
on:click={() => {
let currentDomain = window.location.origin;
let fullUrl = `${currentDomain}/immich/${image.id}`;
dispatch('fetchImage', fullUrl);
if (copyImmichLocally) {
dispatch('fetchImage', fullUrl);
} else {
saveImmichRemoteUrl(image.id);
}
}}
>
{$t('adventures.upload_image')}