Skip to content

Commit

Permalink
Issue #SB-812 fix: Changed share url for unlisted content
Browse files Browse the repository at this point in the history
  • Loading branch information
anuj committed Nov 22, 2017
1 parent 95cfc22 commit 04587a2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
15 changes: 13 additions & 2 deletions src/app/helpers/shareUrlHelper.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
let publicUri = '/public/#!'

module.exports = function (app) {
app.all('/content/*', function (req, res) {
app.all('/content/:id', function (req, res) {
let redirectUrl = publicUri + req.path
res.redirect(redirectUrl)
})

app.all('/course/*', function (req, res) {
app.all('/course/:id', function (req, res) {
let redirectUrl = publicUri + req.path
res.redirect(redirectUrl)
})

app.all('/unlisted/:hash', function (req, res) {
let hash = req.params.hash
let uri = Buffer.from(hash, 'base64').toString()
let redirectUrl = publicUri + '/' + uri + '/unlisted'
if (redirectUrl.indexOf('collection') > -1) {
redirectUrl = redirectUrl.replace('collection', 'content')
redirectUrl = redirectUrl + '/'
}
res.redirect(redirectUrl)
})
}
19 changes: 16 additions & 3 deletions src/app/private/scripts/services/workSpaceUtilsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ angular.module('playerApp')
return this.baseUrl + type + '/' + identifier
}

/**
* @method getBase64Url
* @desc generate the base url to play unlisted content for public users.
* @memberOf Services.getBase64Url
* @param {string} identifier - content or course identifier
* @param {string} type - content or course type
* @returns {string} base64url to share.
* @instance
*/
this.getBase64Url = function (type, identifier) {
return btoa(type + '/' + identifier)
}

/**
* @method getUnlistedShareUrl
* @desc generate the url to play unlisted content for other users.
Expand All @@ -161,11 +174,11 @@ angular.module('playerApp')
*/
this.getUnlistedShareUrl = function (cData) {
if (cData.contentType === 'Course') {
return this.baseUrl + 'course' + '/' + cData.identifier + '/' + config.UNLISTED_CONTENT_TYPE
return this.baseUrl + 'unlisted' + '/' + this.getBase64Url('course', cData.identifier)
} else if (cData.mimeType === 'application/vnd.ekstep.content-collection') {
return this.baseUrl + 'content' + '/' + cData.identifier + '/' + config.UNLISTED_CONTENT_TYPE + '/'
return this.baseUrl + 'unlisted' + '/' + this.getBase64Url('collection', cData.identifier)
} else {
return this.baseUrl + 'content' + '/' + cData.identifier + '/' + config.UNLISTED_CONTENT_TYPE
return this.baseUrl + 'unlisted' + '/' + this.getBase64Url('content', cData.identifier)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/app/public/scripts/routes/publicAppRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ angular.module('loginApp')
views: {
mainView: {
controller: function ($scope, $stateParams, $window, toasterService, $rootScope, $state) {
if ($stateParams.status === 'Unlisted') {
if ($stateParams.status === 'Unlisted' || $stateParams.status === 'unlisted') {
window.localStorage.setItem('redirectUrl', '/content/' + $stateParams.id + '/')
$window.location.href = '/private/index'
} else {
Expand All @@ -82,7 +82,7 @@ angular.module('loginApp')
views: {
mainView: {
controller: function ($scope, $stateParams, $window, toasterService, $rootScope, $state) {
if ($stateParams.status === 'Unlisted') {
if ($stateParams.status === 'Unlisted' || $stateParams.status === 'unlisted') {
window.localStorage.setItem('redirectUrl', '/course/' + $stateParams.id + '/')
$window.location.href = '/private/index'
} else {
Expand All @@ -102,7 +102,7 @@ angular.module('loginApp')
views: {
mainView: {
controller: function ($scope, $stateParams, $window, toasterService, $rootScope, $state) {
if ($stateParams.status === 'Unlisted') {
if ($stateParams.status === 'Unlisted' || $stateParams.status === 'unlisted') {
window.localStorage.setItem('redirectUrl', '/preview/collection/' + $stateParams.id + '/' + '/')
$window.location.href = '/private/index'
} else {
Expand Down

0 comments on commit 04587a2

Please sign in to comment.