Skip to content

Commit

Permalink
Rename mediaType to type in links - closes #2808 (#2907)
Browse files Browse the repository at this point in the history
Rename mediaType to type in links - closes #2808
  • Loading branch information
benfrancis authored Jan 31, 2022
1 parent c0cb45b commit 3b64132
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/models/thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export default class Thing extends EventEmitter {

const uiLink = {
rel: 'alternate',
mediaType: 'text/html',
type: 'text/html',
href: this.href,
};

Expand All @@ -223,7 +223,14 @@ export default class Thing extends EventEmitter {

if (description.hasOwnProperty('links')) {
for (const link of description.links) {
if (link.rel === 'alternate' && link.mediaType === 'text/html') {
// For backwards compatibility
if (link.mediaType) {
console.warn('The mediaType member of Link is deprecated, please use type instead');
link.type = link.mediaType;
delete link.mediaType;
}

if (link.rel === 'alternate' && link.type === 'text/html') {
if (link.proxy) {
delete link.proxy;
uiLink.href = `${Constants.PROXY_PATH}/${encodeURIComponent(this.id)}${link.href}`;
Expand Down Expand Up @@ -811,11 +818,11 @@ export default class Thing extends EventEmitter {

let uiLink: Link = {
rel: 'alternate',
mediaType: 'text/html',
type: 'text/html',
href: this.href,
};
for (const link of this.links) {
if (link.rel === 'alternate' && link.mediaType === 'text/html') {
if (link.rel === 'alternate' && link.type === 'text/html') {
uiLink = link;
break;
}
Expand All @@ -828,7 +835,14 @@ export default class Thing extends EventEmitter {
// Update the UI href
if (description.hasOwnProperty('links')) {
for (const link of description.links) {
if (link.rel === 'alternate' && link.mediaType === 'text/html') {
// For backwards compatibility
if (link.mediaType) {
console.warn('The mediaType member of Link is deprecated, please use type instead');
link.type = link.mediaType;
delete link.mediaType;
}

if (link.rel === 'alternate' && link.type === 'text/html') {
if (link.proxy) {
delete link.proxy;
uiLink.href = `${Constants.PROXY_PATH}/${encodeURIComponent(this.id)}${link.href}`;
Expand Down
2 changes: 1 addition & 1 deletion static/js/schema-impl/capability/thing.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Thing {
this.uiHref = null;
if (description.links) {
for (const link of description.links) {
if (link.rel === 'alternate' && link.mediaType === 'text/html') {
if (link.rel === 'alternate' && link.type === 'text/html') {
if (link.href.startsWith('/proxy/')) {
this.uiHref = `${link.href}?jwt=${API.jwt}`;
} else if (
Expand Down

0 comments on commit 3b64132

Please sign in to comment.