Skip to content

Commit f474dd0

Browse files
committed
feat: add subscription template management and configuration support
- Introduce SubscriptionTemplate model in Prisma schema - Add new constants and routes for subscription template operations - Implement default configuration seeding for various subscription types - Update Clash and Stash template configurations - Modify subscription generation to use YAML parsing - Add new module and service for subscription template management
1 parent 59c77d9 commit f474dd0

35 files changed

+1044
-46
lines changed

configs/clash/clash_template.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ dns:
1717
- 1.1.1.1
1818
- 8.8.8.8
1919
fake-ip-filter:
20-
- "*.lan"
20+
- '*.lan'
2121
- stun.*.*.*
2222
- stun.*.*
2323
- time.windows.com
2424
- time.nist.gov
2525
- time.apple.com
2626
- time.asia.apple.com
27-
- "*.openwrt.pool.ntp.org"
27+
- '*.openwrt.pool.ntp.org'
2828
- pool.ntp.org
2929
- ntp.ubuntu.com
3030
- time1.apple.com
@@ -40,23 +40,21 @@ dns:
4040
- time4.google.com
4141
- api.joox.com
4242
- joox.com
43-
- "*.xiami.com"
44-
- "*.msftconnecttest.com"
45-
- "*.msftncsi.com"
43+
- '*.xiami.com'
44+
- '*.msftconnecttest.com'
45+
- '*.msftncsi.com'
4646
- '+.xboxlive.com'
47-
- "*.*.stun.playstation.net"
47+
- '*.*.stun.playstation.net'
4848
- xbox.*.*.microsoft.com
49-
- "*.ipv6.microsoft.com"
49+
- '*.ipv6.microsoft.com'
5050
- speedtest.cros.wr.pvp.net
5151

52-
proxies:
53-
{{ proxies | yaml | indent(2) }}
52+
proxies: # LEAVE THIS LINE!
5453

5554
proxy-groups:
56-
- name: '→ Remnawave'
57-
type: 'select'
58-
proxies:
59-
{{ proxy_remarks | yaml | indent(2) }}
55+
- name: '→ Remnawave'
56+
type: 'select'
57+
proxies: # LEAVE THIS LINE!
6058

6159
rules:
62-
- MATCH,→ Remnawave
60+
- MATCH,→ Remnawave

configs/stash/stash_template.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
proxy-groups:
2-
- name: → Remnawave
3-
type: select
4-
proxies:
5-
{{ proxy_remarks | yaml | indent(2) }}
2+
- name: → Remnawave
3+
type: select
4+
proxies: # LEAVE THIS LINE!
65

7-
proxies:
8-
{{ proxies | yaml | indent(2) }}
6+
proxies: # LEAVE THIS LINE!
97

108
rules:
119
- SCRIPT,quic,REJECT
@@ -47,4 +45,4 @@ dns:
4745
- 1.1.1.1
4846
- 1.0.0.1
4947
log-level: warning
50-
mode: rule
48+
mode: rule

libs/contract/api/controllers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from './inbounds';
55
export * from './keygen';
66
export * from './nodes';
77
export * from './subscription';
8+
export * from './subscription-template';
89
export * from './system';
910
export * from './users';
1011
export * from './xray';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const SUBSCRIPTION_TEMPLATE_CONTROLLER = 'subscription-templates' as const;
2+
3+
export const SUBSCRIPTION_TEMPLATE_ROUTES = {
4+
GET_TEMPLATE: 'get-template',
5+
UPDATE_TEMPLATE: 'update-template',
6+
} as const;

libs/contract/api/routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,9 @@ export const REST_API = {
9696
BANDWIDTH: `${ROOT}/${CONTROLLERS.SYSTEM_CONTROLLER}/${CONTROLLERS.SYSTEM_ROUTES.BANDWIDTH}`,
9797
NODES_STATISTIC: `${ROOT}/${CONTROLLERS.SYSTEM_CONTROLLER}/${CONTROLLERS.SYSTEM_ROUTES.STATISTIC.NODES}`,
9898
},
99+
SUBSCRIPTION_TEMPLATE: {
100+
GET_INFO: (subscriptionType: string) =>
101+
`${ROOT}/${CONTROLLERS.SUBSCRIPTION_TEMPLATE_CONTROLLER}/${CONTROLLERS.SUBSCRIPTION_TEMPLATE_ROUTES.GET_TEMPLATE}/${subscriptionType}`,
102+
UPDATE_TEMPLATE: `${ROOT}/${CONTROLLERS.SUBSCRIPTION_TEMPLATE_CONTROLLER}/${CONTROLLERS.SUBSCRIPTION_TEMPLATE_ROUTES.UPDATE_TEMPLATE}`,
103+
},
99104
} as const;

libs/contract/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from './inbounds';
55
export * from './keygen';
66
export * from './nodes';
77
export * from './subscription';
8+
export * from './subscription-template';
89
export * from './system';
910
export * from './users';
1011
export * from './xray';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { z } from 'zod';
2+
3+
import { SUBSCRIPTION_TEMPLATE_TYPE } from '../../constants';
4+
import { REST_API } from '../../api';
5+
6+
export namespace GetSubscriptionTemplateCommand {
7+
export const url = REST_API.SUBSCRIPTION_TEMPLATE.GET_INFO;
8+
export const TSQ_url = url(':templateType');
9+
10+
export const RequestSchema = z.object({
11+
templateType: z.nativeEnum(SUBSCRIPTION_TEMPLATE_TYPE),
12+
});
13+
14+
export type Request = z.infer<typeof RequestSchema>;
15+
16+
export const ResponseSchema = z.object({
17+
response: z.object({
18+
uuid: z.string().uuid(),
19+
templateType: z.nativeEnum(SUBSCRIPTION_TEMPLATE_TYPE),
20+
templateJson: z.nullable(z.unknown()),
21+
encodedTemplateYaml: z.nullable(z.string()),
22+
}),
23+
});
24+
25+
export type Response = z.infer<typeof ResponseSchema>;
26+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './get-template.command';
2+
export * from './update-template.command';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { z } from 'zod';
2+
3+
import { SUBSCRIPTION_TEMPLATE_TYPE } from '../../constants';
4+
import { REST_API } from '../../api';
5+
6+
export namespace UpdateSubscriptionTemplateCommand {
7+
export const url = REST_API.SUBSCRIPTION_TEMPLATE.UPDATE_TEMPLATE;
8+
export const TSQ_url = url;
9+
10+
export const RequestSchema = z.object({
11+
templateType: z.nativeEnum(SUBSCRIPTION_TEMPLATE_TYPE),
12+
templateJson: z.optional(z.object({}).passthrough()),
13+
encodedTemplateYaml: z.optional(z.string()),
14+
});
15+
16+
export type Request = z.infer<typeof RequestSchema>;
17+
18+
export const ResponseSchema = z.object({
19+
response: z.object({
20+
uuid: z.string().uuid(),
21+
templateType: z.nativeEnum(SUBSCRIPTION_TEMPLATE_TYPE),
22+
templateJson: z.nullable(z.unknown()),
23+
encodedTemplateYaml: z.nullable(z.string()),
24+
}),
25+
});
26+
27+
export type Response = z.infer<typeof ResponseSchema>;
28+
}

libs/contract/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export * from './hosts';
44
export * from './metrics';
55
export * from './nodes';
66
export * from './roles';
7+
export * from './subscription-template';
78
export * from './templates';
89
export * from './users';

0 commit comments

Comments
 (0)