fix(uploader): upload to temp bucket and fix initialFiles reactivity to prevent file vanishing
deploy-chabokan / deploy (push) Canceled after 0s

This commit is contained in:
2026-08-19 04:58:19 +03:30
parent 36f2c200a1
commit ba54647837
2 changed files with 31 additions and 20 deletions
+2 -2
View File
@@ -862,7 +862,7 @@ const saveProperty = async () => {
<i class="pi pi-file-pdf text-xl"></i> <i class="pi pi-file-pdf text-xl"></i>
<span>اسناد و مدارک تصویری / پی‌دی‌اف ملک</span> <span>اسناد و مدارک تصویری / پی‌دی‌اف ملک</span>
</div> </div>
<ImageUploader v-model="documentUrlsWithData" bucketName="documents" :maxFiles="10" /> <ImageUploader v-model="documentUrlsWithData" bucketName="temp" :maxFiles="10" />
<div v-if="documentUrlsWithData && documentUrlsWithData.length > 0" class="pt-2"> <div v-if="documentUrlsWithData && documentUrlsWithData.length > 0" class="pt-2">
<label class="block text-xs font-semibold text-surface-600 dark:text-surface-400 mb-2">فایل‌ها و اسناد بارگذاری‌شده ({{ documentUrlsWithData.length }} مورد)</label> <label class="block text-xs font-semibold text-surface-600 dark:text-surface-400 mb-2">فایل‌ها و اسناد بارگذاری‌شده ({{ documentUrlsWithData.length }} مورد)</label>
<ImageGallery v-model="documentUrlsWithData" galleryId="propertyDocumentsGallery" /> <ImageGallery v-model="documentUrlsWithData" galleryId="propertyDocumentsGallery" />
@@ -904,7 +904,7 @@ const saveProperty = async () => {
<i class="pi pi-image text-xl"></i> <i class="pi pi-image text-xl"></i>
<span>تصاویر ملک</span> <span>تصاویر ملک</span>
</div> </div>
<ImageUploader v-model="mainImageUrlsWithData" bucketName="properties" :maxFiles="10" /> <ImageUploader v-model="mainImageUrlsWithData" bucketName="temp" :maxFiles="10" />
<div v-if="mainImageUrlsWithData && mainImageUrlsWithData.length > 0" class="pt-2"> <div v-if="mainImageUrlsWithData && mainImageUrlsWithData.length > 0" class="pt-2">
<label class="block text-xs font-semibold text-surface-600 dark:text-surface-400 mb-2">گالری تصاویر ({{ mainImageUrlsWithData.length }} مورد)</label> <label class="block text-xs font-semibold text-surface-600 dark:text-surface-400 mb-2">گالری تصاویر ({{ mainImageUrlsWithData.length }} مورد)</label>
<ImageGallery v-model="mainImageUrlsWithData" galleryId="propertyMainImagesGallery" /> <ImageGallery v-model="mainImageUrlsWithData" galleryId="propertyMainImagesGallery" />
+18 -7
View File
@@ -54,7 +54,7 @@ import FilePondPluginImagePreview from 'filepond-plugin-image-preview';
const props = defineProps({ const props = defineProps({
bucketName: { bucketName: {
type: String, type: String,
default: 'properties' default: 'temp'
}, },
uploadEndpoint: { uploadEndpoint: {
type: String, type: String,
@@ -115,7 +115,7 @@ const authHeaders = computed(() => {
const resolvedUploadUrl = computed(() => { const resolvedUploadUrl = computed(() => {
let endpoint = props.uploadUrl || props.uploadEndpoint; let endpoint = props.uploadUrl || props.uploadEndpoint;
if (!endpoint || endpoint === '/api/files/admin/upload-file') { if (!endpoint || endpoint === '/api/files/admin/upload-file') {
endpoint = `/api/files/bucket/upload-single-filepond/${props.bucketName}`; endpoint = `/api/files/bucket/upload-single-filepond/${props.bucketName || 'temp'}`;
} }
if (endpoint.startsWith('http://') || endpoint.startsWith('https://')) { if (endpoint.startsWith('http://') || endpoint.startsWith('https://')) {
return endpoint; return endpoint;
@@ -127,7 +127,7 @@ const resolvedUploadUrl = computed(() => {
const resolvedDeleteUrl = computed(() => { const resolvedDeleteUrl = computed(() => {
let endpoint = props.deleteUrl || props.deleteEndpoint; let endpoint = props.deleteUrl || props.deleteEndpoint;
if (!endpoint) { if (!endpoint) {
endpoint = `/api/files/bucket/delete-file/${props.bucketName}`; endpoint = `/api/files/bucket/delete-file/${props.bucketName || 'temp'}`;
} }
if (endpoint.startsWith('http://') || endpoint.startsWith('https://')) { if (endpoint.startsWith('http://') || endpoint.startsWith('https://')) {
return endpoint; return endpoint;
@@ -136,9 +136,17 @@ const resolvedDeleteUrl = computed(() => {
return `${API_URL}${cleanEndpoint}`; return `${API_URL}${cleanEndpoint}`;
}); });
const initialFiles = computed(() => { const initialFiles = ref([]);
if (!Array.isArray(props.modelValue)) return []; let isInitialLoaded = false;
return props.modelValue
watch(
() => props.modelValue,
(val) => {
// Only populate initialFiles on first load with existing items (e.g. edit mode)
// to avoid resetting active FilePond state during live uploads
if (!isInitialLoaded && Array.isArray(val) && val.length > 0) {
isInitialLoaded = true;
initialFiles.value = val
.map((item) => { .map((item) => {
const url = typeof item === 'string' ? item : item.url || item.source || ''; const url = typeof item === 'string' ? item : item.url || item.source || '';
if (!url) return null; if (!url) return null;
@@ -150,7 +158,10 @@ const initialFiles = computed(() => {
}; };
}) })
.filter(Boolean); .filter(Boolean);
}); }
},
{ immediate: true }
);
// Handle server responses for file processing // Handle server responses for file processing
function handleProcessResponse(response) { function handleProcessResponse(response) {