@@ -14,6 +14,17 @@ const patchSchema = {
14
14
fileSizeLimit : { type : 'number' } ,
15
15
jwtSecret : { type : 'string' } ,
16
16
serviceKey : { type : 'string' } ,
17
+ features : {
18
+ type : 'object' ,
19
+ properties : {
20
+ imageTransformation : {
21
+ type : 'object' ,
22
+ properties : {
23
+ enabled : { type : 'boolean' } ,
24
+ } ,
25
+ } ,
26
+ } ,
27
+ } ,
17
28
} ,
18
29
} ,
19
30
} as const
@@ -46,6 +57,7 @@ interface tenantDBInterface {
46
57
jwt_secret : string
47
58
service_key : string
48
59
file_size_limit ?: number
60
+ feature_image_transformation : boolean
49
61
}
50
62
51
63
export default async function routes ( fastify : FastifyInstance ) {
@@ -54,13 +66,26 @@ export default async function routes(fastify: FastifyInstance) {
54
66
fastify . get ( '/' , async ( ) => {
55
67
const tenants = await knex ( 'tenants' ) . select ( )
56
68
return tenants . map (
57
- ( { id, anon_key, database_url, file_size_limit, jwt_secret, service_key } ) => ( {
69
+ ( {
70
+ id,
71
+ anon_key,
72
+ database_url,
73
+ file_size_limit,
74
+ jwt_secret,
75
+ service_key,
76
+ feature_image_transformation,
77
+ } ) => ( {
58
78
id,
59
79
anonKey : decrypt ( anon_key ) ,
60
80
databaseUrl : decrypt ( database_url ) ,
61
81
fileSizeLimit : Number ( file_size_limit ) ,
62
82
jwtSecret : decrypt ( jwt_secret ) ,
63
83
serviceKey : decrypt ( service_key ) ,
84
+ features : {
85
+ imageTransformation : {
86
+ enabled : feature_image_transformation ,
87
+ } ,
88
+ } ,
64
89
} )
65
90
)
66
91
} )
@@ -70,20 +95,34 @@ export default async function routes(fastify: FastifyInstance) {
70
95
if ( ! tenant ) {
71
96
reply . code ( 404 ) . send ( )
72
97
} else {
73
- const { anon_key, database_url, file_size_limit, jwt_secret, service_key } = tenant
98
+ const {
99
+ anon_key,
100
+ database_url,
101
+ file_size_limit,
102
+ jwt_secret,
103
+ service_key,
104
+ feature_image_transformation,
105
+ } = tenant
106
+
74
107
return {
75
108
anonKey : decrypt ( anon_key ) ,
76
109
databaseUrl : decrypt ( database_url ) ,
77
110
fileSizeLimit : Number ( file_size_limit ) ,
78
111
jwtSecret : decrypt ( jwt_secret ) ,
79
112
serviceKey : decrypt ( service_key ) ,
113
+ features : {
114
+ imageTransformation : {
115
+ enabled : feature_image_transformation ,
116
+ } ,
117
+ } ,
80
118
}
81
119
}
82
120
} )
83
121
84
122
fastify . post < tenantRequestInterface > ( '/:tenantId' , { schema } , async ( request , reply ) => {
85
- const { anonKey, databaseUrl, fileSizeLimit, jwtSecret, serviceKey } = request . body
86
123
const { tenantId } = request . params
124
+ const { anonKey, databaseUrl, fileSizeLimit, jwtSecret, serviceKey, features } = request . body
125
+
87
126
await runMigrations ( tenantId , databaseUrl )
88
127
await knex ( 'tenants' ) . insert ( {
89
128
id : tenantId ,
@@ -92,6 +131,7 @@ export default async function routes(fastify: FastifyInstance) {
92
131
file_size_limit : fileSizeLimit ,
93
132
jwt_secret : encrypt ( jwtSecret ) ,
94
133
service_key : encrypt ( serviceKey ) ,
134
+ feature_image_transformation : features ?. imageTransformation ?. enabled ?? false ,
95
135
} )
96
136
reply . code ( 201 ) . send ( )
97
137
} )
@@ -100,7 +140,7 @@ export default async function routes(fastify: FastifyInstance) {
100
140
'/:tenantId' ,
101
141
{ schema : patchSchema } ,
102
142
async ( request , reply ) => {
103
- const { anonKey, databaseUrl, fileSizeLimit, jwtSecret, serviceKey } = request . body
143
+ const { anonKey, databaseUrl, fileSizeLimit, jwtSecret, serviceKey, features } = request . body
104
144
const { tenantId } = request . params
105
145
if ( databaseUrl ) {
106
146
await runMigrations ( tenantId , databaseUrl )
@@ -112,14 +152,15 @@ export default async function routes(fastify: FastifyInstance) {
112
152
file_size_limit : fileSizeLimit ,
113
153
jwt_secret : jwtSecret !== undefined ? encrypt ( jwtSecret ) : undefined ,
114
154
service_key : serviceKey !== undefined ? encrypt ( serviceKey ) : undefined ,
155
+ feature_image_transformation : features ?. imageTransformation ?. enabled ,
115
156
} )
116
157
. where ( 'id' , tenantId )
117
158
reply . code ( 204 ) . send ( )
118
159
}
119
160
)
120
161
121
162
fastify . put < tenantRequestInterface > ( '/:tenantId' , { schema } , async ( request , reply ) => {
122
- const { anonKey, databaseUrl, fileSizeLimit, jwtSecret, serviceKey } = request . body
163
+ const { anonKey, databaseUrl, fileSizeLimit, jwtSecret, serviceKey, features } = request . body
123
164
const { tenantId } = request . params
124
165
await runMigrations ( tenantId , databaseUrl )
125
166
@@ -129,6 +170,7 @@ export default async function routes(fastify: FastifyInstance) {
129
170
database_url : encrypt ( databaseUrl ) ,
130
171
jwt_secret : encrypt ( jwtSecret ) ,
131
172
service_key : encrypt ( serviceKey ) ,
173
+ feature_image_transformation : features ?. imageTransformation ?. enabled ?? false ,
132
174
}
133
175
134
176
if ( fileSizeLimit ) {
0 commit comments