Skip to content

Commit

Permalink
(fix) show screenshots if stored in the db
Browse files Browse the repository at this point in the history
fixes #246
  • Loading branch information
leonjza committed Oct 10, 2024
1 parent 83b61c3 commit a40f82a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
2 changes: 2 additions & 0 deletions web/api/gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type galleryContent struct {
ResponseCode int `json:"response_code"`
Title string `json:"title"`
Filename string `json:"file_name"`
Screenshot string `json:"screenshot"`
Failed bool `json:"failed"`
Technologies []string `json:"technologies"`
}
Expand Down Expand Up @@ -141,6 +142,7 @@ func (h *ApiHandler) GalleryHandler(w http.ResponseWriter, r *http.Request) {
ResponseCode: result.ResponseCode,
Title: result.Title,
Filename: result.Filename,
Screenshot: result.Screenshot,
Failed: result.Failed,
Technologies: technologies,
})
Expand Down
2 changes: 2 additions & 0 deletions web/api/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type searchResult struct {
Failed bool `json:"failed"`
FailedReason string `json:"failed_reason"`
Filename string `json:"file_name"`
Screenshot string `json:"screenshot"`
MatchedFields []string `json:"matched_fields"`
}

Expand Down Expand Up @@ -254,6 +255,7 @@ func appendResults(searchResults []searchResult, resultIDs map[uint]bool, newRes
Failed: res.Failed,
FailedReason: res.FailedReason,
Filename: res.Filename,
Screenshot: res.Screenshot,
MatchedFields: []string{matchedField},
})

Expand Down
24 changes: 2 additions & 22 deletions web/ui/src/lib/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type galleryResult = {
title: string;
response_code: number;
file_name: string;
screenshot: string;
failed: boolean;
technologies: string[];
};
Expand Down Expand Up @@ -106,27 +107,6 @@ interface consolelog {
value: string;
}

/*
type Cookie struct {
ID uint `json:"id" gorm:"primarykey"`
ResultID uint `json:"result_id"`
Name string `json:"name"`
Value string `json:"value"`
Domain string `json:"domain"`
Path string `json:"path"`
Expires float64 `json:"expires"`
Size int64 `json:"size"`
HTTPOnly bool `json:"http_only"`
Secure bool `json:"secure"`
Session bool `json:"session"`
Priority string `json:"priority"`
SourceScheme string `json:"source_scheme"`
SourcePort int64 `json:"source_port"`
}
*/

interface cookie {
id: number;
result_id: number;
Expand Down Expand Up @@ -178,13 +158,13 @@ interface searchresult {
title: string;
matched_fields: string[];
file_name: string;
screenshot: string;
}

interface technologylist {
technologies: string[];
}


export type {
statistics,
wappalyzer,
Expand Down
6 changes: 5 additions & 1 deletion web/ui/src/pages/detail/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ const ScreenshotDetailPage = () => {
<DialogTrigger asChild>
<button className="w-full relative">
<img
src={api.endpoints.screenshot.path + "/" + detail.file_name}
src={
detail.screenshot
? `data:image/png;base64,${detail.screenshot}`
: api.endpoints.screenshot.path + "/" + detail.file_name
}
alt={detail.title}
className="w-full h-auto object-cover transition-all duration-300 filter group-hover:brightness-75 rounded-lg"
/>
Expand Down
4 changes: 3 additions & 1 deletion web/ui/src/pages/gallery/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ const GalleryPage = () => {
</div>
) : (
<img
src={api.endpoints.screenshot.path + "/" + screenshot.file_name}
src={screenshot.screenshot
? `data:image/png;base64,${screenshot.screenshot}`
: api.endpoints.screenshot.path + "/" + screenshot.file_name}
alt={screenshot.url}
loading="lazy"
className="w-full h-48 object-cover transition-all duration-300 filter group-hover:scale-105"
Expand Down
5 changes: 4 additions & 1 deletion web/ui/src/pages/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export default function SearchResultsPage() {
<Card className="flex flex-col h-full transition-shadow hover:shadow-lg">
<CardHeader className="relative p-0">
<img
src={api.endpoints.screenshot.path + "/" + result.file_name}
src={
result.screenshot
? `data:image/png;base64,${result.screenshot}`
: api.endpoints.screenshot.path + "/" + result.file_name}
alt={result.url}
loading="lazy"
className="w-full h-48 object-cover transition-all duration-300 filter group-hover:scale-105"
Expand Down

0 comments on commit a40f82a

Please sign in to comment.