Ejemplo n.º 1
0
        public async Task <ActionResult <GenericResponse> > ASFPost([FromBody] ASFRequest request)
        {
            if (request == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(request));
                return(BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request)))));
            }

            (bool valid, string errorMessage) = request.GlobalConfig.CheckValidation();
            if (!valid)
            {
                return(BadRequest(new GenericResponse(false, errorMessage)));
            }

            if (!request.GlobalConfig.IsWebProxyPasswordSet && Program.GlobalConfig.IsWebProxyPasswordSet)
            {
                request.GlobalConfig.WebProxyPassword = Program.GlobalConfig.WebProxyPassword;
            }

            request.GlobalConfig.ShouldSerializeEverything = false;

            string filePath = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            bool result = await GlobalConfig.Write(filePath, request.GlobalConfig).ConfigureAwait(false);

            return(Ok(new GenericResponse(result)));
        }
Ejemplo n.º 2
0
    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 })
Ejemplo n.º 3
0
        public async Task <ActionResult <GenericResponse> > Post([FromBody] ASFRequest request)
        {
            if (request == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(request));
                return(BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request)))));
            }

            if (request.KeepSensitiveDetails)
            {
                if (string.IsNullOrEmpty(request.GlobalConfig.WebProxyPassword) && !string.IsNullOrEmpty(Program.GlobalConfig.WebProxyPassword))
                {
                    request.GlobalConfig.WebProxyPassword = Program.GlobalConfig.WebProxyPassword;
                }
            }

            request.GlobalConfig.ShouldSerializeEverything = false;

            string filePath = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            if (!await GlobalConfig.Write(filePath, request.GlobalConfig).ConfigureAwait(false))
            {
                return(BadRequest(new GenericResponse(false, Strings.WarningFailed)));
            }

            return(Ok(new GenericResponse(true)));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <GenericResponse> > ASFPost([FromBody] ASFRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(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.ShouldSerializeDefaultValues    = false;
            request.GlobalConfig.ShouldSerializeHelperProperties = false;
            request.GlobalConfig.ShouldSerializeSensitiveDetails = true;

            if (!request.GlobalConfig.IsWebProxyPasswordSet && ASF.GlobalConfig.IsWebProxyPasswordSet)
            {
                request.GlobalConfig.WebProxyPassword = ASF.GlobalConfig.WebProxyPassword;
            }

            if (ASF.GlobalConfig.AdditionalProperties is { Count : > 0 })
Ejemplo n.º 5
0
        public async Task <ActionResult <GenericResponse> > ASFPost([FromBody] ASFRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (ASF.GlobalConfig == null)
            {
                throw new InvalidOperationException(nameof(ASF.GlobalConfig));
            }

            if (request.GlobalConfig == null)
            {
                return(BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.GlobalConfig)))));
            }

            (bool valid, string?errorMessage) = request.GlobalConfig.CheckValidation();

            if (!valid)
            {
                return(BadRequest(new GenericResponse(false, errorMessage)));
            }

            request.GlobalConfig.ShouldSerializeDefaultValues    = false;
            request.GlobalConfig.ShouldSerializeHelperProperties = false;
            request.GlobalConfig.ShouldSerializeSensitiveDetails = true;

            if (!request.GlobalConfig.IsWebProxyPasswordSet && ASF.GlobalConfig.IsWebProxyPasswordSet)
            {
                request.GlobalConfig.WebProxyPassword = ASF.GlobalConfig.WebProxyPassword;
            }

            if ((ASF.GlobalConfig.AdditionalProperties != null) && (ASF.GlobalConfig.AdditionalProperties.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)));
        }