Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5249 from geoadmin/BGDIINF_SB-2043_service_shorten
Browse files Browse the repository at this point in the history
Switching to the new service-shortlink
  • Loading branch information
procrastinatio authored Apr 6, 2022
2 parents 5d65522 + 8b4965c commit e05e96a
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 11 deletions.
3 changes: 3 additions & 0 deletions mk/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ QRCODE_PATH ?= /api/qrcode/generate
LAST_QRCODE_PATH := $(call lastvalue,qrcode-path)
PROXY_URL ?= //service-proxy.prod.bgdi.ch
LAST_PROXY_URL := $(call lastvalue,proxy-url)
SHORTEN_URL ?= s.geo.admin.ch
SHORTEN_TECH_URL ?= //sys-s.
LAST_SHORTEN_URL := $(call lastvalue,shorten-url)
STORAGE_URL ?= //sys-public.prod.bgdi.ch
STORAGE_TECH_URL ?= //sys-public.prod.bgdi.ch
STORAGE_LAST_URL := $(call lastvalue,storage-url)
Expand Down
2 changes: 2 additions & 0 deletions mk/debug.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ define buildpage
--var "qrcode_path=$(QRCODE_PATH)" \
--var "shop_url=$(SHOP_URL)" \
--var "shop_tech_url=$(SHOP_TECH_URL)" \
--var "shorten_url=$(SHORTEN_URL)" \
--var "shorten_tech_url=$(SHORTEN_TECH_URL)" \
--var "storage_url=$(STORAGE_URL)" \
--var "storage_tech_url=$(STORAGE_TECH_URL)" \
--var "wms_url=$(WMS_URL)" \
Expand Down
1 change: 1 addition & 0 deletions mk/help.mk
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ help:
@echo "- CONFIG_URL Service URL (build with: $(LAST_CONFIG_URL), current value: $(CONFIG_URL))"
@echo "- ALTI_URL Alti service URL (build with: $(LAST_ALTI_URL), current value: $(ALTI_URL))"
@echo "- PRINT_URL Print service URL (build with: $(LAST_PRINT_URL), current value: $(PRINT_URL))"
@echo "- SHORTEN_URL Shortener URL (build with: $(LAST_SHORTEN_URL), current value: $(SHORTEN_URL))"
@echo "- FEEDBACK_URL Feedback URL (build with: $(LAST_FEEDBACK_URL), current value: $(FEEDBACK_URL))"
@echo "- QRCODE_URL qrcode URL (build with: $(LAST_QRCODE_URL), current value: $(QRCODE_URL))"
@echo "- QRCODE_PATH qrcode path (build with: $(LAST_QRCODE_PATH), current value: $(QRCODE_PATH))"
Expand Down
3 changes: 3 additions & 0 deletions mk/last.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ ${PYTHON_VENV}: .build-artefacts/last-pypi-url
.build-artefacts/last-shop-url::
$(call cachelastvariable,$@,$(SHOP_URL),$(LAST_SHOP_URL),shop-url)

.build-artefacts/last-shorten-url::
$(call cachelastvariable,$@,$(SHORTEN_URL),$(LAST_SHORTEN_URL),shorten-url)

.build-artefacts/last-feedback-url::
$(call cachelastvariable,$@,$(FEEDBACK_URL),$(LAST_FEEDBACK_URL),feedback-url)

Expand Down
1 change: 1 addition & 0 deletions rc_dev
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export FEEDBACK_URL=//sys-map.dev.bgdi.ch
export PUBLIC_URL=//public.dev.bgdi.ch
export PRINT_URL=//service-print.dev.bgdi.ch
export PROXY_URL=//service-proxy.bgdi-dev.swisstopo.cloud
export SHORTEN_URL=//sys-s.dev.bgdi.ch
export QRCODE_URL=//sys-map.dev.bgdi.ch
export QRCODE_PATH=/api/qrcode/generate
export STORAGE_URL=//sys-public.dev.bgdi.ch
Expand Down
1 change: 1 addition & 0 deletions rc_int
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export SHOP_URL=//shop-bgdi.int.bgdi.ch
export PUBLIC_URL=//public.int.bgdi.ch
export PRINT_URL=//service-print.int.bgdi.ch
export PROXY_URL=//service-proxy.int.bgdi.ch
export SHORTEN_URL=//sys-s.int.bgdi.ch
export QRCODE_URL=//sys-map.int.bgdi.ch
export STORAGE_URL=//sys-public.int.bgdi.ch
export WMS_URL=//wms-bgdi-cdn-{s}.int.bgdi.ch
Expand Down
1 change: 1 addition & 0 deletions rc_prod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export SHOP_URL=//shop.swisstopo.admin.ch
export PUBLIC_URL=//public.geo.admin.ch
export PRINT_URL=//print.geo.admin.ch
export PROXY_URL=//service-proxy.prod.bgdi.ch
export SHORTEN_URL=//sys-s.prod.bgdi.ch
export QRCODE_URL=//map.geo.admin.ch
export STORAGE_URL=//public.geo.admin.ch
export WMS_URL=//wms{s}.geo.admin.ch
Expand Down
9 changes: 4 additions & 5 deletions src/components/UrlUtilsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ goog.provide('ga_urlutils_service');
};

this.shorten = function(url, timeout) {
return $http.get(shortenUrl, {
timeout: timeout,
params: {
url: url
}
return $http.post(shortenUrl, {
url: url
}, {
timeout: timeout
}).then(function(response) {
return response.data.shorturl;
}, function(reason) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.mako.html
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@
var altiUrl = setBackend(prtl + cfg['alti_url'], prtl + cfg['alti_tech_url'], 'alti_url');
var feedbackUrl = setBackend(prtl + cfg['feedback_url'], prtl + cfg['feedback_tech_url'], 'feedback_url');
var shopUrl = setBackend(prtl + cfg['shop_url'], prtl + cfg['shop_tech_url'], 'shop_url');
var shortenUrl = setBackend(prtl + cfg['shorten_url'], prtl + cfg['shorten_tech_url'], 'shorten_url');
var publicUrl = setBackend(prtl + cfg['public_url'], prtl + cfg['public_tech_url'], 'public_url');
var printUrl = setBackend(prtl + cfg['print_url'], prtl + cfg['print_tech_url'], 'print_url');
var storageUrl = setBackend(prtl + cfg['storage_url'], prtl + cfg['storage_tech_url'], 'storage_url');
Expand Down Expand Up @@ -801,6 +802,7 @@
printUrl: printUrl,
proxyUrl: proxyUrl,
shopUrl: shopUrl,
shortenUrl: shortenUrl,
storageUrl: storageUrl,
storagePath: '/api/kml/admin',
publicUrl: publicUrl,
Expand Down
4 changes: 2 additions & 2 deletions src/js/GaModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ goog.require('ga_waitcursor_service');
});

module.config(function(gaUrlUtilsProvider, gaGlobalOptions) {
gaUrlUtilsProvider.shortenUrl = gaGlobalOptions.apiUrl +
'/shorten.json';
gaUrlUtilsProvider.shortenUrl = gaGlobalOptions.shortenUrl +
'/';
});

module.config(function(gaQueryProvider, gaGlobalOptions) {
Expand Down
4 changes: 3 additions & 1 deletion test/specs/Loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ beforeEach(function() {
var qrcodeUrl = '//sys-map.prod.bgdi.ch';
var qrcodePath = '/api/qrcode/generate';
var shopUrl = '//shop.bgdi.ch';
var shortenUrl = '//s.geo.admin.ch';
var storageUrl = '//sys-public.prod.bgdi.ch';
var wmsUrl = '//wms.geo.admin.ch';
var wmtsUrl = '//tod{s}.bgdi.ch';
Expand Down Expand Up @@ -47,6 +48,7 @@ beforeEach(function() {
qrcodeUrl: location.protocol + qrcodeUrl,
qrcodePath: qrcodePath,
shopUrl: location.protocol + shopUrl,
shortenUrl: location.protocol + shortenUrl,
storageUrl: location.protocol + storageUrl,
publicUrl: location.protocol + publicUrl,
publicUrlRegexp: /^https?:\/\/public\..*\.(bgdi|admin)\.ch\/.*/,
Expand Down Expand Up @@ -135,7 +137,7 @@ beforeEach(function() {

module(function(gaUrlUtilsProvider, gaGlobalOptions) {
gaUrlUtilsProvider.shortenUrl =
gaGlobalOptions.apiUrl + '/shorten.json';
gaGlobalOptions.shortenUrl + '/';
});

module(function(gaQueryProvider, gaGlobalOptions) {
Expand Down
6 changes: 3 additions & 3 deletions test/specs/UrlUtilsService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('ga_urlutils_service', function() {

describe('#shorten()', function() {
var $httpBackend;
var shortenUrl = 'http://api3.geo.admin.ch/shorten.json?url=foo';
var shortenUrl = 'http://s.geo.admin.ch/';
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
}));
Expand All @@ -181,7 +181,7 @@ describe('ga_urlutils_service', function() {
});

it('shorten a url successfully', function(done) {
$httpBackend.expectGET(shortenUrl).respond({shorturl: 'shortenfoo'});
$httpBackend.expectPOST(shortenUrl).respond({shorturl: 'shortenfoo'});
gaUrlUtils.shorten('foo').then(function(url) {
expect(url).to.be('shortenfoo');
done();
Expand All @@ -192,7 +192,7 @@ describe('ga_urlutils_service', function() {

it('handle service error displaying a log an returning the initial url', function(done) {
var errorSpy = sinon.stub(window.console, 'error');
$httpBackend.expectGET(shortenUrl).respond(501);
$httpBackend.expectPOST(shortenUrl).respond(501);
gaUrlUtils.shorten('foo').then(function(url) {
expect(url).to.be('foo');
expect(errorSpy.callCount).to.be(1);
Expand Down

0 comments on commit e05e96a

Please sign in to comment.