mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-13 09:40:34 +08:00
Chore: improve trace output
This commit is contained in:
parent
64317794b0
commit
34c316f509
@ -1,6 +1,6 @@
|
||||
import type { Span } from '../../trace';
|
||||
import { HostnameSmolTrie } from '../trie';
|
||||
import { invariant, not } from 'foxts/guard';
|
||||
import { not, nullthrow } from 'foxts/guard';
|
||||
import type { MaybePromise } from '../misc';
|
||||
import type { BaseWriteStrategy } from '../writing-strategy/base';
|
||||
import { merge as mergeCidr } from 'fast-cidr-tools';
|
||||
@ -442,25 +442,24 @@ export class FileOutput {
|
||||
return childSpan.traceChildAsync('output to disk', (childSpan) => {
|
||||
const promises: Array<Promise<void> | void> = [];
|
||||
|
||||
invariant(this.title, 'Missing title');
|
||||
invariant(this.description, 'Missing description');
|
||||
|
||||
for (let i = 0, len = this.strategies.length; i < len; i++) {
|
||||
const strategy = this.strategies[i];
|
||||
if (strategy) {
|
||||
const basename = (strategy.overwriteFilename || this.id) + '.' + strategy.fileExtension;
|
||||
promises.push(strategy.output(
|
||||
childSpan,
|
||||
this.title,
|
||||
this.description,
|
||||
this.date,
|
||||
path.join(
|
||||
strategy.outputDir,
|
||||
strategy.type
|
||||
? path.join(strategy.type, basename)
|
||||
: basename
|
||||
)
|
||||
));
|
||||
promises.push(
|
||||
childSpan.traceChildAsync('write ' + strategy.name, (childSpan) => Promise.resolve(strategy.output(
|
||||
childSpan,
|
||||
nullthrow(this.title, 'Missing title'),
|
||||
nullthrow(this.description, 'Missing description'),
|
||||
this.date,
|
||||
path.join(
|
||||
strategy.outputDir,
|
||||
strategy.type
|
||||
? path.join(strategy.type, basename)
|
||||
: basename
|
||||
)
|
||||
)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,8 @@ import { noop } from 'foxts/noop';
|
||||
import { notSupported } from '../misc';
|
||||
|
||||
export class AdGuardHome extends BaseWriteStrategy {
|
||||
public readonly name = 'adguardhome';
|
||||
|
||||
// readonly type = 'domainset';
|
||||
readonly fileExtension = 'txt';
|
||||
readonly type = '';
|
||||
|
||||
@ -6,6 +6,8 @@ import { compareAndWriteFile } from '../create-file';
|
||||
* date is written to a file.
|
||||
*/
|
||||
export abstract class BaseWriteStrategy {
|
||||
public abstract readonly name: string;
|
||||
|
||||
/**
|
||||
* Sometimes a ruleset will create extra files (e.g. reject-url-regex w/ mitm.sgmodule),
|
||||
* and doesn't share the same filename and id. This property is used to overwrite the filename.
|
||||
|
||||
@ -6,6 +6,8 @@ import { OUTPUT_CLASH_DIR } from '../../constants/dir';
|
||||
import { appendArrayInPlace } from '../append-array-in-place';
|
||||
|
||||
export class ClashDomainSet extends BaseWriteStrategy {
|
||||
public readonly name = 'clash domainset';
|
||||
|
||||
// readonly type = 'domainset';
|
||||
readonly fileExtension = 'txt';
|
||||
readonly type = 'domainset';
|
||||
@ -43,6 +45,8 @@ export class ClashDomainSet extends BaseWriteStrategy {
|
||||
}
|
||||
|
||||
export class ClashIPSet extends BaseWriteStrategy {
|
||||
public readonly name = 'clash ipcidr';
|
||||
|
||||
// readonly type = 'domainset';
|
||||
readonly fileExtension = 'txt';
|
||||
readonly type = 'ip';
|
||||
@ -80,6 +84,8 @@ export class ClashIPSet extends BaseWriteStrategy {
|
||||
}
|
||||
|
||||
export class ClashClassicRuleSet extends BaseWriteStrategy {
|
||||
public readonly name = 'clash classic ruleset';
|
||||
|
||||
readonly fileExtension = 'txt';
|
||||
|
||||
protected result: string[] = ['DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'];
|
||||
|
||||
@ -26,6 +26,8 @@ export interface SingboxSourceFormat {
|
||||
}
|
||||
|
||||
export class SingboxSource extends BaseWriteStrategy {
|
||||
public readonly name = 'singbox';
|
||||
|
||||
readonly fileExtension = 'json';
|
||||
|
||||
static readonly jsonToLines = (json: unknown): string[] => stringify(json).split('\n');
|
||||
|
||||
@ -9,6 +9,8 @@ import { OUTPUT_MODULES_DIR, OUTPUT_SURGE_DIR } from '../../constants/dir';
|
||||
import { withBannerArray, withIdentityContent } from '../misc';
|
||||
|
||||
export class SurgeDomainSet extends BaseWriteStrategy {
|
||||
public readonly name = 'surge domainset';
|
||||
|
||||
// readonly type = 'domainset';
|
||||
readonly fileExtension = 'conf';
|
||||
type = 'domainset';
|
||||
@ -46,6 +48,8 @@ export class SurgeDomainSet extends BaseWriteStrategy {
|
||||
}
|
||||
|
||||
export class SurgeRuleSet extends BaseWriteStrategy {
|
||||
public readonly name = 'surge ruleset';
|
||||
|
||||
readonly fileExtension = 'conf';
|
||||
|
||||
protected result: string[] = ['DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'];
|
||||
@ -132,6 +136,8 @@ export class SurgeRuleSet extends BaseWriteStrategy {
|
||||
}
|
||||
|
||||
export class SurgeMitmSgmodule extends BaseWriteStrategy {
|
||||
public readonly name = 'surge sgmodule';
|
||||
|
||||
// readonly type = 'domainset';
|
||||
readonly fileExtension = 'sgmodule';
|
||||
readonly type = '';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user