Ejemplo n.º 1
0
        public async Task <string> Delete(string fileName, string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(ReturnMessage.ErrorMessage("token not supplied"));
            }

            if (_appSettings.Value.AdminKey.Equals(token) || TokenManager.HasToken(token))
            {
                bool?result = FileManager.DeleteFile(fileName, _appSettings.Value.PhysicalUploadPath);
                if (result.HasValue)
                {
                    if (result.Value)
                    {
                        await CloudFlareManager.PurgeCache(
                            _appSettings.Value.CloudFlareZone,
                            _appSettings.Value.CloudFlareEmail,
                            _appSettings.Value.CloudFlareKey,
                            $"{_appSettings.Value.HostUrl}{_appSettings.Value.FileRequestPath}/{fileName}");

                        return(ReturnMessage.OkFileDeleted($"file '{fileName}' successfuly deleted"));
                    }
                    else
                    {
                        return(ReturnMessage.ErrorMessage($"file '{fileName}' doesn't exist"));
                    }
                }
                else
                {
                    return(ReturnMessage.ErrorMessage("could not delete file"));
                }
            }
            else
            {
                return(ReturnMessage.ErrorMessage("unauthorised: invalid token"));
            }
        }