PageSourceSearch

https://pulawy.eu/app/js/cms/component/attachment/pdfConverter.js

js pulawy.eu collected 2026-10-02 20:19:12 UTC 2,269 bytes, 66 lines download raw bytes

1'use strict';
2
3const fileToPdfHandler = function (event) {
4    event.preventDefault();
5    const target = event.target.closest('[data-filetopdf-token]');
6    if (!target) {
7        return;
8    }
9
10    const userToken = target.getAttribute('data-filetopdf-token');
11    const currentDomain = window.location.origin; // Pobierz domenę z aktualnego URL
12    const fileUrl = currentDomain + target.getAttribute('data-href');
13
14    const fileName = fileUrl.substring(fileUrl.lastIndexOf('/') + 1);
15    const fileNameWithPdfExtension = fileName.replace(/\.[^/.]+$/, '.pdf');
16
17    const headers = new Headers({
18        'UserToken': userToken
19    });
20
21    const body = new URLSearchParams({
22        fileSource: fileUrl, // Wysłanie zakodowanego URL
23        fileName: fileNameWithPdfExtension,
24        inline: true
25    });
26
27    let dialog = bootbox.dialog({
28        message: '<div class="text-center"><i class="fa fas fa-spin fa-spinner"></i> Generowanie wersji PDF...</div>',
29        closeButton: true,
30        onEscape: true,
31        backdrop: true,
32    });
33
34    // Wyślij żądanie i obsłuż odpowiedź jako 'Blob'
35    fetch('https://fileconvert.bit-sa.pl/convertToPdf', {
36        method: 'POST',
37        headers: headers,
38        body: body
39    }).then(response => {
40        if (!response.ok) {
41            throw new Error(`Błąd HTTP! status: ${response.status}`);
42        }
43        return response.blob(); // Parsuj odpowiedź jako Blob
44    }).then(blob => {
45        // Utwórz URL do pobranej zawartości
46        const blobUrl = URL.createObjectURL(blob);
47
48        // Otwórz plik w nowym oknie/zakładce
49        window.open(blobUrl, '_blank');
50        dialog.modal('hide');
51        // (Opcjonalnie) Automatyczne usuwanie URL po określonym czasie
52        setTimeout(() => URL.revokeObjectURL(blobUrl), 60000); // Zwolnij URL po 1 minucie
53    })
54        .catch(error => {
55            console.error('Błąd generowania PDF:', error);
56            dialog.modal('hide');
57        });
58};
59
60document.addEventListener('DOMContentLoaded', () => {
61    // Podepnij handler do elementów
62    const pdfConvertElements = document.querySelectorAll('[data-filetopdf-token]');
63    pdfConvertElements.forEach(element => {
64		element.addEventListener('click', fileToPdfHandler);
65    });
66});

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.