Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.9 kB
1
Indexable
Never
import {loadpdfInClient,parsepdfpage} from "https://deno.land/x/pdf_parser@v1.1.2/main.compress.js";

const loginUrl = "https://diesel24portal.com/api/login";


// Define the login request body
const requestBody: string =
    "username=erdbewegung-gasser@gmx.at&password=mZmpX!7%23VB7V4N";

// Send the login request to the API
const response = await fetch(loginUrl, {
    method: "POST",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded",
    },
    body: requestBody,
});

// Check the response status code and handle accordingly
if (response.status === 200) {
    // Login successful
    const responseBody = await response.text();
    console.log("Login successful. Access token:", responseBody);

    getFileContent(responseBody)
        .then((fileContent: string) => {
            console.log("Parsing");
            console.log(fileContent);
        })
        .catch((err) => {
            console.log("Failed during fetch of file" + err);
        })
        
} else {
    // Login failed
    console.log("Login failed. Status code:", response.status);
}
export { };

function getFileContent(token: string): Promise<string> {
    let prom = new Promise<string>(async function(resolve, reject){
        const response = await fetch("https://diesel24portal.com/api/priceList/file/21462/0", {
            method: "GET",
            headers: {
                "Authorization": "Bearer " + token,
            }
        });

        if (response.status === 200) {
            // Login successful
            const responseBody = await response.text();
                    
            resolve(responseBody);
        } else {
            // Login failed
            console.log("Login failed. Status code:", response.status);
            reject();
        }
        });

    return prom;
}