mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-21 05:40:29 +08:00
58 lines
3.2 KiB
JavaScript
58 lines
3.2 KiB
JavaScript
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const downloadMockAssets=require('../_virtual/download-mock-assets.cjs'),index=require('./trace/index.cjs'),require$$0=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:stream/promises'),dir=require('./constants/dir.cjs'),misc=require('./lib/misc.cjs'),fetchRetry=require('./lib/fetch-retry.cjs');var hasRequiredDownloadMockAssets;
|
|
|
|
function requireDownloadMockAssets () {
|
|
if (hasRequiredDownloadMockAssets) return downloadMockAssets.__module.exports;
|
|
hasRequiredDownloadMockAssets = 1;
|
|
(function (module, exports) {
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "downloadMockAssets", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return downloadMockAssets;
|
|
}
|
|
});
|
|
const _trace = /*@__PURE__*/ index.__require();
|
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1);
|
|
const _promises = require$$2;
|
|
const _dir = /*@__PURE__*/ dir.__require();
|
|
const _misc = /*@__PURE__*/ misc.__require();
|
|
const _fetchretry = /*@__PURE__*/ fetchRetry.__require();
|
|
function _interop_require_default(obj) {
|
|
return obj && obj.__esModule ? obj : {
|
|
default: obj
|
|
};
|
|
}
|
|
const ASSETS_LIST = {
|
|
'www-google-analytics-com_ga.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/google-analytics-ga.js',
|
|
'www-googletagservices-com_gpt.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/googletagservices-gpt.js',
|
|
'www-google-analytics-com_analytics.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/google-analytics.js',
|
|
'www-googlesyndication-com_adsbygoogle.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/googlesyndication-adsbygoogle.js',
|
|
'amazon-adsystem-com_amazon-apstag.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/amazon-apstag.js'
|
|
};
|
|
const downloadMockAssets = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
|
const p = (0, _misc.mkdirp)(_dir.OUTPUT_MOCK_DIR);
|
|
if (p) {
|
|
await p;
|
|
}
|
|
return Promise.all(Object.entries(ASSETS_LIST).map(([filename, url])=>span.traceChildAsync(url, async ()=>{
|
|
const res = await (0, _fetchretry.$$fetch)(url);
|
|
if (!res.ok) {
|
|
console.error(`Failed to download ${url}`);
|
|
// we can safely skip this since we can always use previous version
|
|
return;
|
|
}
|
|
if (!res.body) {
|
|
console.error(`Empty body from ${url}`);
|
|
// we can safely skip this since we can always use previous version
|
|
return;
|
|
}
|
|
const src = _nodepath.default.join(_dir.OUTPUT_MOCK_DIR, filename);
|
|
return (0, _promises.pipeline)(res.body, _nodefs.default.createWriteStream(src, 'utf-8'));
|
|
})));
|
|
});
|
|
} (downloadMockAssets.__module, downloadMockAssets.__module.exports));
|
|
return downloadMockAssets.__module.exports;
|
|
}exports.__require=requireDownloadMockAssets; |