mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-21 05:40:29 +08:00
121 lines
4.8 KiB
JavaScript
121 lines
4.8 KiB
JavaScript
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const singbox=require('../../../_virtual/singbox.cjs'),base=require('./base.cjs'),appendArrayInPlace=require('../append-array-in-place.cjs'),require$$2=require('foxts/noop'),misc=require('../misc.cjs'),require$$4=require('json-stringify-pretty-compact'),dir=require('../../constants/dir.cjs');var hasRequiredSingbox;
|
|
|
|
function requireSingbox () {
|
|
if (hasRequiredSingbox) return singbox.__exports;
|
|
hasRequiredSingbox = 1;
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "SingboxSource", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return SingboxSource;
|
|
}
|
|
});
|
|
const _base = /*@__PURE__*/ base.__require();
|
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
|
const _noop = require$$2;
|
|
const _misc = /*@__PURE__*/ misc.__require();
|
|
const _jsonstringifyprettycompact = /*#__PURE__*/ _interop_require_default(require$$4);
|
|
const _dir = /*@__PURE__*/ dir.__require();
|
|
function _interop_require_default(obj) {
|
|
return obj && obj.__esModule ? obj : {
|
|
default: obj
|
|
};
|
|
}
|
|
class SingboxSource extends _base.BaseWriteStrategy {
|
|
type;
|
|
outputDir;
|
|
fileExtension;
|
|
static jsonToLines = (json)=>(0, _jsonstringifyprettycompact.default)(json).split('\n');
|
|
singbox;
|
|
get result() {
|
|
return SingboxSource.jsonToLines({
|
|
version: 2,
|
|
rules: [
|
|
this.singbox
|
|
]
|
|
});
|
|
}
|
|
constructor(/** Since sing-box only have one format that does not reflect type, we need to specify it */ type/* | (string & {}) */ , outputDir = _dir.OUTPUT_SINGBOX_DIR){
|
|
super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'json', this.singbox = {
|
|
domain: [
|
|
'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
|
|
],
|
|
domain_suffix: [
|
|
'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
|
|
]
|
|
}, this.withPadding = _misc.withIdentityContent, this.writeUserAgents = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeGeoip = _noop.noop, this.writeIpAsns = _noop.noop, this.writeOtherRules = _noop.noop;
|
|
}
|
|
withPadding;
|
|
writeDomain(domain) {
|
|
this.singbox.domain.push(domain);
|
|
}
|
|
writeDomainSuffix(domain) {
|
|
this.singbox.domain_suffix.push(domain);
|
|
}
|
|
writeDomainKeywords(keyword) {
|
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.domain_keyword ??= [], Array.from(keyword));
|
|
}
|
|
writeDomainWildcards(wildcard) {
|
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.domain_regex ??= [], Array.from(wildcard, SingboxSource.domainWildCardToRegex));
|
|
}
|
|
writeUserAgents;
|
|
writeProcessNames(processName) {
|
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.process_name ??= [], Array.from(processName));
|
|
}
|
|
writeProcessPaths(processPath) {
|
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.process_path ??= [], Array.from(processPath));
|
|
}
|
|
writeUrlRegexes;
|
|
writeIpCidrs(ipCidr) {
|
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.ip_cidr ??= [], ipCidr);
|
|
}
|
|
writeIpCidr6s(ipCidr6) {
|
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.ip_cidr ??= [], ipCidr6);
|
|
}
|
|
writeGeoip;
|
|
writeIpAsns;
|
|
writeSourceIpCidrs(sourceIpCidr) {
|
|
this.singbox.source_ip_cidr ??= [];
|
|
for(let i = 0, len = sourceIpCidr.length; i < len; i++){
|
|
const value = sourceIpCidr[i];
|
|
if (value.includes('/')) {
|
|
this.singbox.source_ip_cidr.push(value);
|
|
continue;
|
|
}
|
|
const v = (0, _misc.fastIpVersion)(value);
|
|
if (v === 4) {
|
|
this.singbox.source_ip_cidr.push(`${value}/32`);
|
|
continue;
|
|
}
|
|
if (v === 6) {
|
|
this.singbox.source_ip_cidr.push(`${value}/128`);
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
writeSourcePorts(port) {
|
|
this.singbox.source_port ??= [];
|
|
for (const i of port){
|
|
const tmp = Number(i);
|
|
if (!Number.isNaN(tmp)) {
|
|
this.singbox.source_port.push(tmp);
|
|
}
|
|
}
|
|
}
|
|
writeDestinationPorts(port) {
|
|
this.singbox.port ??= [];
|
|
for (const i of port){
|
|
const tmp = Number(i);
|
|
if (!Number.isNaN(tmp)) {
|
|
this.singbox.port.push(tmp);
|
|
}
|
|
}
|
|
}
|
|
writeOtherRules;
|
|
}
|
|
} (singbox.__exports));
|
|
return singbox.__exports;
|
|
}exports.__require=requireSingbox; |