-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
379091c
commit 57c206c
Showing
6 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { FetchIconResponse } from "./types"; | ||
|
||
export async function fetchIcons(searchTerm: string): Promise<Array<FetchIconResponse>> { | ||
const url = `https://hammerhead-app-fj5ps.ondigitalocean.app/icons?term=${searchTerm}&family-id=300&filters[shape]=outline&filters[color]=solid-black&filters[free_svg]=premium`; | ||
const requestHeaders = new Headers(); | ||
requestHeaders.append("X-Freepik-API-Key", "XXX"); | ||
const requestOptions = { | ||
method: "GET", | ||
headers: requestHeaders, | ||
}; | ||
|
||
try { | ||
const result = await fetch(url, requestOptions); | ||
const response = await result.json(); | ||
return response.data | ||
.filter((obj) => obj.author.name === "Smashicons" && obj.family.name === "Basic Miscellany Lineal") | ||
.map((obj) => ({ | ||
id: obj.id.toString(), | ||
url: obj.thumbnails[0].url, | ||
})) | ||
.slice(0, 50); | ||
} catch (e) { | ||
throw new Error("Error fetching icons: " + e); | ||
} | ||
} | ||
|
||
export async function getDownloadPathForIconWith(id: string) { | ||
const url = `https://hammerhead-app-fj5ps.ondigitalocean.app/icons/${id}/download?format=png`; | ||
const requestHeaders = new Headers(); | ||
requestHeaders.append("X-Freepik-API-Key", "XXX"); | ||
const requestOptions = { | ||
method: "GET", | ||
headers: requestHeaders, | ||
}; | ||
|
||
try { | ||
const result = await fetch(url, requestOptions); | ||
const response = await result.json(); | ||
return response.data.url; | ||
} catch (e) { | ||
throw new Error("Error getting download url: " + e); | ||
} | ||
} | ||
|
||
export async function downloadIconWith(url: string) { | ||
const requestOptions = { | ||
method: "GET", | ||
}; | ||
|
||
try { | ||
return await fetch(url, requestOptions); | ||
} catch (e) { | ||
throw new Error("Error downloading icon: " + e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type FetchIconResponse = { | ||
id: string; | ||
url: string; | ||
}; |