Compare commits

..

16 Commits

Author SHA1 Message Date
Aritro37
c5d8aff73c fix: 修复聚合模式下,名称带有中文或特殊符号的分享token判断异常的问题 2025-03-20 21:57:42 +08:00
xream
5696492dde release: bump version
Some checks are pending
build / build (push) Waiting to run
2025-03-19 16:11:49 +08:00
Aritro37
e6d05fd873 perf: 增加 MERGE 模式下的信息输出 2025-03-19 16:08:48 +08:00
Aritro37
4111b8fabf fix: 修复 SUB_STORE_FRONTEND_PATH 使用绝对目录时前端资源 Content-Type 响应错误的问题 2025-03-19 15:52:37 +08:00
Aritro37
dfc619a181 feat: 引入SUB_STORE_BACKEND_MERGE 变量实现前后端端口合并及安全增强
1. 新增SUB_STORE_BACKEND_MERGE配置变量,支持功能整合模式:
   - 当设置SUB_STORE_BACKEND_MERGE为非空任意值时,后端支持同时处理API和前端资源请求
   - 新增配置示例:
     #合并前后端端口
     SUB_STORE_BACKEND_MERGE=true
     #设置接口安全地址
     SUB_STORE_FRONTEND_BACKEND_PATH=/safe-api
     #设置前端文件的路径
     SUB_STORE_FRONTEND_PATH=./dist
     #后端监听的端口
     SUB_STORE_BACKEND_API_PORT=3000
     #后端监听的HOST
     SUB_STORE_BACKEND_API_HOST="127.0.0.1"

2. 合并后支持前端在子路由界面刷新:
   - 原前端在subs、files、sync等页面刷新时会出现404问题,合并后修复了该问题
2025-03-19 15:26:17 +08:00
Aritro37
ff5283a66f fix: 修复使用 .env 时 /api/utils/env 接口中的 env 字段为空的问题 2025-03-19 15:07:01 +08:00
xream
6c54518e84 chore: 日志
Some checks failed
build / build (push) Has been cancelled
2025-03-18 13:34:50 +08:00
Aritro37
dd92a26e6c Perf: 提前加载 .env;后端复用前端 Path
Some checks are pending
build / build (push) Waiting to run
2025-03-17 22:01:38 +08:00
xream
bb5c9d43d0 Merge pull request #430 from Aritro37/master
feat: 支持通过.env配置环境变量,后端支持设置前置路由
2025-03-17 17:07:37 +08:00
Aritro37
e54ac92357 feat: 支持通过.env配置环境变量,后端支持设置前置路由 2025-03-17 17:04:24 +08:00
xream
507e37021c feat: 增加更多的同步配置日志
Some checks are pending
build / build (push) Waiting to run
2025-03-16 15:48:47 +08:00
xream
a70dc7b913 feat: undici 配置重定向
Some checks are pending
build / build (push) Waiting to run
2025-03-15 22:50:47 +08:00
xream
fc56df7bfd fix: 处理 YAML short-idnull 的情况
Some checks are pending
build / build (push) Waiting to run
2025-03-15 16:29:19 +08:00
xream
1281df59f3 feat: 增强 VMess URI 解析兼容性; 修改导出文件名格式
Some checks failed
build / build (push) Has been cancelled
2025-03-13 20:19:45 +08:00
xream
1faa3fb793 fix: 修复 VMess URI IPv6 格式
Some checks are pending
build / build (push) Waiting to run
2025-03-13 19:26:53 +08:00
xream
47307716b2 feat: url 支持 credentials; 修改导出文件名格式 2025-03-13 17:42:48 +08:00
16 changed files with 176 additions and 82 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.18.1", "version": "2.19.1",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {
@@ -27,10 +27,12 @@
"automerge": "1.0.1-preview.7", "automerge": "1.0.1-preview.7",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"buffer": "^6.0.3", "buffer": "^6.0.3",
"dotenv": "^16.4.7",
"connect-history-api-fallback": "^2.0.0", "connect-history-api-fallback": "^2.0.0",
"cron": "^3.1.6", "cron": "^3.1.6",
"dns-packet": "^5.6.1", "dns-packet": "^5.6.1",
"express": "^4.17.1", "express": "^4.17.1",
"mime-types": "^2.1.35",
"http-proxy-middleware": "^3.0.3", "http-proxy-middleware": "^3.0.3",
"ip-address": "^9.0.5", "ip-address": "^9.0.5",
"js-base64": "^3.7.2", "js-base64": "^3.7.2",

View File

@@ -342,7 +342,7 @@ function URI_VMess() {
}; };
const parse = (line) => { const parse = (line) => {
line = line.split('vmess://')[1]; line = line.split('vmess://')[1];
let content = Base64.decode(line); let content = Base64.decode(line.replace(/\?.*?$/, ''));
if (/=\s*vmess/.test(content)) { if (/=\s*vmess/.test(content)) {
// Quantumult VMess URI format // Quantumult VMess URI format
const partitions = content.split(',').map((p) => p.trim()); const partitions = content.split(',').map((p) => p.trim());

View File

@@ -75,6 +75,8 @@ function Clash() {
// 是否被引号包裹 // 是否被引号包裹
if (/^(['"]).*\1$/.test(afterTrim)) { if (/^(['"]).*\1$/.test(afterTrim)) {
return `short-id: ${afterTrim}`; return `short-id: ${afterTrim}`;
} else if (['null'].includes(afterTrim)) {
return `short-id: ${afterTrim}`;
} else { } else {
return `short-id: "${afterTrim}"`; return `short-id: "${afterTrim}"`;
} }

View File

@@ -23,7 +23,11 @@ export default function URI_Producer() {
) { ) {
delete proxy.tls; delete proxy.tls;
} }
if (proxy.server && isIPv6(proxy.server)) { if (
!['vmess'].includes(proxy.type) &&
proxy.server &&
isIPv6(proxy.server)
) {
proxy.server = `[${proxy.server}]`; proxy.server = `[${proxy.server}]`;
} }
switch (proxy.type) { switch (proxy.type) {

View File

@@ -11,6 +11,7 @@
* @documentation: https://www.notion.so/Sub-Store-6259586994d34c11a4ced5c406264b46 * @documentation: https://www.notion.so/Sub-Store-6259586994d34c11a4ced5c406264b46
*/ */
import { version } from '../package.json'; import { version } from '../package.json';
import $ from '@/core/app';
console.log( console.log(
` `
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅ ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
@@ -18,7 +19,6 @@ console.log(
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅ ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
`, `,
); );
import migrate from '@/utils/migration'; import migrate from '@/utils/migration';
import serve from '@/restful'; import serve from '@/restful';

View File

@@ -89,8 +89,10 @@ async function doSync() {
const allSubs = $.read(SUBS_KEY); const allSubs = $.read(SUBS_KEY);
const allCols = $.read(COLLECTIONS_KEY); const allCols = $.read(COLLECTIONS_KEY);
const subNames = []; const subNames = [];
let enabledCount = 0;
allArtifacts.map((artifact) => { allArtifacts.map((artifact) => {
if (artifact.sync && artifact.source) { if (artifact.sync && artifact.source) {
enabledCount++;
if (artifact.type === 'subscription') { if (artifact.type === 'subscription') {
const subName = artifact.source; const subName = artifact.source;
const sub = findByName(allSubs, subName); const sub = findByName(allSubs, subName);
@@ -111,6 +113,13 @@ async function doSync() {
} }
}); });
if (enabledCount === 0) {
$.info(
`需同步的配置: ${enabledCount}, 总数: ${allArtifacts.length}`,
);
return;
}
if (subNames.length > 0) { if (subNames.length > 0) {
await Promise.all( await Promise.all(
subNames.map(async (subName) => { subNames.map(async (subName) => {

View File

@@ -3,6 +3,7 @@ import { COLLECTIONS_KEY, ARTIFACTS_KEY } from '@/constants';
import { failed, success } from '@/restful/response'; import { failed, success } from '@/restful/response';
import $ from '@/core/app'; import $ from '@/core/app';
import { RequestInvalidError, ResourceNotFoundError } from '@/restful/errors'; import { RequestInvalidError, ResourceNotFoundError } from '@/restful/errors';
import { formatDateTime } from '@/utils';
export default function register($app) { export default function register($app) {
if (!$.read(COLLECTIONS_KEY)) $.write({}, COLLECTIONS_KEY); if (!$.read(COLLECTIONS_KEY)) $.write({}, COLLECTIONS_KEY);
@@ -60,20 +61,9 @@ function getCollection(req, res) {
.set( .set(
'content-disposition', 'content-disposition',
`attachment; filename="${encodeURIComponent( `attachment; filename="${encodeURIComponent(
`sub-store_collection_${name}_${new Date() `sub-store_collection_${name}_${formatDateTime(
.toLocaleString('zh-CN', { new Date(),
year: 'numeric', )}.json`,
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
})
.replace(
/^(\d+?)\/(\d+?)\/(\d+?)\s*?(\d+?):(\d+?):(\d+?)$/,
'$1-$2-$3_$4-$5-$6',
)}.json`,
)}"`, )}"`,
) )
.send(JSON.stringify(collection)); .send(JSON.stringify(collection));

View File

@@ -9,6 +9,7 @@ import {
InternalServerError, InternalServerError,
} from '@/restful/errors'; } from '@/restful/errors';
import { produceArtifact } from '@/restful/sync'; import { produceArtifact } from '@/restful/sync';
import { formatDateTime } from '@/utils';
export default function register($app) { export default function register($app) {
if (!$.read(FILES_KEY)) $.write([], FILES_KEY); if (!$.read(FILES_KEY)) $.write([], FILES_KEY);
@@ -210,20 +211,9 @@ function getWholeFile(req, res) {
.set( .set(
'content-disposition', 'content-disposition',
`attachment; filename="${encodeURIComponent( `attachment; filename="${encodeURIComponent(
`sub-store_file_${name}_${new Date() `sub-store_file_${name}_${formatDateTime(
.toLocaleString('zh-CN', { new Date(),
year: 'numeric', )}.json`,
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
})
.replace(
/^(\d+?)\/(\d+?)\/(\d+?)\s*?(\d+?):(\d+?):(\d+?)$/,
'$1-$2-$3_$4-$5-$6',
)}.json`,
)}"`, )}"`,
) )
.send(JSON.stringify(file)); .send(JSON.stringify(file));

View File

@@ -29,6 +29,72 @@ export default function serve() {
host = eval('process.env.SUB_STORE_BACKEND_API_HOST') || '::'; host = eval('process.env.SUB_STORE_BACKEND_API_HOST') || '::';
} }
const $app = express({ substore: $, port, host }); const $app = express({ substore: $, port, host });
if ($.env.isNode) {
const be_merge = eval('process.env.SUB_STORE_BACKEND_MERGE');
const be_prefix = eval('process.env.SUB_STORE_BACKEND_PREFIX');
const fe_be_path = eval('process.env.SUB_STORE_FRONTEND_BACKEND_PATH');
const fe_path = eval('process.env.SUB_STORE_FRONTEND_PATH');
if (be_prefix || be_merge) {
if(!fe_be_path.startsWith('/')){
throw new Error(
'SUB_STORE_FRONTEND_BACKEND_PATH should start with /',
);
}
if (be_merge) {
$.info(`[BACKEND] MERGE mode is [ON].`);
$.info(`[BACKEND && FRONTEND] ${host}:${port}`);
}
$.info(`[BACKEND PREFIX] ${host}:${port}${fe_be_path}`);
$app.use((req, res, next) => {
if (req.path.startsWith(fe_be_path)) {
req.url = req.url.replace(fe_be_path, '') || '/';
if(be_merge && req.url.startsWith('/api/')){
req.query['share'] = 'true';
}
next();
return;
}
const pathname = decodeURIComponent(req._parsedUrl.pathname) || '/';
if(be_merge && req.path.startsWith('/share/') && req.query.token){
if (req.method.toLowerCase() !== 'get'){
res.status(405).send('Method not allowed');
return;
}
const tokens = $.read(TOKENS_KEY) || [];
const token = tokens.find(
(t) =>
t.token === req.query.token &&
`/share/${t.type}/${t.name}` === pathname &&
(t.exp == null || t.exp > Date.now()),
);
if (token){
next();
return;
}
}
if (be_merge && fe_path && req.path.indexOf('/',1) == -1) {
if (req.path.indexOf('.') == -1){
req.url = "/index.html"
}
const express_ = eval(`require("express")`);
const mime_ = eval(`require("mime-types")`);
const path_ = eval(`require("path")`);
const staticFileMiddleware = express_.static(fe_path, {
setHeaders: (res, path) => {
const type = mime_.contentType(path_.extname(path));
if (type) {
res.set('Content-Type', type);
}
}
});
staticFileMiddleware(req, res, next);
return;
}
res.status(403).end('Forbbiden');
return;
});
}
}
// register routes // register routes
registerCollectionRoutes($app); registerCollectionRoutes($app);
registerSubscriptionRoutes($app); registerSubscriptionRoutes($app);
@@ -175,7 +241,8 @@ export default function serve() {
const fe_abs_path = path.resolve( const fe_abs_path = path.resolve(
fe_path || path.join(__dirname, 'frontend'), fe_path || path.join(__dirname, 'frontend'),
); );
if (fe_path) { const be_merge = eval('process.env.SUB_STORE_BACKEND_MERGE');
if (fe_path && !be_merge) {
try { try {
fs.accessSync(path.join(fe_abs_path, 'index.html')); fs.accessSync(path.join(fe_abs_path, 'index.html'));
} catch (e) { } catch (e) {
@@ -200,6 +267,9 @@ export default function serve() {
let be_download_rewrite = ''; let be_download_rewrite = '';
let be_api_rewrite = ''; let be_api_rewrite = '';
let be_share_rewrite = `${be_share}:type/:name`; let be_share_rewrite = `${be_share}:type/:name`;
let prefix = eval('process.env.SUB_STORE_BACKEND_PREFIX')
? fe_be_path
: '';
if (fe_be_path) { if (fe_be_path) {
if (!fe_be_path.startsWith('/')) { if (!fe_be_path.startsWith('/')) {
throw new Error( throw new Error(
@@ -216,7 +286,7 @@ export default function serve() {
app.use( app.use(
be_share_rewrite, be_share_rewrite,
createProxyMiddleware({ createProxyMiddleware({
target: `http://127.0.0.1:${port}`, target: `http://127.0.0.1:${port}${prefix}`,
changeOrigin: true, changeOrigin: true,
pathRewrite: async (path, req) => { pathRewrite: async (path, req) => {
if (req.method.toLowerCase() !== 'get') if (req.method.toLowerCase() !== 'get')
@@ -237,7 +307,7 @@ export default function serve() {
app.use( app.use(
be_api_rewrite, be_api_rewrite,
createProxyMiddleware({ createProxyMiddleware({
target: `http://127.0.0.1:${port}${be_api}`, target: `http://127.0.0.1:${port}${prefix}${be_api}`,
pathRewrite: async (path) => { pathRewrite: async (path) => {
return path.includes('?') return path.includes('?')
? `${path}&share=true` ? `${path}&share=true`
@@ -248,7 +318,7 @@ export default function serve() {
app.use( app.use(
be_download_rewrite, be_download_rewrite,
createProxyMiddleware({ createProxyMiddleware({
target: `http://127.0.0.1:${port}${be_download}`, target: `http://127.0.0.1:${port}${prefix}${be_download}`,
changeOrigin: true, changeOrigin: true,
}), }),
); );
@@ -269,10 +339,10 @@ export default function serve() {
$.info(`[FRONTEND] ${fe_address}:${fe_port}`); $.info(`[FRONTEND] ${fe_address}:${fe_port}`);
if (fe_be_path) { if (fe_be_path) {
$.info( $.info(
`[FRONTEND -> BACKEND] ${fe_address}:${fe_port}${be_api_rewrite} -> http://127.0.0.1:${port}${be_api}`, `[FRONTEND -> BACKEND] ${fe_address}:${fe_port}${be_api_rewrite} -> ${host}:${port}${prefix}${be_api}`,
); );
$.info( $.info(
`[FRONTEND -> BACKEND] ${fe_address}:${fe_port}${be_download_rewrite} -> http://127.0.0.1:${port}${be_download}`, `[FRONTEND -> BACKEND] ${fe_address}:${fe_port}${be_download_rewrite} -> ${host}:${port}${prefix}${be_download}`,
); );
$.info( $.info(
`[SHARE BACKEND] ${fe_address}:${fe_port}${be_share_rewrite}`, `[SHARE BACKEND] ${fe_address}:${fe_port}${be_share_rewrite}`,

View File

@@ -14,6 +14,7 @@ import { InternalServerError, RequestInvalidError } from '@/restful/errors';
import Gist from '@/utils/gist'; import Gist from '@/utils/gist';
import migrate from '@/utils/migration'; import migrate from '@/utils/migration';
import env from '@/utils/env'; import env from '@/utils/env';
import { formatDateTime } from '@/utils';
export default function register($app) { export default function register($app) {
// utils // utils
@@ -28,20 +29,7 @@ export default function register($app) {
.set( .set(
'content-disposition', 'content-disposition',
`attachment; filename="${encodeURIComponent( `attachment; filename="${encodeURIComponent(
`sub-store_data_${new Date() `sub-store_data_${formatDateTime(new Date())}.json`,
.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
})
.replace(
/^(\d+?)\/(\d+?)\/(\d+?)\s*?(\d+?):(\d+?):(\d+?)$/,
'$1-$2-$3_$4-$5-$6',
)}.json`,
)}"`, )}"`,
) )
.send( .send(

View File

@@ -134,11 +134,15 @@ export async function updateArtifactStore() {
settings.artifactStore = url; settings.artifactStore = url;
settings.artifactStoreStatus = 'VALID'; settings.artifactStoreStatus = 'VALID';
} else { } else {
$.error(`找不到 Sub-Store Gist`); $.error(`找不到 Sub-Store Gist (${ARTIFACT_REPOSITORY_KEY})`);
settings.artifactStoreStatus = 'NOT FOUND'; settings.artifactStoreStatus = 'NOT FOUND';
} }
} catch (err) { } catch (err) {
$.error(`查找 Sub-Store Gist 时发生错误: ${err.message ?? err}`); $.error(
`查找 Sub-Store Gist (${ARTIFACT_REPOSITORY_KEY}) 时发生错误: ${
err.message ?? err
}`,
);
settings.artifactStoreStatus = 'ERROR'; settings.artifactStoreStatus = 'ERROR';
} }
$.write(settings, SETTINGS_KEY); $.write(settings, SETTINGS_KEY);

View File

@@ -13,6 +13,7 @@ import {
} from '@/utils/flow'; } from '@/utils/flow';
import { success, failed } from './response'; import { success, failed } from './response';
import $ from '@/core/app'; import $ from '@/core/app';
import { formatDateTime } from '@/utils';
if (!$.read(SUBS_KEY)) $.write({}, SUBS_KEY); if (!$.read(SUBS_KEY)) $.write({}, SUBS_KEY);
@@ -265,20 +266,9 @@ function getSubscription(req, res) {
.set( .set(
'content-disposition', 'content-disposition',
`attachment; filename="${encodeURIComponent( `attachment; filename="${encodeURIComponent(
`sub-store_subscription_${name}_${new Date() `sub-store_subscription_${name}_${formatDateTime(
.toLocaleString('zh-CN', { new Date(),
year: 'numeric', )}.json`,
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
})
.replace(
/^(\d+?)\/(\d+?)\/(\d+?)\s*?(\d+?):(\d+?):(\d+?)$/,
'$1-$2-$3_$4-$5-$6',
)}.json`,
)}"`, )}"`,
) )
.send(JSON.stringify(sub)); .send(JSON.stringify(sub));

View File

@@ -556,8 +556,10 @@ async function syncArtifacts() {
const allSubs = $.read(SUBS_KEY); const allSubs = $.read(SUBS_KEY);
const allCols = $.read(COLLECTIONS_KEY); const allCols = $.read(COLLECTIONS_KEY);
const subNames = []; const subNames = [];
let enabledCount = 0;
allArtifacts.map((artifact) => { allArtifacts.map((artifact) => {
if (artifact.sync && artifact.source) { if (artifact.sync && artifact.source) {
enabledCount++;
if (artifact.type === 'subscription') { if (artifact.type === 'subscription') {
const subName = artifact.source; const subName = artifact.source;
const sub = findByName(allSubs, subName); const sub = findByName(allSubs, subName);
@@ -578,6 +580,13 @@ async function syncArtifacts() {
} }
}); });
if (enabledCount === 0) {
$.info(
`需同步的配置: ${enabledCount}, 总数: ${allArtifacts.length}`,
);
return;
}
if (subNames.length > 0) { if (subNames.length > 0) {
await Promise.all( await Promise.all(
subNames.map(async (subName) => { subNames.map(async (subName) => {

View File

@@ -280,7 +280,7 @@ export default class Gist {
return Promise.reject(err); return Promise.reject(err);
} }
} else { } else {
return Promise.reject('找不到 Sub-Store Gist'); return Promise.reject(`找不到 Sub-Store Gist (${this.key})`);
} }
} }
} }

View File

@@ -126,7 +126,32 @@ function isValidUUID(uuid) {
); );
} }
function formatDateTime(date, format = 'YYYY-MM-DD_HH-mm-ss') {
const d = date instanceof Date ? date : new Date(date);
if (isNaN(d.getTime())) {
return '';
}
const pad = (num) => String(num).padStart(2, '0');
const replacements = {
YYYY: d.getFullYear(),
MM: pad(d.getMonth() + 1),
DD: pad(d.getDate()),
HH: pad(d.getHours()),
mm: pad(d.getMinutes()),
ss: pad(d.getSeconds()),
};
return format.replace(
/YYYY|MM|DD|HH|mm|ss/g,
(match) => replacements[match],
);
}
export { export {
formatDateTime,
isValidUUID, isValidUUID,
ipAddress, ipAddress,
isIPv4, isIPv4,

View File

@@ -18,6 +18,10 @@ export class OpenAPI {
this.http = HTTP(); this.http = HTTP();
this.env = ENV(); this.env = ENV();
if (isNode) {
const dotenv = eval(`require("dotenv")`);
dotenv.config();
}
this.node = (() => { this.node = (() => {
if (isNode) { if (isNode) {
const fs = eval("require('fs')"); const fs = eval("require('fs')");
@@ -360,7 +364,12 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
} }
if (isNode) { if (isNode) {
const undici = eval("require('undici')"); const undici = eval("require('undici')");
const { ProxyAgent, EnvHttpProxyAgent, request } = undici; const {
ProxyAgent,
EnvHttpProxyAgent,
request,
interceptors,
} = undici;
const agentOpts = { const agentOpts = {
connect: { connect: {
rejectUnauthorized: rejectUnauthorized:
@@ -374,29 +383,31 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
}; };
try { try {
const url = new URL(opts.url); const url = new URL(opts.url);
const auth = if (url.username || url.password) {
url.username || url.password
? Buffer.from(
`${url.username || ''}:${
url.password || ''
}`,
).toString('base64')
: undefined;
if (auth) {
opts.headers = { opts.headers = {
...(opts.headers || {}), ...(opts.headers || {}),
Authorization: `Basic ${auth}`, Authorization: `Basic ${Buffer.from(
`${url.username || ''}:${
url.password || ''
}`,
).toString('base64')}`,
}; };
} }
const response = await request(opts.url, { const response = await request(opts.url, {
...opts, ...opts,
method: method.toUpperCase(), method: method.toUpperCase(),
dispatcher: opts.proxy dispatcher: (opts.proxy
? new ProxyAgent({ ? new ProxyAgent({
...agentOpts, ...agentOpts,
uri: opts.proxy, uri: opts.proxy,
}) })
: new EnvHttpProxyAgent(agentOpts), : new EnvHttpProxyAgent(agentOpts)
).compose(
interceptors.redirect({
maxRedirections: 3,
throwOnMaxRedirects: true,
}),
),
}); });
resolve({ resolve({
statusCode: response.statusCode, statusCode: response.statusCode,