Commit 508634488a
508634488a2019283c0394df03ed1303656c8449
parent: 3a1ec913fb
Unsigned
Alicia Sykes <alicia@omg.lol> · 2024-03-08 07:37 UTC
Render DockerHub info for apps published there
Layout: unified · split
web/src/components/things/DockerDetailedInfo.astro
added
+178
| @@ -0,0 +1,178 @@ |
| 1 | --- |
| 2 | import type { TemplateResponse } from '@utils/fetch-docker-instructions'; |
| 3 | import { formatDate, timeAgo } from '@utils/dates-n-stuff'; |
| 4 | |
| 5 | interface Props { |
| 6 | docker: TemplateResponse; |
| 7 | } |
| 8 | |
| 9 | const { docker } = Astro.props; |
| 10 | |
| 11 | const formatBigNumber = (num: number): string => { |
| 12 | if (!num) return 'None'; |
| 13 | return num.toLocaleString(); |
| 14 | }; |
| 15 | |
| 16 | --- |
| 17 | |
| 18 | <div class="docker-info-wrap"> |
| 19 | |
| 20 | <div class="left"> |
| 21 | { docker.template && ( |
| 22 | <h4>Container Info</h4> |
| 23 | <p class="dockerhub-title"> |
| 24 | <img src={docker.template.logo} width="16" /> |
| 25 | {docker.template.name} |
| 26 | </p> |
| 27 | <p class="dockerhub-description">{docker.template.description}</p> |
| 28 | <span class="tags"> |
| 29 | {(docker.template.categories || []).map((category: string) => ( |
| 30 | <span class="tag">#{category}</span> |
| 31 | ))} |
| 32 | </span> |
| 33 | )} |
| 34 | |
| 35 | {docker.dockerHubData && Object.keys(docker.dockerHubData).length > 0 && ( |
| 36 | <h4>DockerHub Metrics</h4> |
| 37 | <ul class="table"> |
| 38 | <li> |
| 39 | <span class="lbl">Pull Count</span> |
| 40 | <span class="val">{formatBigNumber(docker.dockerHubData.pull_count)}</span> |
| 41 | </li> |
| 42 | <li> |
| 43 | <span class="lbl">Stars</span> |
| 44 | <span class="val">{formatBigNumber(docker.dockerHubData.star_count)}</span> |
| 45 | </li> |
| 46 | <li> |
| 47 | <span class="lbl">Date Created</span> |
| 48 | <span class="val">{formatDate(docker.dockerHubData.date_registered)}</span> |
| 49 | </li> |
| 50 | <li> |
| 51 | <span class="lbl">Last Updated</span> |
| 52 | <span class="val">{timeAgo(docker.dockerHubData.last_updated)}</span> |
| 53 | </li> |
| 54 | </ul> |
| 55 | )} |
| 56 | |
| 57 | <h4>View on DockerHub</h4> |
| 58 | {docker.dockerHubData && Object.keys(docker.dockerHubData).length > 0 && ( |
| 59 | <a href={`https://hub.docker.com/r/${docker.dockerHubData.user}/${docker.dockerHubData.name}`} target="_blank"> |
| 60 | {docker.dockerHubData.user}/{docker.dockerHubData.name} |
| 61 | </a> |
| 62 | )} |
| 63 | |
| 64 | {!docker.dockerHubData && docker.template && |
| 65 | ( |
| 66 | <a href={`https://hub.docker.com/r/${docker.template.image}`} target="_blank"> |
| 67 | {docker.template.image} |
| 68 | </a> |
| 69 | ) |
| 70 | } |
| 71 | |
| 72 | </div> |
| 73 | <div class="right"> |
| 74 | {docker.usage && ( |
| 75 | <h4>Run Command</h4> |
| 76 | <pre>{docker.usage.dockerRunCommand}</pre> |
| 77 | )} |
| 78 | |
| 79 | </div> |
| 80 | </div> |
| 81 | |
| 82 | <style lang="scss"> |
| 83 | .docker-info-wrap { |
| 84 | display: flex; |
| 85 | flex-wrap: wrap; |
| 86 | justify-content: space-between; |
| 87 | .left, .right { |
| 88 | width: 50%; |
| 89 | @media (max-width: 768px) { |
| 90 | width: 100%; |
| 91 | } |
| 92 | } |
| 93 | .long-list-data { |
| 94 | width: 100%; |
| 95 | display: flex; |
| 96 | flex-wrap: wrap; |
| 97 | justify-content: space-between; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | .left { |
| 102 | .dockerhub-title, .dockerhub-description { |
| 103 | font-size: 0.9rem; |
| 104 | opacity: 0.8; |
| 105 | display: -webkit-box; |
| 106 | -webkit-line-clamp: 1; |
| 107 | -webkit-box-orient: vertical; |
| 108 | overflow: hidden; |
| 109 | border-left: 2px solid var(--accent-3); |
| 110 | padding-left: 0.5rem; |
| 111 | } |
| 112 | .dockerhub-title { |
| 113 | font-weight: 500; |
| 114 | } |
| 115 | .dockerhub-description { |
| 116 | font-style: italic; |
| 117 | -webkit-line-clamp: 3; |
| 118 | } |
| 119 | .table { |
| 120 | max-width: 15rem; |
| 121 | padding-left: 0; |
| 122 | li { |
| 123 | display: flex; |
| 124 | justify-content: space-between; |
| 125 | .lbl { |
| 126 | font-weight: 500; |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | h4 { |
| 133 | margin: 1rem 0 0 0; |
| 134 | font-size: 1.2rem; |
| 135 | } |
| 136 | p { |
| 137 | margin: 0; |
| 138 | display: flex; |
| 139 | align-items: center; |
| 140 | gap: 0.25rem; |
| 141 | :global(svg) { |
| 142 | width: 1rem; |
| 143 | } |
| 144 | img { |
| 145 | border-radius: var(--curve-sm); |
| 146 | } |
| 147 | } |
| 148 | .tags { |
| 149 | display: flex; |
| 150 | flex-wrap: wrap; |
| 151 | .tag { |
| 152 | margin: 0.1rem; |
| 153 | background: #5f53f440; |
| 154 | border-radius: var(--curve-sm); |
| 155 | padding: 0.05rem 0.2rem; |
| 156 | font-size: 0.8rem; |
| 157 | opacity: 0.8; |
| 158 | } |
| 159 | } |
| 160 | ul { |
| 161 | padding-left: 1rem; |
| 162 | list-style: circle; |
| 163 | max-height: 400px; |
| 164 | overflow: auto; |
| 165 | img { |
| 166 | border-radius: var(--curve-sm); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | pre { |
| 171 | font-family: 'Courier New', Courier, monospace; |
| 172 | background: #cecbf780; |
| 173 | padding: 0.6rem 1rem; |
| 174 | border-radius: var(--curve-sm); |
| 175 | font-size: 0.8rem; |
| 176 | overflow-x: auto; |
| 177 | } |
| 178 | </style> |
web/src/pages/[...listing].astro
+13
| @@ -6,12 +6,14 @@ import Comments from '@components/things/Comments.svelte'; |
| 6 | 6 | import GitHubDetailedInfo from '@components/things/GitHubDetailedInfo.astro'; |
| 7 | 7 | import PrivacyPolicyDetails from '@components/things/PrivacyPolicyDetails.astro'; |
| 8 | 8 | import WebsiteDetailedInfo from '@components/things/WebsiteDetailedInfo.astro'; |
| 9 | import DockerDetailedInfo from '@components/things/DockerDetailedInfo.astro'; |
| 9 | 10 | import DataActions from '@components/things/DataActions.svelte'; |
| 10 | 11 | import type { AwesomePrivacy, Section, Service } from '../types/Service'; |
| 11 | 12 | import { fetchData, slugify } from '@utils/fetch-data'; |
| 12 | 13 | import { fetchGitHubStats } from '@utils/fetch-repo-info'; |
| 13 | 14 | import { fetchTosdrPrivacy } from '@utils/fetch-privacy-policy'; |
| 14 | 15 | import { fetchWebsiteInfo } from '@utils/fetch-website-info'; |
| 16 | import { fetchDockerData } from '@utils/fetch-docker-instructions'; |
| 15 | 17 | import { parseMarkdown, formatLink } from '@utils/parse-markdown'; |
| 16 | 18 | import FontAwesome from '@components/form/FontAwesome.svelte'; |
| 17 | 19 | import Button from '@components/form/Button.astro'; |
| @@ -122,8 +124,11 @@ const ignoredSites = ['github.gom', 'wikipedia.']; |
| 122 | 124 | // Fetch detailed data about the services GitHub repo, privacy policy and website |
| 123 | 125 | const githubData = github ? await fetchGitHubStats(github) : null; |
| 124 | 126 | const privacyData = tosdrId ? await fetchTosdrPrivacy(tosdrId) : null; |
| 127 | const dockerData = await fetchDockerData(name); |
| 125 | 128 | const websiteData = (url && !ignoredSites.some(ignoredSite => url.includes(ignoredSite))) ? await fetchWebsiteInfo(url) : null; |
| 126 | 129 | |
| 130 | console.log(dockerData); |
| 131 | |
| 127 | 132 | const getApiEndpoint = () => { |
| 128 | 133 | return `https://api.awesome-privacy.xyz/${slugify(categoryName)}/${slugify(parentSection.name)}/${slugify(name)}`; |
| 129 | 134 | } |
| @@ -237,10 +242,18 @@ const getApiEndpoint = () => { |
| 237 | 242 | <WebsiteDetailedInfo url={url} websiteInfo={websiteData} /> |
| 238 | 243 | </section> |
| 239 | 244 | )} |
| 245 | { dockerData && dockerData.found && ( |
| 246 | <section> |
| 247 | <h3>{name} Docker</h3> |
| 248 | <DockerDetailedInfo docker={dockerData} /> |
| 249 | </section> |
| 250 | )} |
| 251 | |
| 240 | 252 | <section> |
| 241 | 253 | <h3>{name} Reviews</h3> |
| 242 | 254 | <Comments client:visible /> |
| 243 | 255 | </section> |
| 256 | |
| 244 | 257 | <section> |
| 245 | 258 | <h3>More {parentSection.name}</h3> |
| 246 | 259 | <ServiceList |
web/src/utils/fetch-docker-instructions.ts
added
+72
| @@ -0,0 +1,72 @@ |
| 1 | |
| 2 | |
| 3 | export const fetchDockerData = async (serviceName: string): Promise<TemplateResponse | null> => { |
| 4 | const endpoint = `https://docker-info.as93.workers.dev/${serviceName}`; |
| 5 | try { |
| 6 | return await fetch(endpoint).then((res) => res.json()); |
| 7 | } catch (error) { |
| 8 | console.error('Error fetching docker data:', error); |
| 9 | return null; |
| 10 | } |
| 11 | }; |
| 12 | |
| 13 | interface DockerTemplatePort { |
| 14 | privatePort: number; |
| 15 | publicPort: number; |
| 16 | type: string; // Typically TCP/UDP |
| 17 | } |
| 18 | |
| 19 | interface DockerTemplateEnvironmentVariable { |
| 20 | name: string; |
| 21 | default?: string; |
| 22 | description?: string; |
| 23 | } |
| 24 | |
| 25 | interface DockerTemplateVolume { |
| 26 | bind: string; |
| 27 | container: string; |
| 28 | readonly?: boolean; |
| 29 | } |
| 30 | |
| 31 | interface DockerTemplate { |
| 32 | name?: string; |
| 33 | title: string; |
| 34 | description?: string; |
| 35 | logo?: string; |
| 36 | image: string; |
| 37 | categories?: string[]; |
| 38 | ports?: DockerTemplatePort[]; |
| 39 | env?: DockerTemplateEnvironmentVariable[]; |
| 40 | volumes?: DockerTemplateVolume[]; |
| 41 | restart_policy?: string; // Typically "no", "always", "unless-stopped", "on-failure" |
| 42 | } |
| 43 | |
| 44 | interface DockerHubData { |
| 45 | user: string; |
| 46 | name: string; |
| 47 | namespace: string; |
| 48 | repository_type: string; |
| 49 | status: number; |
| 50 | description: string; |
| 51 | is_private: boolean; |
| 52 | is_automated: boolean; |
| 53 | can_edit: boolean; |
| 54 | star_count: number; |
| 55 | pull_count: number; |
| 56 | last_updated: string; |
| 57 | date_registered: string; |
| 58 | build_status: string; |
| 59 | } |
| 60 | |
| 61 | interface DockerUsage { |
| 62 | dockerRunCommand: string; |
| 63 | dockerComposeFile: string; |
| 64 | } |
| 65 | |
| 66 | export interface TemplateResponse { |
| 67 | found: boolean; |
| 68 | error: string | null; |
| 69 | template?: DockerTemplate; |
| 70 | dockerHubData?: DockerHubData; |
| 71 | usage?: DockerUsage; |
| 72 | } |