Skip to content

Commit 2269d15

Browse files
committed
refactor(configuration.ts): remove unused configuration processing functions
Remove `ProcessEnvironmentConfig`, `ProcessConfiguration`, and `GenerateConfiguration` functions along with their dependencies from `configurationHelper`. These functions are no longer needed as the configuration processing logic has been moved to a different module or is no longer required. This cleanup reduces code complexity and potential maintenance overhead by eliminating unused code paths.
1 parent bd89d61 commit 2269d15

File tree

1 file changed

+0
-244
lines changed

1 file changed

+0
-244
lines changed

src/actions/configuration.ts

Lines changed: 0 additions & 244 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ import {
99
type Schema_App_Configuration_Env,
1010
} from "@/types/schema";
1111

12-
import {
13-
configurationTemplate,
14-
environmentTemplate,
15-
parseEnvironment,
16-
parseVersion1Config,
17-
parseVersion2Config,
18-
} from "@/lib/configurationHelper";
1912
import {
2013
base64Decode,
2114
base64Encode,
@@ -52,240 +45,3 @@ export async function GenerateServiceAccountB64(
5245
data: b64,
5346
};
5447
}
55-
56-
export async function ProcessEnvironmentConfig(
57-
configuration: string
58-
): Promise<ActionResponseSchema<z.infer<typeof Schema_App_Configuration_Env>>> {
59-
const data = parseEnvironment(configuration);
60-
if ("message" in data && "details" in data) {
61-
return {
62-
success: false,
63-
message: data.message,
64-
error: data.details.join("\n"),
65-
};
66-
}
67-
// Verify service account
68-
const serviceAccount = data.GD_SERVICE_B64;
69-
const decoded = base64Decode(serviceAccount, "standard");
70-
if (decoded === null) {
71-
data.GD_SERVICE_B64 = "";
72-
return {
73-
success: true,
74-
data,
75-
message: "Environment loaded, but service account is invalid",
76-
};
77-
}
78-
79-
return {
80-
success: true,
81-
message: "Environment loaded",
82-
data,
83-
};
84-
}
85-
86-
export async function ProcessConfiguration(
87-
configuration: string,
88-
version: "v1" | "v2" | "latest"
89-
): Promise<
90-
ActionResponseSchema<
91-
Omit<z.infer<typeof Schema_App_Configuration>, "environment">
92-
>
93-
> {
94-
const data =
95-
version === "v1"
96-
? parseVersion1Config(configuration)
97-
: parseVersion2Config(configuration);
98-
if ("message" in data && "details" in data) {
99-
return {
100-
success: false,
101-
message: data.message,
102-
error: data.details.join("\n"),
103-
};
104-
}
105-
106-
return {
107-
success: true,
108-
message: "Configuration loaded, but folder ID are not processed",
109-
data,
110-
};
111-
}
112-
113-
export async function GenerateConfiguration(
114-
values: z.infer<typeof Schema_App_Configuration>
115-
): Promise<
116-
ActionResponseSchema<{ configuration: string; env: string; zip: Blob }>
117-
> {
118-
const configurationMap: { key: string; value: string }[] = [
119-
{
120-
key: "version",
121-
value: values.version,
122-
},
123-
{
124-
key: "showGuideButton",
125-
value: values.site.guideButton.toString(),
126-
},
127-
{
128-
key: "cacheControl",
129-
value: `${values.api.cache.public ? "public, " : ""}max-age=${values.api.cache.maxAge}, s-maxage=${
130-
values.api.cache.sMaxAge
131-
}${values.api.cache.staleWhileRevalidate ? ", stale-while-revalidate" : ""}`,
132-
},
133-
{
134-
key: "api.rootFolder",
135-
value: await encryptionService.encrypt(
136-
values.api.rootFolder,
137-
values.environment.ENCRYPTION_KEY
138-
),
139-
},
140-
{
141-
key: "api.isTeamDrive",
142-
value: values.api.isTeamDrive.toString(),
143-
},
144-
{
145-
key: "api.sharedDrive",
146-
value: values.api.sharedDrive
147-
? await encryptionService.encrypt(
148-
values.api.sharedDrive,
149-
values.environment.ENCRYPTION_KEY
150-
)
151-
: "",
152-
},
153-
{
154-
key: "api.itemsPerPage",
155-
value: values.api.itemsPerPage.toString(),
156-
},
157-
{
158-
key: "api.searchResult",
159-
value: values.api.searchResult.toString(),
160-
},
161-
162-
{
163-
key: "api.specialFile.readme",
164-
value: values.api.specialFile.readme,
165-
},
166-
{
167-
key: "api.specialFile.banner",
168-
value: values.api.specialFile.banner,
169-
},
170-
{
171-
key: "api.hiddenFiles",
172-
value: `[${values.api.hiddenFiles.map((file) => `"${file}"`).join(", ")}]`,
173-
},
174-
{
175-
key: "api.proxyThumbnail",
176-
value: values.api.proxyThumbnail.toString(),
177-
},
178-
{
179-
key: "api.streamMaxSize",
180-
value: values.api.streamMaxSize.toString(),
181-
},
182-
{
183-
key: "api.maxFileSize",
184-
value: values.api.maxFileSize.toString(),
185-
},
186-
187-
{
188-
key: "site.siteName",
189-
value: values.site.siteName,
190-
},
191-
{
192-
key: "site.siteNameTemplate",
193-
value: values.site.siteNameTemplate,
194-
},
195-
{
196-
key: "site.siteDescription",
197-
value: values.site.siteDescription,
198-
},
199-
{
200-
key: "site.siteAuthor",
201-
value: values.site.siteAuthor,
202-
},
203-
{
204-
key: "site.robots",
205-
value: values.site.robots,
206-
},
207-
{
208-
key: "site.twitterHandle",
209-
value: values.site.twitterHandle,
210-
},
211-
{
212-
key: "site.showFileExtension",
213-
value: values.site.showFileExtension.toString(),
214-
},
215-
216-
{
217-
key: "site.breadcrumbMax",
218-
value: values.site.breadcrumbMax.toString(),
219-
},
220-
{
221-
key: "site.toaster.position",
222-
value: values.site.toaster.position,
223-
},
224-
{
225-
key: "site.toaster.duration",
226-
value: values.site.toaster.duration.toString(),
227-
},
228-
{
229-
key: "site.navbarItems",
230-
value: JSON.stringify(values.site.navbarItems, null, 2),
231-
},
232-
{
233-
key: "site.supports",
234-
value: JSON.stringify(values.site.supports, null, 2),
235-
},
236-
{
237-
key: "site.footer",
238-
value: JSON.stringify(values.site.footer, null, 2),
239-
},
240-
];
241-
let configuration = configurationTemplate;
242-
for (const { key, value } of configurationMap) {
243-
configuration = configuration.replace(`{{ ${key} }}`, value);
244-
}
245-
246-
const envMap: { key: string; value: string }[] = [
247-
{
248-
key: "serviceAccount",
249-
value: values.environment.GD_SERVICE_B64,
250-
},
251-
{
252-
key: "key",
253-
value: values.environment.ENCRYPTION_KEY,
254-
},
255-
256-
{
257-
key: "domain",
258-
value: values.environment.NEXT_PUBLIC_DOMAIN ?? "",
259-
},
260-
];
261-
let env = environmentTemplate;
262-
for (const { key, value } of envMap) {
263-
env = env.replace(`{{ ${key} }}`, value);
264-
}
265-
266-
const struct: AsyncZippable = {
267-
".env": [
268-
strToU8(env),
269-
{
270-
level: 9,
271-
},
272-
],
273-
"gIndex.config.ts": [
274-
strToU8(configuration),
275-
{
276-
level: 9,
277-
},
278-
],
279-
};
280-
const zip = zipSync(struct);
281-
282-
return {
283-
success: true,
284-
message: "Configuration generated",
285-
data: {
286-
configuration,
287-
env,
288-
zip: new Blob([zip], { type: "application/zip" }),
289-
},
290-
};
291-
}

0 commit comments

Comments
 (0)