MCPcopy Create free account
hub / github.com/IsAvaible/AngularModUpdater / getModInfoForFile

Method getModInfoForFile

src/app/libraries/github/github.ts:125–214  ·  view source on GitHub ↗

* Gets mod information for a filename that matches GitHub patterns * @param filename The mod filename to check * @param loader The current loader * @param mcVersion The current selected minecraft version * @param modrinth The client to fetch data from Modrinth with

(
    filename: string,
    loader: Loader,
    mcVersion: string,
    modrinth: Modrinth
  )

Source from the content-addressed store, hash-verified

123 * @param modrinth The client to fetch data from Modrinth with
124 */
125 public getModInfoForFile(
126 filename: string,
127 loader: Loader,
128 mcVersion: string,
129 modrinth: Modrinth
130 ): Observable<GitHubModInfo | null> {
131 const matchingConfig = GitHub.REPO_CONFIGS.find(
132 (config) => config.loader === loader && config.pattern.test(filename)
133 );
134
135 if (!matchingConfig) {
136 return of(null);
137 }
138
139 return this.getReleases(matchingConfig).pipe(
140 switchMap(async (releases) => {
141 if (this.isAnnotatedError(releases)) {
142 return null;
143 }
144
145 await this.findGithubInfoFromModrinth(matchingConfig, modrinth);
146
147 const validReleases = releases
148 .filter((release) => !release.draft && !release.prerelease)
149 .filter((release) => release.name.includes(mcVersion))
150 .filter((release) =>
151 this.findMatchingAsset(release, matchingConfig.pattern)
152 );
153
154 if (validReleases.length === 0) {
155 return null;
156 }
157
158 const id = `${matchingConfig.owner}/${matchingConfig.repo}`;
159 const project: GitHubProject = {
160 id: id,
161 title: matchingConfig.title || matchingConfig.repo,
162 description: matchingConfig.description || 'Github Repository',
163 project_url: `https://github.com/${id}`,
164 downloads: validReleases.reduce(
165 (sum, release) =>
166 sum +
167 release.assets.reduce(
168 (assetSum, asset) => assetSum + asset.download_count,
169 0
170 ),
171 0
172 ),
173 updated: new Date(
174 Math.max(
175 ...validReleases.map((r) => new Date(r.published_at).getTime())
176 )
177 ),
178 versions: validReleases.map((r) => r.tag_name),
179 loaders: [matchingConfig.loader]
180 };
181
182 const versions: GitHubVersion[] = validReleases.map((release) => {

Callers 1

tryGitHubMethod · 0.80

Calls 3

getReleasesMethod · 0.95
findMatchingAssetMethod · 0.95

Tested by

no test coverage detected