Загрузка: client_key и переход на /api/images/public/claim вместо /public/upscale
После загрузки посетитель попадал на /public/upscale?id=… и видел 404: XHR с преленда кросс-доменный, и сессия, в которой сайт запомнил загрузку, посетителю на сайте недоступна (куки третьей стороны изолированы или не приняты). Теперь вместе с файлом уходит client_key (crypto.randomUUID, иначе 16 байт getRandomValues), а после ответа браузер идёт на https://<сайт>/api/images/public/claim?key=<ключ>&<метки>: сайт кладёт загрузку в сессию посетителя и ведёт на /public/upscale (ключ годен 30 мин). Нужен api с ClaimAction (fix/preland-claim). Проверка — .extras/checks-preland-claim/t_preland.sh в рабочей области (index.php в php:8.3-cli, скрипт формы в node:22): до правки FAIL=3, после 5/5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
792676e974
commit
9ce010f5c1
2 files changed
+11
-3
No files matched your search
+8
-2
@@ -197,7 +197,13 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
|
|||||||
function uploadFile(file) {
|
function uploadFile(file) {
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
// Ключ загрузки: по нему сайт передаёт её в сессию посетителя (/api/images/public/claim, годен 30 мин).
|
||||||
|
// randomUUID есть в HTTPS-контексте; где его нет (старый Safari), есть getRandomValues.
|
||||||
|
const clientKey = crypto.randomUUID
|
||||||
|
? crypto.randomUUID()
|
||||||
|
: Array.from(crypto.getRandomValues(new Uint8Array(16)), (b) => b.toString(16).padStart(2, '0')).join('');
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
|
formData.append('client_key', clientKey);
|
||||||
|
|
||||||
const actionUrl = createApiUrl || formEl.getAttribute('action') || '/api/images/public/create';
|
const actionUrl = createApiUrl || formEl.getAttribute('action') || '/api/images/public/create';
|
||||||
xhr.open('POST', actionUrl, true);
|
xhr.open('POST', actionUrl, true);
|
||||||
@@ -232,8 +238,8 @@ $redirectUrlUtm = $redirect_url_utm ?? '';
|
|||||||
process.setStage(1);
|
process.setStage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build redirect target URL: $redirect_url_base . $imageId . ($redirect_url_utm ? '&' . $redirect_url_utm : '')
|
// Переход: $redirect_url_base . client_key . ($redirect_url_utm ? '&' . $redirect_url_utm : '')
|
||||||
let targetUrl = redirectUrlBase + encodeURIComponent(imageId);
|
let targetUrl = redirectUrlBase + encodeURIComponent(clientKey);
|
||||||
if (redirectUrlUtm) {
|
if (redirectUrlUtm) {
|
||||||
// const sep = targetUrl.includes('?') ? '&' : '?';
|
// const sep = targetUrl.includes('?') ? '&' : '?';
|
||||||
targetUrl += '&' + redirectUrlUtm;
|
targetUrl += '&' + redirectUrlUtm;
|
||||||
|
|||||||
@@ -71,7 +71,9 @@ $UTM = $get_params;
|
|||||||
$host = $config['host'] ?? ($_SERVER['HTTP_HOST'] ?? '');
|
$host = $config['host'] ?? ($_SERVER['HTTP_HOST'] ?? '');
|
||||||
$apiHost = $host ? (preg_match('#^https?://#', $host) ? rtrim($host, '/') : 'https://' . rtrim($host, '/')) : '';
|
$apiHost = $host ? (preg_match('#^https?://#', $host) ? rtrim($host, '/') : 'https://' . rtrim($host, '/')) : '';
|
||||||
|
|
||||||
$redirect_url_base = ($apiHost ? $apiHost : '') . '/public/upscale?id=';
|
// После загрузки — на сайт по ключу загрузки (client_key): /api/images/public/claim кладёт её в сессию посетителя и ведёт
|
||||||
|
// на /public/upscale. Сразу на /public/upscale нельзя: сессия кросс-доменной загрузки посетителю на сайте недоступна — 404.
|
||||||
|
$redirect_url_base = ($apiHost ? $apiHost : '') . '/api/images/public/claim?key=';
|
||||||
$redirect_url_utm = http_build_query($get_params);
|
$redirect_url_utm = http_build_query($get_params);
|
||||||
|
|
||||||
$assetsUriPrefix = $config['assetsUriPrefix'] ?? '';
|
$assetsUriPrefix = $config['assetsUriPrefix'] ?? '';
|
||||||
|
|||||||
Reference in new issue
Block a user