Skip to content
This repository has been archived by the owner on Apr 23, 2022. It is now read-only.

Service #10

Merged
merged 5 commits into from
Oct 23, 2020
Merged

Service #10

merged 5 commits into from
Oct 23, 2020

Conversation

TheGrinch00
Copy link

  • Added Service Component

  • Added basic checks for props (I just check if some fields are empty because passwords from different websites can have different restrictions, also the username can be either a nickname or a password)

  • Added function to fetch favicon from any website that uses it within a 'link' tag, yet to add other kind of favicons

  • Added base structure to make the actual POST request on the DB, Endpoint is missing and keys for the data to be sent need to be edited in the future to match the correct properties

@powext powext self-requested a review October 21, 2020 21:10
Copy link

@Thanzex Thanzex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!

One last question though:
Shouldn't we use either npm or yarn? As of now the repo contains both yarn.lock and package-lock.json, which can quickly get out of sync between PR, as shown in this one.
I personally suggest using yarn in favour of npm

Comment on lines 41 to 64
let response = await fetch(this.props.serviceUrl)
let data: string = await response.text()

// Match any number of characters between <head> tags. Case-insensitive, including newline
let headContentRegex = /<head>(.*)<\/head>/is
let matches: RegExpExecArray | null = headContentRegex.exec(data)

let headContent = ""

if (matches && matches.length > 0) {
headContent = matches[1]
}

if (!headContent) return ""

/// Matches THE FIRST <link> tag whose [rel] property contains "icon" and extracts the url WITHOUT the domain
let faviconRegex = /<link.*rel=".*icon.*".*href="(.+)".*>/i
matches = faviconRegex.exec(headContent)

let faviconUrl = ""

if (matches && matches.length > 0) {
faviconUrl = `${this.props.serviceUrl}${matches[1]}`
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Google offers a Favicon Snatcher service, by simply fetching
https://www.google.com/s2/favicons?domain=URL
we obtain the favicon of the desired website, this would greatly simplify the process.

Note:
Using Google's service we do not obtain the link to the favicon but the image itself

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check out this API and see if I can use it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked on that API and I found out that Google never intended to distribute that endpoint but it was for internal use only. so it's not safe to use it because they can lock it anytime.
Another option could be https://rapidapi.com/rubycuts/api/grabicon but it's latency times are way too long, at least trying on their example page.

@powext
Copy link
Contributor

powext commented Oct 22, 2020

Nice job!

One last question though:
Shouldn't we use either npm or yarn? As of now the repo contains both yarn.lock and package-lock.json, which can quickly get out of sync between PR, as shown in this one.
I personally suggest using yarn in favour of npm

Yeah, nice point. I'm going to remove package-lock.json

@powext
Copy link
Contributor

powext commented Oct 22, 2020

I just made a refactor of service.tsx, now it is a fnc, also i made a rebase into the origin develop since there were many changes

@powext
Copy link
Contributor

powext commented Oct 23, 2020

@JEToP/hacktoberfest-front-end This service is actually a container of functions that will be useful in the future, IDK if merge it or not

@TheGrinch00
Copy link
Author

TheGrinch00 commented Oct 23, 2020

Those functions are needed only in the Service Component, maybe we could just merge it and wait for the UI part to render it

@powext powext linked an issue Oct 23, 2020 that may be closed by this pull request
3 tasks
@powext powext merged commit 6334d9d into JEToP:develop Oct 23, 2020
@TheGrinch00 TheGrinch00 deleted the service branch October 23, 2020 17:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Service
3 participants