feat: defer preland format validation to api gate

This commit is contained in:
Panfilov Konstantin committed 2026-10-14 21:03:46 +03:00
1 parent 4fcb8164df
commit 98db1c2a16
1 file changed
+21 -32
+21 -32
View File
@@ -1,10 +1,5 @@
<?php
$maxSide = 6000;
$errorSizeMessage = Yii::t('app', 'Изображение слишком большое ({width}x{height}px). Максимальный размер — {maxSide}px по большей стороне.', [
'maxSide' => $maxSide,
]);
$errorMessage = Yii::t('app', 'Возникла ошибка');
$utmJson = json_encode($UTM ?? [], JSON_UNESCAPED_UNICODE);
@@ -29,6 +24,12 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
<div class="dropzone-form-format-item">jpg</div>
<div class="dropzone-form-format-item">webp</div>
<div class="dropzone-form-format-item">heic</div>
<div class="dropzone-form-format-item">gif</div>
<div class="dropzone-form-format-item">tiff</div>
<div class="dropzone-form-format-item">bmp</div>
<div class="dropzone-form-format-item">avif</div>
<div class="dropzone-form-format-item">jxl</div>
<div class="dropzone-form-format-item">dng</div>
</div>
</div>
<div class="dropzone-form-action">
@@ -41,7 +42,7 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
</div>
</div>
<input type="file" id="dropzone-file-input" name="file" accept="image/jpeg,image/png,image/jpg,image/webp,image/heic,.heic" style="display: none;">
<input type="file" id="dropzone-file-input" name="file" accept=".jpg,.jpeg,.png,.webp,.heic,.heif,.gif,.tif,.tiff,.bmp,.avif,.jxl,.dng,.pdf" style="display: none;">
</form>
<script>
@@ -67,7 +68,6 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
const redirectUrlUtm = <?= json_encode($redirectUrlUtm, JSON_UNESCAPED_UNICODE) ?>;
const createApiUrl = <?= json_encode($createApiUrl, JSON_UNESCAPED_UNICODE) ?>;
const errorSizeTpl = <?= json_encode($errorSizeMessage, JSON_UNESCAPED_UNICODE) ?>;
const genericErrorMsg = <?= json_encode($errorMessage, JSON_UNESCAPED_UNICODE) ?>;
(function initNativeUploader() {
@@ -126,7 +126,6 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
}
function handleSelectedFile(file) {
const maxSide = 6000;
const objectUrl = URL.createObjectURL(file);
const img = new Image();
@@ -134,26 +133,6 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
const width = img.naturalWidth;
const height = img.naturalHeight;
if (width > maxSide || height > maxSide) {
URL.revokeObjectURL(objectUrl);
fileInput.value = '';
const msg = errorSizeTpl
.replace('{width}', width)
.replace('{height}', height);
form.show();
if (typeof preview !== 'undefined' && preview) {
const col7 = document.querySelector('.col-md-7');
if (col7) col7.appendChild(preview.el);
preview.show();
preview.showError(msg);
}
if (typeof process !== 'undefined' && process) process.hide();
if (typeof examples !== 'undefined' && examples) examples.hide();
return;
}
form.hide();
swapColumns();
@@ -184,11 +163,21 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
};
img.onerror = () => {
URL.revokeObjectURL(objectUrl);
if (typeof preview !== 'undefined' && preview) {
preview.show();
preview.showError(genericErrorMsg);
// Browser не обязан декодировать допустимый контейнер. Не отказываем локально:
// серверный Tour gate проверит байты и при необходимости даст JPEG-preview.
form.hide();
swapColumns();
if (typeof process !== 'undefined' && process) {
const col5 = document.querySelector('.col-md-5');
if (col5) col5.appendChild(process.el);
process.setFilename(file.name);
process.setSize(file.size);
process.setDimensions(0, 0);
process.setStage(0);
process.setStatus(0);
process.show();
}
uploadFile(file);
};
img.src = objectUrl;