MCPcopy Index your code
hub / github.com/darkreader/darkreader / firefoxFetchAllMetadata

Function firefoxFetchAllMetadata

tasks/integrity.js:159–225  ·  view source on GitHub ↗
(noCache = false)

Source from the content-addressed store, hash-verified

157}
158
159async function firefoxFetchAllMetadata(noCache = false) {
160 if (noCache) {
161 await rm(tmpDirParent, {force: true, recursive: true});
162 }
163 try {
164 await mkdir(tmpDirParent, {recursive: true});
165 } catch (e) {
166 // No need to create already existing directory
167 }
168
169 const versions = await firefoxFetchAllReleases();
170 log.ok(`Fetched release URLs (${versions.length})`);
171 await writeFile(`${tmpDirParent}/firefox-index.json`, JSON.stringify(versions, null, 2));
172
173 for (const {version, url, size} of versions) {
174 const fileName = `${tmpDirParent}/firefox-${version}.xpi`;
175 const dest = `./integrity/firefox/${version}`;
176 const tempDest = `${tmpDirParent}/firefox-${version}`;
177
178 try {
179 const st = await stat(fileName);
180 // Fast-fail path, it is actually never taken in practice
181 if (st.size !== size) {
182 throw new Error('Stored file had changed');
183 }
184 log.ok(`Found release file (Firefox, ${version})`);
185 } catch {
186 log.ok(`Fetching release file (${version})`);
187 const file = await fetch(url);
188 await writeFile(fileName, toBuffer(await file.arrayBuffer()));
189 log.ok(`Wrote release file (${version})`);
190 }
191
192 await rm(tempDest, {force: true, recursive: true});
193 await mkdir(tempDest, {recursive: true});
194 await rm(dest, {force: true, recursive: true});
195 await mkdir(dest, {recursive: true});
196
197 const zip = new unzipper(fileName);
198 zip.extractAllTo(tempDest);
199
200
201 const manifestMf = await readFile(`${tempDest}/META-INF/manifest.mf`, {encoding: 'utf-8'});
202 const {type, order} = firefoxExtractHashMetaInfOrder(manifestMf);
203
204 const manifestJSON = await readFile(`${tempDest}/manifest.json`, {encoding: 'utf-8'});
205 const manifest = getManifestJSONData(manifestJSON);
206
207 const info = {
208 type,
209 manifest,
210 order,
211 };
212 await writeFile(`${dest}/info.json`, `${JSON.stringify(info)}\n`);
213 await copyFile(`${tempDest}/META-INF/mozilla.rsa`, `${dest}/mozilla.rsa`);
214 try {
215 await copyFile(`${tempDest}/META-INF/cose.sig`, `${dest}/cose.sig`);
216 } catch (e) {

Callers 1

mainFunction · 0.85

Calls 7

firefoxFetchAllReleasesFunction · 0.85
writeFileFunction · 0.85
toBufferFunction · 0.85
readFileFunction · 0.85
getManifestJSONDataFunction · 0.85
copyFileFunction · 0.85

Tested by

no test coverage detected