|
| 1 | +import { Firebase } from '../../Firebase'; |
1 | 2 | import { GithubGraphQL } from '../../v2/GraphQLInterop'; |
2 | 3 |
|
3 | 4 | const FormatSize = (kilobytes) => { |
@@ -40,8 +41,9 @@ export interface PluginDataTable { |
40 | 41 | metadata: { id: string; commitId: string }[]; |
41 | 42 | } |
42 | 43 |
|
43 | | -const GetPluginData = async (pluginList): Promise<PluginDataProps[]> => { |
44 | | - const query = ` |
| 44 | +const GetPluginData = (pluginList) => { |
| 45 | + return new Promise<PluginDataProps[]>(async (resolve, reject) => { |
| 46 | + const query = ` |
45 | 47 | query { |
46 | 48 | ${pluginList |
47 | 49 | .map( |
@@ -86,33 +88,33 @@ const GetPluginData = async (pluginList): Promise<PluginDataProps[]> => { |
86 | 88 | } |
87 | 89 | `; |
88 | 90 |
|
89 | | - const responseJson = await GithubGraphQL.Post(query); |
| 91 | + const responseJson = await GithubGraphQL.Post(query); |
90 | 92 |
|
91 | | - if (!responseJson.data) { |
92 | | - throw new Error(`GitHub GraphQL error: ${JSON.stringify(responseJson)}`); |
93 | | - } |
| 93 | + const jsonResponse = Object.values(responseJson.data) |
| 94 | + .map((repository) => repository) |
| 95 | + .map((repo: any): PluginDataProps | null => { |
| 96 | + try { |
| 97 | + const pluginJson = JSON.parse(repo.pluginJson.text); |
| 98 | + return { |
| 99 | + pluginJson: pluginJson, |
| 100 | + usesBackend: pluginJson?.useBackend === true || pluginJson?.useBackend === undefined, |
| 101 | + readme: repo?.pluginReadme?.text || repo.readme.text, |
| 102 | + stargazerCount: repo.stargazerCount, |
| 103 | + diskUsage: FormatSize(repo.diskUsage), |
| 104 | + commitDate: repo.commit.committedDate, |
| 105 | + commitMessage: repo.commit.message, |
| 106 | + repoName: repo.repoName, |
| 107 | + repoOwner: repo.repoOwner.login, |
| 108 | + id: repo.commitId.oid, |
| 109 | + }; |
| 110 | + } catch { |
| 111 | + return null; |
| 112 | + } |
| 113 | + }) |
| 114 | + .filter((item): item is PluginDataProps => item !== null); |
94 | 115 |
|
95 | | - return Object.values(responseJson.data) |
96 | | - .map((repo: any): PluginDataProps | null => { |
97 | | - try { |
98 | | - const pluginJson = JSON.parse(repo.pluginJson.text); |
99 | | - return { |
100 | | - pluginJson: pluginJson, |
101 | | - usesBackend: pluginJson?.useBackend === true || pluginJson?.useBackend === undefined, |
102 | | - readme: repo?.pluginReadme?.text || repo.readme.text, |
103 | | - stargazerCount: repo.stargazerCount, |
104 | | - diskUsage: FormatSize(repo.diskUsage), |
105 | | - commitDate: repo.commit.committedDate, |
106 | | - commitMessage: repo.commit.message, |
107 | | - repoName: repo.repoName, |
108 | | - repoOwner: repo.repoOwner.login, |
109 | | - id: repo.commitId.oid, |
110 | | - }; |
111 | | - } catch { |
112 | | - return null; |
113 | | - } |
114 | | - }) |
115 | | - .filter((item): item is PluginDataProps => item !== null); |
| 116 | + resolve(jsonResponse); |
| 117 | + }); |
116 | 118 | }; |
117 | 119 |
|
118 | 120 | export { GetPluginData }; |
0 commit comments