1
- import { Octokit } from "@octokit/rest" ;
2
- import { getGitHubAccessToken } from "../getters/get-github-access-token" ;
3
- import { getImageFromDB , saveImageToDB } from "../getters/get-indexed-db" ;
1
+ import { getImageFromDB } from "../getters/get-indexed-db" ;
4
2
import { getLocalStore } from "../getters/get-local-store" ;
5
3
import { GitHubIssue } from "../github-types" ;
6
4
import { renderGitHubIssues } from "../rendering/render-github-issues" ;
7
5
import { Sorting } from "../sorting/generate-sorting-buttons" ;
8
6
import { sortIssuesController } from "../sorting/sort-issues-controller" ;
7
+ import { fetchAvatar } from "./fetch-avatar" ;
9
8
import { organizationImageCache } from "./fetch-issues-full" ;
10
9
import { fetchIssuePreviews } from "./fetch-issues-preview" ;
11
10
@@ -29,44 +28,7 @@ export async function fetchAndDisplayPreviews(sorting?: Sorting, options = { ord
29
28
const match = issue . body . match ( urlPattern ) ;
30
29
const orgName = match ?. groups ?. org ;
31
30
if ( orgName ) {
32
- // Check local cache first
33
- const cachedAvatar = organizationImageCache . find ( ( entry ) => entry [ orgName ] !== undefined ) ;
34
- if ( cachedAvatar ) {
35
- return Promise . resolve ( ) ;
36
- }
37
-
38
- // If not in local cache, check IndexedDB
39
- const avatarBlob = await getImageFromDB ( { dbName : "ImageDatabase" , storeName : "ImageStore" , orgName : `avatarUrl-${ orgName } ` } ) ;
40
- if ( avatarBlob ) {
41
- // If the avatar Blob is found in IndexedDB, add it to the cache
42
- organizationImageCache . push ( { [ orgName ] : avatarBlob } ) ;
43
- return Promise . resolve ( ) ;
44
- }
45
-
46
- // If not in IndexedDB, fetch from network
47
- const octokit = new Octokit ( { auth : getGitHubAccessToken ( ) } ) ;
48
- return octokit . rest . orgs
49
- . get ( { org : orgName } )
50
- . then ( async ( { data : { avatar_url : avatarUrl } } ) => {
51
- if ( avatarUrl ) {
52
- // Fetch the image as a Blob and save it to IndexedDB
53
- await fetch ( avatarUrl )
54
- . then ( ( response ) => response . blob ( ) )
55
- . then ( async ( blob ) => {
56
- await saveImageToDB ( {
57
- dbName : "ImageDatabase" ,
58
- storeName : "ImageStore" ,
59
- keyName : "name" ,
60
- orgName : `avatarUrl-${ orgName } ` ,
61
- avatarBlob : blob ,
62
- } ) ;
63
- organizationImageCache . push ( { [ orgName ] : blob } ) ;
64
- } ) ;
65
- }
66
- } )
67
- . catch ( ( error ) => {
68
- console . error ( `Failed to fetch avatar for organization ${ orgName } : ${ error } ` ) ;
69
- } ) ;
31
+ return fetchAvatar ( orgName ) ;
70
32
}
71
33
return Promise . resolve ( ) ;
72
34
} ) ;
0 commit comments