MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / post

Method post

packages/hydrooj/src/handler/manage.ts:210–233  ·  view source on GitHub ↗
({ }, value: string)

Source from the content-addressed store, hash-verified

208 @requireSudo
209 @param('value', Types.String)
210 async post({ }, value: string) {
211 const oldConfig = yaml.load(this.ctx.setting.configSource);
212 let config;
213 const processNode = (node: any, old: any, schema: Schema<any, any>, parent?: any, accessKey?: string) => {
214 if (['union', 'intersect'].includes(schema.type)) {
215 for (const item of schema.list) processNode(node, old, item, parent, accessKey);
216 }
217 if (parent && (schema.meta.secret === true || schema.meta.role === 'secret')) {
218 if (node === '[hidden]') parent[accessKey] = old;
219 // TODO support more types
220 }
221 if (schema.type === 'object') {
222 for (const key in schema.dict) processNode(node[key] || {}, old[key] || {}, schema.dict[key], node, key);
223 }
224 };
225
226 try {
227 config = yaml.load(value);
228 for (const schema of this.ctx.setting.settings) processNode(config, oldConfig, schema, null, '');
229 } catch (e) {
230 throw new ValidationError('value', '', e.message);
231 }
232 await this.ctx.setting.saveConfig(config);
233 }
234}
235
236/* eslint-disable no-await-in-loop */

Callers

nothing calls this directly

Calls 3

processNodeFunction · 0.85
saveConfigMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected