feat: defer preland format validation to api gate
This commit is contained in:
1 parent
4fcb8164df
commit
98db1c2a16
1 file changed
+21
-32
+21
-32
@@ -1,10 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$maxSide = 6000;
|
|
||||||
|
|
||||||
$errorSizeMessage = Yii::t('app', 'Изображение слишком большое ({width}x{height}px). Максимальный размер — {maxSide}px по большей стороне.', [
|
|
||||||
'maxSide' => $maxSide,
|
|
||||||
]);
|
|
||||||
$errorMessage = Yii::t('app', 'Возникла ошибка');
|
$errorMessage = Yii::t('app', 'Возникла ошибка');
|
||||||
$utmJson = json_encode($UTM ?? [], JSON_UNESCAPED_UNICODE);
|
$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">jpg</div>
|
||||||
<div class="dropzone-form-format-item">webp</div>
|
<div class="dropzone-form-format-item">webp</div>
|
||||||
<div class="dropzone-form-format-item">heic</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>
|
</div>
|
||||||
<div class="dropzone-form-action">
|
<div class="dropzone-form-action">
|
||||||
@@ -41,7 +42,7 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
|
|||||||
</div>
|
</div>
|
||||||
</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>
|
</form>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -67,7 +68,6 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
|
|||||||
const redirectUrlUtm = <?= json_encode($redirectUrlUtm, JSON_UNESCAPED_UNICODE) ?>;
|
const redirectUrlUtm = <?= json_encode($redirectUrlUtm, JSON_UNESCAPED_UNICODE) ?>;
|
||||||
const createApiUrl = <?= json_encode($createApiUrl, 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) ?>;
|
const genericErrorMsg = <?= json_encode($errorMessage, JSON_UNESCAPED_UNICODE) ?>;
|
||||||
|
|
||||||
(function initNativeUploader() {
|
(function initNativeUploader() {
|
||||||
@@ -126,7 +126,6 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleSelectedFile(file) {
|
function handleSelectedFile(file) {
|
||||||
const maxSide = 6000;
|
|
||||||
const objectUrl = URL.createObjectURL(file);
|
const objectUrl = URL.createObjectURL(file);
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
|
|
||||||
@@ -134,26 +133,6 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
|
|||||||
const width = img.naturalWidth;
|
const width = img.naturalWidth;
|
||||||
const height = img.naturalHeight;
|
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();
|
form.hide();
|
||||||
swapColumns();
|
swapColumns();
|
||||||
|
|
||||||
@@ -184,11 +163,21 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
|
|||||||
};
|
};
|
||||||
|
|
||||||
img.onerror = () => {
|
img.onerror = () => {
|
||||||
URL.revokeObjectURL(objectUrl);
|
// Browser не обязан декодировать допустимый контейнер. Не отказываем локально:
|
||||||
if (typeof preview !== 'undefined' && preview) {
|
// серверный Tour gate проверит байты и при необходимости даст JPEG-preview.
|
||||||
preview.show();
|
form.hide();
|
||||||
preview.showError(genericErrorMsg);
|
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;
|
img.src = objectUrl;
|
||||||
|
|||||||
Reference in new issue
Block a user