Skip to content

Commit

Permalink
(feat) options
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed May 6, 2024
1 parent 253516d commit 6f81cb5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
46 changes: 38 additions & 8 deletions frontend/src/components/Extractor.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
Free - Online Email Extractor
</p>

<hr class="w-48 h-1 mx-auto bg-gray-500 border-0 rounded my-10" />
<hr class="w-24 h-1 mx-auto bg-gray-500 border-0 rounded my-10" />
<p class="text-center text-slate-400 font-semibold select-none">
<span class=" text-slate-500">Free <b class="text-green-500">online</b> tool to extract emails from any
URL.
Expand All @@ -20,15 +20,14 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;

<div class="max-w-md mx-auto mt-10 select-none">
<div class="relative">
<div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
<div class="absolute inset-y-12 start-0 flex items-center ps-3 pointer-events-none">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round"
d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m5.231 13.481L15 17.25m-4.5-15H5.625c-.621 0-1.125.504-1.125 1.125v16.5c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Zm3.75 11.625a2.625 2.625 0 1 1-5.25 0 2.625 2.625 0 0 1 5.25 0Z" />
</svg>


</div>
<label for="first_name" class="block mb-2 text-sm font-bold text-slate-300">URL to Crawl</label>
<input type="search" x-model="input.url" x-on:change.debounce="extractEmails($event)"
class="block font-mono w-full p-3 ps-10 text-sm text-slate-300 hover:text-slate-100 border border-gray-300 hover:border-gray-100 rounded-lg bg-gray-900 focus:outline-none"
placeholder="https://" required />
Expand All @@ -53,13 +52,39 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
</template>
</button>
</div>
<span x-text="loading.error" class="text-red-300 text-sm font-bold text-center block mt-5"></span>
<pre x-text="loading.errorJSON" class="text-red-200 text-sm text-center block mt-2"></pre>
<div class="pt-10">
<div class="grid gap-6 mb-6 md:grid-cols-2">
<div>
<label for="first_name" class="block mb-2 text-sm font-medium text-slate-500">Depth</label>
<input disabled type="text" class="block font-mono w-full p-3 ps-4 text-sm text-slate-300 hover:text-slate-100 border border-gray-500 hover:border-gray-100 rounded-lg bg-gray-900 focus:outline-none" placeholder="-1" required />
</div>
<div>
<label for="first_name" class="block mb-2 text-sm font-medium text-slate-500">Limit URLs</label>
<input disabled type="text" class="block font-mono w-full p-3 ps-4 text-sm text-slate-300 hover:text-slate-100 border border-gray-500 hover:border-gray-100 rounded-lg bg-gray-900 focus:outline-none" placeholder="100" required />
</div>
<div>
<label for="first_name" class="block mb-2 text-sm font-medium text-slate-500">Limit Emails</label>
<input disabled type="text" class="block font-mono w-full p-3 ps-4 text-sm text-slate-300 hover:text-slate-100 border border-gray-500 hover:border-gray-100 rounded-lg bg-gray-900 focus:outline-none" placeholder="1000" required />
</div>
<div>
<label for="first_name" class="block mb-2 text-sm font-medium text-slate-500">Ignore Queries</label>
<input disabled type="tel" class="block font-mono w-full p-3 ps-4 text-sm text-slate-300 hover:text-slate-100 border border-gray-500 hover:border-gray-100 rounded-lg bg-gray-900 focus:outline-none" placeholder="true" required />
</div>
</div>
</div>
</div>
<br>
<div class="inline-flex items-center justify-center w-full">
<hr class="w-64 h-px my-8 bg-gray-500 border-0 dark:bg-gray-700">
<span class="absolute px-3 py-1 font-bold -translate-x-1/2 left-1/2 text-green-300 bg-slate-900 rounded border-2 border-gray-700">Output</span>
</div>

<span x-text="loading.error" class="text-red-300 text-sm text-center block mt-5"></span>
<div class="text-center text-sm pt-5">
<span class="">CRAWLS #</span><span x-text="loading.counterCrawls"
<span class="font-semibold">CRAWLS #</span><span x-text="loading.counterCrawls"
class=" text-green-300 font-bold"></span>
<span class="pl-5">HITS #</span><span x-text="loading.counterHits"
<span class="font-semibold pl-5">HITS #</span><span x-text="loading.counterHits"
class=" text-green-500 font-bold"></span>
</div>
<div class="text-center text-sm pt-1 block">
Expand Down Expand Up @@ -112,6 +137,7 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
counterCrawls: 0,
counterHits: 0,
error: "",
errorJSON: "",
});
const isURL = (str) => {
const pattern = new RegExp(
Expand All @@ -134,6 +160,7 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
}
if (!isURL(input.url)) {
loading.error = "Input error: Invalid URL";
loading.errorJSON = "";
return;
}
result.data = [];
Expand All @@ -142,14 +169,17 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
loading.counterCrawls = 0;
loading.counterHits = 0;
loading.error = "";
loading.errorJSON = "";

// stream api
const response = await fetch(`${baseURL}/api/extract?url=${input.url}`);
if (!response.ok) {
loading.fetching = false;
loading.url = "";
json = await response.json();
loading.error = "Error: (" + response.status + ") " + response.statusText + " (" + json.error + ")";
jsonString = JSON.stringify(json);
loading.error = response.status + " " + response.statusText;
loading.errorJSON = jsonString;
return;
}
const reader = response.body.getReader();
Expand Down
5 changes: 3 additions & 2 deletions pkg/extract_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func NewExtractHandler() *ExtractHandler {
}

type ExtractorRequest struct {
URL string `json:"url" query:"url" validate:"required" message:"url is required"`
URL string `json:"url" query:"url" validate:"required" message:"url is required"`
Depth int `json:"depth" query:"depth" validate:"numeric" message:"depth must be a number"`
}

func (h *ExtractHandler) Get(c echo.Context) error {
Expand All @@ -51,7 +52,7 @@ func (h *ExtractHandler) Get(c echo.Context) error {
opts := []CrawlOption{
func(o *CrawlOptions) error {
o.TimeoutMillisecond = 1000
o.SleepMillisecond = 0
o.SleepMillisecond = 10
o.URL = req.URL
o.IgnoreQueries = true
o.Depth = -1
Expand Down

0 comments on commit 6f81cb5

Please sign in to comment.