ArchiSteamFarm/IPC/Controllers/Api/ASFController.cs
/// <summary>
///     Updates ASF's global config.
/// </summary>
Updates ASF's global config.
Updates ASF ' s global config .
[Consumes("application/json")]
	[HttpPost]
	[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)]
	[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
	public async Task<ActionResult<GenericResponse>> ASFPost([FromBody] ASFRequest request) {
		ArgumentNullException.ThrowIfNull(request);
		if (ASF.GlobalConfig == null) {
			throw new InvalidOperationException(nameof(ASF.GlobalConfig));
		}
		(bool valid, string? errorMessage) = request.GlobalConfig.CheckValidation();
		if (!valid) {
			return BadRequest(new GenericResponse(false, errorMessage));
		}
		request.GlobalConfig.Saving = true;
		if (!request.GlobalConfig.IsIPCPasswordSet && ASF.GlobalConfig.IsIPCPasswordSet) {
			request.GlobalConfig.IPCPassword = ASF.GlobalConfig.IPCPassword;
		}
		if (!request.GlobalConfig.IsWebProxyPasswordSet && ASF.GlobalConfig.IsWebProxyPasswordSet) {
			request.GlobalConfig.WebProxyPassword = ASF.GlobalConfig.WebProxyPassword;
		}
		if (ASF.GlobalConfig.AdditionalProperties is { Count: > 0 }) {
			request.GlobalConfig.AdditionalProperties ??= new Dictionary<string, JToken>(ASF.GlobalConfig.AdditionalProperties.Count, ASF.GlobalConfig.AdditionalProperties.Comparer);
			foreach ((string key, JToken value) in ASF.GlobalConfig.AdditionalProperties.Where(property => !request.GlobalConfig.AdditionalProperties.ContainsKey(property.Key))) {
				request.GlobalConfig.AdditionalProperties.Add(key, value);
			}
			request.GlobalConfig.AdditionalProperties.TrimExcess();
		}
		string filePath = ASF.GetFilePath(ASF.EFileType.Config);
		if (string.IsNullOrEmpty(filePath)) {
			ASF.ArchiLogger.LogNullError(filePath);
			return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(filePath))));
		}
		bool result = await GlobalConfig.Write(filePath, request.GlobalConfig).ConfigureAwait(false);
		return Ok(new GenericResponse(result));
	}
[ Consumes ( " " ) ] [ HttpPost ] [ ProducesResponseType ( typeof ( GenericResponse ) , ( int ) HttpStatusCode . OK ) ] [ ProducesResponseType ( typeof ( GenericResponse ) , ( int ) HttpStatusCode . BadRequest ) ] public async Task < ActionResult < GenericResponse > > ASFPost ( [ FromBody ] ASFRequest request ) { ArgumentNullException . ThrowIfNull ( request ) ; if ( ASF . GlobalConfig == null ) { throw new InvalidOperationException ( nameof ( ASF . GlobalConfig ) ) ; } ( bool valid , string ? errorMessage ) = request . GlobalConfig . CheckValidation ( ) ; if ( ! valid ) { return BadRequest ( new GenericResponse ( false , errorMessage ) ) ; } request . GlobalConfig . Saving = true ; if ( ! request . GlobalConfig . IsIPCPasswordSet && ASF . GlobalConfig . IsIPCPasswordSet ) { request . GlobalConfig . IPCPassword = ASF . GlobalConfig . IPCPassword ; } if ( ! request . GlobalConfig . IsWebProxyPasswordSet && ASF . GlobalConfig . IsWebProxyPasswordSet ) { request . GlobalConfig . WebProxyPassword = ASF . GlobalConfig . WebProxyPassword ; } if ( ASF . GlobalConfig . AdditionalProperties is { Count : > 0 } ) { request . GlobalConfig . AdditionalProperties ??= new Dictionary < string , JToken > ( ASF . GlobalConfig . AdditionalProperties . Count , ASF . GlobalConfig . AdditionalProperties . Comparer ) ; foreach ( ( string key , JToken value ) in ASF . GlobalConfig . AdditionalProperties . Where ( property => ! request . GlobalConfig . AdditionalProperties . ContainsKey ( property . Key ) ) ) { request . GlobalConfig . AdditionalProperties . Add ( key , value ) ; } request . GlobalConfig . AdditionalProperties . TrimExcess ( ) ; } string filePath = ASF . GetFilePath ( ASF . EFileType . Config ) ; if ( string . IsNullOrEmpty ( filePath ) ) { ASF . ArchiLogger . LogNullError ( filePath ) ; return BadRequest ( new GenericResponse ( false , string . Format ( CultureInfo . CurrentCulture , Strings . ErrorIsInvalid , nameof ( filePath ) ) ) ) ; } bool result = await GlobalConfig . Write ( filePath , request . GlobalConfig ) . ConfigureAwait ( false ) ; return Ok ( new GenericResponse ( result ) ) ; }
Updates ASF's global config.
Updates ASF ' s global config .
ASFRequest
[FromBody]