@@ -14,7 +14,7 @@ export enum RouteStatus {
14
14
15
15
export enum RouteType {
16
16
APP = 'app' ,
17
- OSS_CUSTOM = 'oss_custom '
17
+ WEBSITE_CUSTOM = 'website_custom '
18
18
}
19
19
20
20
@@ -24,6 +24,7 @@ export interface IRouteData {
24
24
appid : string
25
25
type : RouteType
26
26
website_id : string
27
+ domain : string [ ]
27
28
status : RouteStatus
28
29
created_by : ObjectId
29
30
created_at ?: Date
@@ -37,6 +38,7 @@ export async function createApplicationRoute(name: string, appid: string, uid: a
37
38
appid : appid ,
38
39
type : RouteType . APP ,
39
40
website_id : null ,
41
+ domain : [ ] ,
40
42
status : RouteStatus . PREPARED_CREATE ,
41
43
created_by : new ObjectId ( uid ) ,
42
44
created_at : now ,
@@ -68,28 +70,52 @@ export async function deleteApplicationRoute(appid: string) {
68
70
}
69
71
70
72
71
- export async function createOssCustomRoute ( name : string , appid : string , websiteId : string , uid : any ) : Promise < Boolean > {
72
- const now = new Date ( )
73
- let data : IRouteData = {
74
- name : name ,
73
+ export async function createWebsiteCustomRoute ( name : string , appid : string , websiteId : string , domain : string [ ] , uid : any ) : Promise < Boolean > {
74
+ const route = await DatabaseAgent . db . collection ( CN_ROUTES ) . findOne ( {
75
75
appid : appid ,
76
- type : RouteType . OSS_CUSTOM ,
77
- website_id : websiteId ,
78
- status : RouteStatus . PREPARED_CREATE ,
79
- created_by : new ObjectId ( uid ) ,
80
- created_at : now ,
81
- updated_at : now ,
82
- }
83
- const ret = await DatabaseAgent . db . collection ( CN_ROUTES )
84
- . insertOne ( data as any )
85
- if ( ! ret . insertedId ) {
86
- logger . error ( 'create route task successful: {}' , appid )
87
- return false
76
+ websiteId : websiteId
77
+ } )
78
+ const now = new Date ( )
79
+ if ( route ) {
80
+ const ret = await DatabaseAgent . db . collection ( CN_ROUTES ) . updateOne ( {
81
+ appid : appid ,
82
+ websiteId : websiteId
83
+ } , {
84
+ $set : {
85
+ domain : domain ,
86
+ status : RouteStatus . PREPARED_CREATE ,
87
+ created_at : now ,
88
+ updated_at : now ,
89
+ }
90
+ } )
91
+ if ( ! ret . modifiedCount ) {
92
+ logger . error ( 'update route task failed: {}' , appid )
93
+ return false
94
+ }
95
+ } else {
96
+ let data : IRouteData = {
97
+ name : name ,
98
+ appid : appid ,
99
+ type : RouteType . WEBSITE_CUSTOM ,
100
+ website_id : websiteId ,
101
+ domain : domain ,
102
+ status : RouteStatus . PREPARED_CREATE ,
103
+ created_by : new ObjectId ( uid ) ,
104
+ created_at : now ,
105
+ updated_at : now ,
106
+ }
107
+ const ret = await DatabaseAgent . db . collection ( CN_ROUTES )
108
+ . insertOne ( data as any )
109
+ if ( ! ret . insertedId ) {
110
+ logger . error ( 'create route task failed: {}' , appid )
111
+ return false
112
+ }
88
113
}
114
+
89
115
return true
90
116
}
91
117
92
- export async function deleteOssCustomRoute ( appid : string , websiteId : string ) {
118
+ export async function deleteWebsiteCustomRoute ( appid : string , websiteId : string ) {
93
119
const ret = await DatabaseAgent . db . collection < IRouteData > ( CN_ROUTES )
94
120
. updateOne ( {
95
121
appid : appid ,
0 commit comments