PageSourceSearch

https://cdn.infourok.ru/assets/helpers/ai-pending-action/index-bnPbmnK.js

js infourok.ru collected 2026-09-24 08:51:14 UTC 5,444 bytes, 145 lines download raw bytes

1/// <reference path="../../../../global.d.ts" />
2/// <reference path="../../../../iu.d.ts" />
3function _class_call_check(instance, Constructor) {
4    if (!(instance instanceof Constructor)) {
5        throw new TypeError("Cannot call a class as a function");
6    }
7}
8function _defineProperties(target, props) {
9    for(var i = 0; i < props.length; i++){
10        var descriptor = props[i];
11        descriptor.enumerable = descriptor.enumerable || false;
12        descriptor.configurable = true;
13        if ("value" in descriptor) descriptor.writable = true;
14        Object.defineProperty(target, descriptor.key, descriptor);
15    }
16}
17function _create_class(Constructor, protoProps, staticProps) {
18    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
19    if (staticProps) _defineProperties(Constructor, staticProps);
20    return Constructor;
21}
22function _define_property(obj, key, value) {
23    if (key in obj) {
24        Object.defineProperty(obj, key, {
25            value: value,
26            enumerable: true,
27            configurable: true,
28            writable: true
29        });
30    } else {
31        obj[key] = value;
32    }
33    return obj;
34}
35import { v4 as uuidv4 } from "uuid";
36import { setHiddenInput, snapshotForm } from "./form-snapshot.js";
37import { submitPendingAction, UNEXPECTED_ERROR_MESSAGE } from "./http.js";
38import { buildResumeUrl, consumeResumeIdFromCurrentUrl, IDEMPOTENCY_KEY_PARAM, normalizeAiActionUrl, RESUME_ID_PARAM, RESUME_URL_PARAM } from "./resume-url.js";
39import { buildAction, onActionRemoved, removeAction, saveAction, takeAction } from "./storage.js";
40var resumedIds = new Set();
41var activeResume = null;
42var PENDING_ACTION_EXPIRED_MESSAGE = "Запрос устарел. Отправьте его повторно.";
43var PENDING_ACTION_UNAVAILABLE_MESSAGE = "Не удалось восстановить запрос после входа. Отправьте его повторно.";
44export function createAiPendingAction(form) {
45    var action = normalizeAiActionUrl(form.action);
46    if (action === null) {
47        return null;
48    }
49    var id = uuidv4();
50    var idempotencyKey = uuidv4();
51    setHiddenInput(form, RESUME_ID_PARAM, id);
52    setHiddenInput(form, RESUME_URL_PARAM, buildResumeUrl(id));
53    setHiddenInput(form, IDEMPOTENCY_KEY_PARAM, idempotencyKey);
54    return buildAction(id, action, snapshotForm(form), idempotencyKey);
55}
56export function saveAiPendingAction(action) {
57    saveAction(action);
58}
59export function removeAiPendingAction(id) {
60    removeAction(id);
61}
62export function resumeAiPendingActionOnLoad() {
63    var resumeId = consumeResumeIdFromCurrentUrl();
64    if (resumeId === null || resumedIds.has(resumeId)) {
65        return activeResume;
66    }
67    resumedIds.add(resumeId);
68    var _takeAction = takeAction(resumeId), action = _takeAction.action, reason = _takeAction.reason;
69    if (reason === "expired") {
70        iu.popup.error(PENDING_ACTION_EXPIRED_MESSAGE);
71        return null;
72    }
73    if (action === null || normalizeAiActionUrl(action.action) === null) {
74        iu.popup.error(PENDING_ACTION_UNAVAILABLE_MESSAGE);
75        return null;
76    }
77    var abortController = new AbortController();
78    var cancelResume = function() {
79        return abortController.abort();
80    };
81    document.addEventListener("turbo:visit", cancelResume);
82    document.addEventListener("turbo:before-cache", cancelResume);
83    window.addEventListener("beforeunload", cancelResume);
84    var resume = submitPendingAction(action, abortController.signal).catch(function() {
85        if (!abortController.signal.aborted) {
86            iu.popup.error(UNEXPECTED_ERROR_MESSAGE);
87        }
88    }).finally(function() {
89        document.removeEventListener("turbo:visit", cancelResume);
90        document.removeEventListener("turbo:before-cache", cancelResume);
91        window.removeEventListener("beforeunload", cancelResume);
92        if (activeResume === resume) {
93            activeResume = null;
94        }
95    });
96    activeResume = resume;
97    return activeResume;
98}
99export var PendingActionLifecycle = /*#__PURE__*/ function() {
100    "use strict";
101    function PendingActionLifecycle(form) {
102        _class_call_check(this, PendingActionLifecycle);
103        _define_property(this, "form", void 0);
104        _define_property(this, "id", void 0);
105        this.form = form;
106        this.id = null;
107    }
108    _create_class(PendingActionLifecycle, [
109        {
110            key: "prepare",
111            value: function prepare() {
112                this.clear();
113                var action = createAiPendingAction(this.form);
114                if (action === null) {
115                    return;
116                }
117                this.id = action.id;
118                saveAiPendingAction(action);
119            }
120        },
121        {
122            key: "clear",
123            value: function clear() {
124                if (this.id === null) {
125                    return;
126                }
127                removeAiPendingAction(this.id);
128                this.id = null;
129            }
130        },
131        {
132            key: "handOffToNewTab",
133            value: function handOffToNewTab() {
134                if (this.id === null) {
135                    return;
136                }
137                onActionRemoved(this.id, function() {
138                    return window.location.reload();
139                });
140                this.id = null;
141            }
142        }
143    ]);
144    return PendingActionLifecycle;
145}();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.