コード例 #1
0
        public async Task <IActionResult> CreateNewRecord(CreateNewRecordAddressModel model)
        {
            var appid = await _appRepo.GetAppId(model.AccessToken);

            var conflict = await _recordRepo.GetRecordByName(model.NewRecordName) != null;

            if (conflict)
            {
                return(this.Protocol(ErrorType.NotEnoughResources, $"There is already a record with name: '{model.NewRecordName}'. Please try another new name."));
            }
            var createdRecord = await _recordRepo.CreateRecord(model.NewRecordName, model.Type, appid, model.TargetUrl, model.Enabled);

            return(this.Protocol(ErrorType.Success, $"Successfully created your new record: '{createdRecord.RecordUniqueName}' at {createdRecord.CreationTime}."));
        }
コード例 #2
0
        public async Task <IActionResult> Wrap(WrapAddressModel model)
        {
            var record = await _recordRepo.GetRecordByName(model.RecordName);

            if (record == null)
            {
                return(NotFound());
            }
            if (!record.Enabled)
            {
                return(NotFound());
            }
            var builtUrl = BuildTargetUrl(record, model.Path);

            switch (record.Type)
            {
            case RecordType.IFrame:
                return(View("Iframe", builtUrl));

            case RecordType.Redirect:
                return(Redirect(builtUrl));

            case RecordType.PermanentRedirect:
                return(RedirectPermanent(builtUrl));

            case RecordType.ReverseProxy:
                return(await RewriteToUrl(builtUrl));

            default:
                return(Redirect(builtUrl));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Wrap(WrapAddressModel model)
        {
            var record = await _recordRepo.GetRecordByName(model.RecordName);

            if (record == null)
            {
                return(NotFound());
            }
            if (!record.Enabled)
            {
                return(NotFound());
            }
            var builtUrl = BuildTargetUrl(record, model.Path);

            return(record.Type switch
            {
                RecordType.IFrame => View("Iframe", builtUrl),
                RecordType.Redirect => Redirect(builtUrl),
                RecordType.PermanentRedirect => RedirectPermanent(builtUrl),
                RecordType.ReverseProxy => await RewriteToUrl(builtUrl),
                _ => Redirect(builtUrl),
            });
コード例 #4
0
        public async Task <IActionResult> UpdateRecordInfo(UpdateRecordInfoAddressModel model)
        {
            var appid = await _appRepo.GetAppId(model.AccessToken);

            var record = await _recordRepo.GetRecordByNameUnderApp(model.OldRecordName, appid);

            // Conflict = Name changed, and new name already exists.
            var conflict = model.NewRecordName.ToLower() != model.OldRecordName.ToLower() &&
                           await _recordRepo.GetRecordByName(model.NewRecordName) != null;

            if (conflict)
            {
                return(this.Protocol(ErrorType.Conflict, $"There is already a record with name: '{model.NewRecordName}'. Please try another new name."));
            }
            record.RecordUniqueName = model.NewRecordName.ToLower();
            record.Type             = model.NewType;
            record.TargetUrl        = model.NewUrl;
            record.Enabled          = model.Enabled;
            record.Tags             = model.Tags;
            await _recordRepo.UpdateRecord(record);

            return(this.Protocol(ErrorType.Success, "Successfully updated your Record!"));
        }
コード例 #5
0
        public async Task <IActionResult> Warp(WarpAddressModel model)
        {
            var record = await _recordRepo.GetRecordByName(model.RecordName);

            _logger.LogInformation($"New request coming with name: {model.RecordName}, path: {model.Path}.");
            if (record == null)
            {
                return(NotFound());
            }
            if (!record.Enabled)
            {
                return(NotFound());
            }
            var builtUrl = BuildTargetUrl(record, model.Path);

            _logger.LogInformation($"Target {record.Type} url is: {builtUrl}.");
            return(record.Type switch
            {
                RecordType.IFrame => View("Iframe", builtUrl),
                RecordType.Redirect => Redirect(builtUrl),
                RecordType.PermanentRedirect => RedirectPermanent(builtUrl),
                RecordType.ReverseProxy => await RewriteToUrl(builtUrl),
                _ => Redirect(builtUrl),
            });