Download buttons for screenshots
This commit is contained in:
parent
895260b096
commit
fae0a8d8b7
|
@ -5,12 +5,6 @@ h1 {
|
||||||
margin-bottom: calc(24 / 16 * 1rem);
|
margin-bottom: calc(24 / 16 * 1rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
.generator-container {
|
|
||||||
max-width: 100ex;
|
|
||||||
margin: 0 auto;
|
|
||||||
font-size: calc(14 / 16 * 1rem);
|
|
||||||
}
|
|
||||||
|
|
||||||
.mail-container {
|
.mail-container {
|
||||||
box-shadow: rgba(12, 12, 13, 0.1) 0px 1px 4px 0px;
|
box-shadow: rgba(12, 12, 13, 0.1) 0px 1px 4px 0px;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
|
@ -53,3 +47,28 @@ h1 {
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.buttons-email-container {
|
||||||
|
display: grid;
|
||||||
|
grid-gap: 1rem;
|
||||||
|
grid-template-columns: 1fr 1fr 1fr 1fr;
|
||||||
|
margin: 2rem 0;
|
||||||
|
padding: 1em 0;
|
||||||
|
|
||||||
|
&--single {
|
||||||
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sv_prev_btn,
|
||||||
|
.sv_next_btn {
|
||||||
|
margin: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sv_prev_btn {
|
||||||
|
grid-column: 2/3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sv_next_btn--single {
|
||||||
|
grid-column: 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,14 +8,20 @@ import { Fragment, useState } from 'react';
|
||||||
import emailIntro from './email-intro';
|
import emailIntro from './email-intro';
|
||||||
import { reportIntro } from './report-intro';
|
import { reportIntro } from './report-intro';
|
||||||
|
|
||||||
|
const SS_URL = 'http://65.108.60.135:3000';
|
||||||
|
|
||||||
export default function EmailContent({
|
export default function EmailContent({
|
||||||
answers,
|
answers,
|
||||||
visited_url,
|
visited_url,
|
||||||
clusters,
|
clusters,
|
||||||
|
scrRequestPath,
|
||||||
|
downloadFiles,
|
||||||
}: {
|
}: {
|
||||||
answers: ParsedAnswers;
|
answers: ParsedAnswers;
|
||||||
visited_url: string;
|
visited_url: string;
|
||||||
clusters: Record<string, RequestCluster>;
|
clusters: Record<string, RequestCluster>;
|
||||||
|
scrRequestPath: string;
|
||||||
|
downloadFiles: Function;
|
||||||
}) {
|
}) {
|
||||||
console.log('rendering email!', answers);
|
console.log('rendering email!', answers);
|
||||||
const _ = (key: string) => v(key, answers.zaimek);
|
const _ = (key: string) => v(key, answers.zaimek);
|
||||||
|
@ -88,9 +94,28 @@ export default function EmailContent({
|
||||||
)}
|
)}
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
<div className="buttons-container">
|
<div
|
||||||
<button className="sv_next_btn" onClick={() => copyTextToClipboard()}>
|
className={
|
||||||
{copied ? 'Skopiowano!' : 'Kopiuj treść wiadomości'}
|
scrRequestPath
|
||||||
|
? 'buttons-email-container'
|
||||||
|
: 'buttons-email-container buttons-email-container--single'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{scrRequestPath ? (
|
||||||
|
<button
|
||||||
|
className="sv_prev_btn"
|
||||||
|
onClick={() => downloadFiles(`${SS_URL}${scrRequestPath}`)}
|
||||||
|
>
|
||||||
|
Pobierz zrzuty ekranów
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
<button
|
||||||
|
className={
|
||||||
|
scrRequestPath ? 'sv_next_btn' : 'sv_next_btn sv_next_btn--single'
|
||||||
|
}
|
||||||
|
onClick={() => copyTextToClipboard()}
|
||||||
|
>
|
||||||
|
{copied ? 'Skopiowano!' : 'Kopiuj treść'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{copied ? (
|
{copied ? (
|
||||||
|
|
|
@ -274,3 +274,14 @@ h1 {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: calc(14 / 16 * 1rem);
|
font-size: calc(14 / 16 * 1rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.generator-container {
|
||||||
|
max-width: 100ex;
|
||||||
|
margin: 0 auto;
|
||||||
|
font-size: calc(14 / 16 * 1rem);
|
||||||
|
margin-top: 3rem;
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: $ultra-black-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,14 @@ import EmailContent from './email-content';
|
||||||
import { parseAnswers, ParsedAnswers } from './parse-answers';
|
import { parseAnswers, ParsedAnswers } from './parse-answers';
|
||||||
import ScreenshotGenerator from './screenshot-generator';
|
import ScreenshotGenerator from './screenshot-generator';
|
||||||
|
|
||||||
|
function downloadFiles(link: string) {
|
||||||
|
let a = document.createElement('a');
|
||||||
|
a.setAttribute('href', link);
|
||||||
|
a.setAttribute('download', '');
|
||||||
|
a.setAttribute('target', '_blank');
|
||||||
|
a.click();
|
||||||
|
}
|
||||||
|
|
||||||
function Report() {
|
function Report() {
|
||||||
try {
|
try {
|
||||||
const url = new URL(document.location.toString());
|
const url = new URL(document.location.toString());
|
||||||
|
@ -18,6 +26,8 @@ function Report() {
|
||||||
url.searchParams.get('answers') ? JSON.parse(url.searchParams.get('answers')) : null
|
url.searchParams.get('answers') ? JSON.parse(url.searchParams.get('answers')) : null
|
||||||
);
|
);
|
||||||
const [mode, setMode] = React.useState(url.searchParams.get('mode') || 'survey');
|
const [mode, setMode] = React.useState(url.searchParams.get('mode') || 'survey');
|
||||||
|
const [scrRequestPath, setScrRequestPath] = React.useState('');
|
||||||
|
|
||||||
const clusters = getMemory().getClustersForOrigin(origin);
|
const clusters = getMemory().getClustersForOrigin(origin);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
@ -48,13 +58,30 @@ function Report() {
|
||||||
)}
|
)}
|
||||||
{mode === 'screenshots' ? (
|
{mode === 'screenshots' ? (
|
||||||
<ScreenshotGenerator
|
<ScreenshotGenerator
|
||||||
{...{ visited_url, clusters, setReportWindowMode: setMode }}
|
{...{
|
||||||
|
visited_url,
|
||||||
|
clusters,
|
||||||
|
setReportWindowMode: setMode,
|
||||||
|
setRequestPath: setScrRequestPath,
|
||||||
|
downloadFiles: downloadFiles,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
''
|
||||||
|
)}
|
||||||
|
{mode === 'preview' ? (
|
||||||
|
<EmailContent
|
||||||
|
{...{
|
||||||
|
answers,
|
||||||
|
visited_url,
|
||||||
|
clusters,
|
||||||
|
scrRequestPath,
|
||||||
|
downloadFiles: downloadFiles,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
''
|
''
|
||||||
)}
|
)}
|
||||||
{mode === 'preview' ? <EmailContent {...{ answers, visited_url, clusters }} /> : ''}
|
|
||||||
{/* <HARConverter {...{ entries }} /> */}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -23,16 +23,6 @@ h2 {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.generator-container {
|
|
||||||
max-width: 100ex;
|
|
||||||
margin: 0 auto;
|
|
||||||
font-size: calc(14 / 16 * 1rem);
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: $ultra-black-color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.buttons-container {
|
.buttons-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
|
@ -13,16 +13,25 @@ enum taskState {
|
||||||
type Screenshot = {
|
type Screenshot = {
|
||||||
url: string;
|
url: string;
|
||||||
domain: string;
|
domain: string;
|
||||||
|
filename: string;
|
||||||
found_headers: string[];
|
found_headers: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
interface screenshotTask {
|
interface screenshotTask {
|
||||||
url: string;
|
|
||||||
domains: string[];
|
domains: string[];
|
||||||
|
elapsed_time_s: number;
|
||||||
|
finished_time: number;
|
||||||
id: string;
|
id: string;
|
||||||
status: taskState;
|
|
||||||
output: string;
|
|
||||||
images: Screenshot[];
|
images: Screenshot[];
|
||||||
|
jobs_ahead: number;
|
||||||
|
output: string;
|
||||||
|
processing_took: number;
|
||||||
|
request_time: number;
|
||||||
|
started_time: number;
|
||||||
|
status: taskState;
|
||||||
|
url: string;
|
||||||
|
waiting_took: number;
|
||||||
|
zip_url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTaskEndpoint(visited_url: string, domains: string[]) {
|
function createTaskEndpoint(visited_url: string, domains: string[]) {
|
||||||
|
@ -44,14 +53,19 @@ export default function ScreenshotGenerator({
|
||||||
visited_url,
|
visited_url,
|
||||||
clusters,
|
clusters,
|
||||||
setReportWindowMode,
|
setReportWindowMode,
|
||||||
|
setRequestPath,
|
||||||
|
downloadFiles,
|
||||||
}: {
|
}: {
|
||||||
visited_url: string;
|
visited_url: string;
|
||||||
clusters: Record<string, RequestCluster>;
|
clusters: Record<string, RequestCluster>;
|
||||||
setReportWindowMode: Function;
|
setReportWindowMode: Function;
|
||||||
|
setRequestPath: Function;
|
||||||
|
downloadFiles: Function;
|
||||||
}) {
|
}) {
|
||||||
const [mode, setMode] = React.useState<string>('idle');
|
const [mode, setMode] = React.useState<string>('idle');
|
||||||
const [images, setImages] = React.useState<Screenshot[]>([]);
|
const [images, setImages] = React.useState<Screenshot[]>([]);
|
||||||
const [taskId, setTaskId] = React.useState<string>(null);
|
const [taskId, setTaskId] = React.useState<string>(null);
|
||||||
|
const [output, setOutput] = React.useState<any>({});
|
||||||
|
|
||||||
async function subscribeTask(path: string): Promise<screenshotTask> {
|
async function subscribeTask(path: string): Promise<screenshotTask> {
|
||||||
let response = { status: taskState.WAITING };
|
let response = { status: taskState.WAITING };
|
||||||
|
@ -71,19 +85,6 @@ export default function ScreenshotGenerator({
|
||||||
return response as screenshotTask;
|
return response as screenshotTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadFiles() {
|
|
||||||
const urls = images.map((el) => `${SS_URL}${el}`);
|
|
||||||
|
|
||||||
for (const url of urls) {
|
|
||||||
let a = document.createElement('a');
|
|
||||||
a.setAttribute('href', url);
|
|
||||||
a.setAttribute('download', '');
|
|
||||||
a.setAttribute('target', '_blank');
|
|
||||||
a.click();
|
|
||||||
}
|
|
||||||
setReportWindowMode('preview');
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="generator-container">
|
<div className="generator-container">
|
||||||
{mode === 'idle' ? (
|
{mode === 'idle' ? (
|
||||||
|
@ -108,6 +109,7 @@ export default function ScreenshotGenerator({
|
||||||
className="sv_prev_btn"
|
className="sv_prev_btn"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setReportWindowMode('preview');
|
setReportWindowMode('preview');
|
||||||
|
setRequestPath(null);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Pomiń
|
Pomiń
|
||||||
|
@ -123,6 +125,9 @@ export default function ScreenshotGenerator({
|
||||||
setImages(response.images);
|
setImages(response.images);
|
||||||
console.log('response.images', response.images);
|
console.log('response.images', response.images);
|
||||||
console.log('output', response);
|
console.log('output', response);
|
||||||
|
|
||||||
|
setOutput(response);
|
||||||
|
setRequestPath(response.zip_url);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Wygeneruj
|
Wygeneruj
|
||||||
|
@ -186,7 +191,13 @@ export default function ScreenshotGenerator({
|
||||||
<div className="buttons-container">
|
<div className="buttons-container">
|
||||||
{mode === 'finished' ? (
|
{mode === 'finished' ? (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<button className="sv_next_btn" onClick={() => downloadFiles()}>
|
<button
|
||||||
|
className="sv_next_btn"
|
||||||
|
onClick={() => {
|
||||||
|
downloadFiles(`${SS_URL}${output.zip_url}`);
|
||||||
|
setReportWindowMode('preview');
|
||||||
|
}}
|
||||||
|
>
|
||||||
Pobierz zrzuty ekranów i przejdź dalej
|
Pobierz zrzuty ekranów i przejdź dalej
|
||||||
</button>
|
</button>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user