Skip to content

Commit 932782f

Browse files
committed
feat: enhance subscription and external squad models with custom remarks
- Added customRemarks field to SubscriptionSettings and ExternalSquad models. - Updated related schemas, commands, and services to handle custom remarks. - Refactored seeding logic to include custom remarks for subscription settings. - Enhanced formatting logic to utilize custom remarks in host responses.
1 parent 78a3191 commit 932782f

26 files changed

+166
-120
lines changed

libs/contract/commands/external-squads/update-external-squad.command.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { z } from 'zod';
22

33
import {
4+
CustomRemarksSchema,
45
ExternalSquadHostOverridesSchema,
56
ExternalSquadResponseHeadersSchema,
67
ExternalSquadSchema,
@@ -43,6 +44,7 @@ export namespace UpdateExternalSquadCommand {
4344
hostOverrides: ExternalSquadHostOverridesSchema.optional(),
4445
responseHeaders: ExternalSquadResponseHeadersSchema.optional(),
4546
hwidSettings: z.optional(z.nullable(HwidSettingsSchema)),
47+
customRemarks: z.optional(z.nullable(CustomRemarksSchema)),
4648
});
4749

4850
export type Request = z.infer<typeof RequestSchema>;

libs/contract/commands/subscription-settings/update-subscription-settings.command.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { z } from 'zod';
22

33
import {
4+
CustomRemarksSchema,
45
HwidSettingsSchema,
56
ResponseRulesConfigSchema,
67
SubscriptionSettingsSchema,
@@ -27,7 +28,6 @@ export namespace UpdateSubscriptionSettingsCommand {
2728
isProfileWebpageUrlEnabled: z.optional(z.boolean()),
2829
serveJsonAtBaseSubscription: z.optional(z.boolean()),
2930
addUsernameToBaseSubscription: z.optional(z.boolean()),
30-
isShowCustomRemarks: z.optional(z.boolean()),
3131

3232
happAnnounce: z.optional(
3333
z
@@ -37,9 +37,8 @@ export namespace UpdateSubscriptionSettingsCommand {
3737
),
3838
happRouting: z.optional(z.string().nullable()),
3939

40-
expiredUsersRemarks: z.optional(z.array(z.string())),
41-
limitedUsersRemarks: z.optional(z.array(z.string())),
42-
disabledUsersRemarks: z.optional(z.array(z.string())),
40+
isShowCustomRemarks: z.optional(z.boolean()),
41+
customRemarks: z.optional(CustomRemarksSchema),
4342

4443
customResponseHeaders: z.optional(
4544
z.record(

libs/contract/models/external-squad.schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ExternalSquadHostOverridesSchema,
66
ExternalSquadResponseHeadersSchema,
77
} from './external-squads';
8-
import { HwidSettingsSchema } from './subscription-settings/hwid-settings.schema';
8+
import { HwidSettingsSchema, CustomRemarksSchema } from './subscription-settings';
99
import { SUBSCRIPTION_TEMPLATE_TYPE } from '../constants';
1010

1111
export const ExternalSquadSchema = z.object({
@@ -27,6 +27,7 @@ export const ExternalSquadSchema = z.object({
2727
hostOverrides: z.nullable(ExternalSquadHostOverridesSchema),
2828
responseHeaders: ExternalSquadResponseHeadersSchema,
2929
hwidSettings: z.nullable(HwidSettingsSchema),
30+
customRemarks: z.nullable(CustomRemarksSchema),
3031

3132
createdAt: z
3233
.string()

libs/contract/models/subscription-settings.schema.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { z } from 'zod';
22

3+
import { CustomRemarksSchema } from './subscription-settings/custom-remarks.schema';
34
import { HwidSettingsSchema } from './subscription-settings/hwid-settings.schema';
45
import { ResponseRulesConfigSchema } from './response-rules';
56

@@ -16,15 +17,13 @@ export const SubscriptionSettingsSchema = z.object({
1617
isProfileWebpageUrlEnabled: z.boolean(),
1718
serveJsonAtBaseSubscription: z.boolean(),
1819
addUsernameToBaseSubscription: z.boolean(),
20+
1921
isShowCustomRemarks: z.boolean(),
22+
customRemarks: CustomRemarksSchema,
2023

2124
happAnnounce: z.string().nullable(),
2225
happRouting: z.string().nullable(),
2326

24-
expiredUsersRemarks: z.array(z.string()),
25-
limitedUsersRemarks: z.array(z.string()),
26-
disabledUsersRemarks: z.array(z.string()),
27-
2827
customResponseHeaders: z.nullable(z.record(z.string(), z.string())),
2928

3029
randomizeHosts: z.boolean(),
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import z from 'zod';
2+
3+
export const CustomRemarksSchema = z.object({
4+
expiredUsers: z.array(z.string()).min(1),
5+
limitedUsers: z.array(z.string()).min(1),
6+
disabledUsers: z.array(z.string()).min(1),
7+
emptyHosts: z.array(z.string()).min(1),
8+
emptyInternalSquads: z.array(z.string()).min(1),
9+
});
10+
11+
export type TCustomRemarks = z.infer<typeof CustomRemarksSchema>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './custom-remarks.schema';
12
export * from './hwid-settings.schema';

libs/contract/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@remnawave/backend-contract",
3-
"version": "2.3.16",
3+
"version": "2.3.19",
44
"public": true,
55
"license": "AGPL-3.0-only",
66
"description": "A contract library for Remnawave Backend. It can be used in backend and frontend.",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "external_squads" ADD COLUMN "custom_remarks" JSONB;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- AlterTable
2+
ALTER TABLE "subscription_settings" ADD COLUMN "custom_remarks" JSONB;
3+
4+
-- Migrate data
5+
UPDATE "subscription_settings"
6+
SET "custom_remarks" = jsonb_build_object(
7+
'expiredUsers', COALESCE("expired_users_remarks", '[]'::jsonb),
8+
'limitedUsers', COALESCE("limited_users_remarks", '[]'::jsonb),
9+
'disabledUsers', COALESCE("disabled_users_remarks", '[]'::jsonb),
10+
'emptyHosts', '["→ Remnawave", "Did you forget to add hosts?", "→ No hosts found", "→ Check Hosts tab"]'::jsonb,
11+
'emptyInternalSquads', '["→ Remnawave", "Did you forget to add internal squads?", "→ No internal squads found", "User has no internal squads"]'::jsonb
12+
);
13+
14+
-- AlterTable
15+
ALTER TABLE "subscription_settings" ALTER COLUMN "custom_remarks" SET NOT NULL;
16+
17+
-- Drop old columns
18+
ALTER TABLE "subscription_settings"
19+
DROP COLUMN "disabled_users_remarks",
20+
DROP COLUMN "expired_users_remarks",
21+
DROP COLUMN "limited_users_remarks";

prisma/schema.prisma

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,7 @@ model SubscriptionSettings {
361361
happAnnounce String? @map("happ_announce")
362362
happRouting String? @map("happ_routing")
363363
isShowCustomRemarks Boolean @default(true) @map("is_show_custom_remarks")
364-
expiredUsersRemarks Json @map("expired_users_remarks")
365-
limitedUsersRemarks Json @map("limited_users_remarks")
366-
disabledUsersRemarks Json @map("disabled_users_remarks")
364+
customRemarks Json @map("custom_remarks")
367365
customResponseHeaders Json? @map("custom_response_headers")
368366
randomizeHosts Boolean @default(false) @map("randomize_hosts")
369367
responseRules Json? @map("response_rules")
@@ -568,7 +566,8 @@ model ExternalSquads {
568566
hostOverrides Json? @map("host_overrides")
569567
responseHeaders Json? @map("response_headers")
570568
571-
hwidSettings Json? @map("hwid_settings")
569+
hwidSettings Json? @map("hwid_settings")
570+
customRemarks Json? @map("custom_remarks")
572571
573572
createdAt DateTime @default(dbgenerated("now()")) @map("created_at")
574573
updatedAt DateTime @default(dbgenerated("now()")) @updatedAt @map("updated_at")

0 commit comments

Comments
 (0)