mirror of
https://github.com/status-im/universal-links-handler.git
synced 2025-02-23 08:08:08 +00:00
use js-status-chat-key lib to display chat name from chat key
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
2f5d796be0
commit
e2c49346c7
@ -7,8 +7,8 @@ ADD package-lock.json /srv
|
||||
|
||||
WORKDIR /srv
|
||||
|
||||
RUN npm install
|
||||
RUN yarn install
|
||||
|
||||
ADD . /srv
|
||||
|
||||
CMD npm start
|
||||
CMD yarn start
|
||||
|
@ -12,6 +12,7 @@
|
||||
"ejs": "~2.5.7",
|
||||
"express": "~4.16.0",
|
||||
"http-errors": "~1.6.2",
|
||||
"js-status-chat-name": "https://github.com/status-im/js-status-chat-name#v0.1.2",
|
||||
"qrcode": "^1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -1,32 +1,24 @@
|
||||
var express = require('express');
|
||||
var StatusIm = require('js-status-chat-name')
|
||||
var assetLinks = require('../resources/assetlinks.json');
|
||||
var appleSiteAssociation = require('../resources/apple-app-site-association.json');
|
||||
var { makeQrCodeDataUri } = require('../utils/qrcodeUtils');
|
||||
var utils = require('../utils');
|
||||
|
||||
var router = express.Router();
|
||||
|
||||
router.get('/', function (req, res, next) {
|
||||
function isAndroid(userAgent) {
|
||||
return userAgent.toLowerCase().indexOf("android") > -1;
|
||||
}
|
||||
|
||||
function isIOS(userAgent) {
|
||||
return userAgent.toLowerCase().indexOf("iphone") > -1;
|
||||
}
|
||||
|
||||
if (req.query.redirect) {
|
||||
return next();
|
||||
}
|
||||
|
||||
var userAgent = req.headers['user-agent'];
|
||||
|
||||
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
|
||||
res.header('Expires', '-1');
|
||||
res.header('Pragma', 'no-cache');
|
||||
|
||||
if (isAndroid(userAgent)) {
|
||||
var userAgent = req.headers['user-agent'];
|
||||
if (utils.isAndroid(userAgent)) {
|
||||
return res.redirect("https://play.google.com/store/apps/details?id=im.status.ethereum");
|
||||
} else if (isIOS(userAgent)) {
|
||||
} else if (utils.isIOS(userAgent)) {
|
||||
return res.redirect("https://testflight.apple.com/join/J8EuJmey");
|
||||
}
|
||||
|
||||
@ -49,19 +41,28 @@ router.get('/chat/:chatType/:chatId', function(req, res, next) {
|
||||
const { chatId, chatType } = req.params;
|
||||
res.render('index', {
|
||||
title: `Join the ${chatType} chat: #${chatId} in Status`,
|
||||
info: `Chat in a public channel <span>#${chatId}</span> in Status.`,
|
||||
path: req.originalUrl,
|
||||
id: `${chatId}`
|
||||
chatId: chatId,
|
||||
chatName: chatId,
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/user/:userId', function(req, res, next) {
|
||||
const { userId } = req.params;
|
||||
chatName = userId
|
||||
/* chat keys can be resolved to chat names */
|
||||
if (utils.isChatKey(userId)) {
|
||||
chatName = StatusIm.chatKeyToChatName(userId)
|
||||
}
|
||||
const options = {
|
||||
title: `View user ${userId} profile in Status`,
|
||||
title: `Join ${chatName} in Status`,
|
||||
info: `Chat and transact with <span>${userId}</span> in Status.`,
|
||||
path: req.originalUrl,
|
||||
id: `${userId}`
|
||||
chatId: userId,
|
||||
chatName: chatName,
|
||||
};
|
||||
makeQrCodeDataUri(userId).then(
|
||||
utils.makeQrCodeDataUri(userId).then(
|
||||
qrCodeDataUri => res.render('index', { ...options, qrCodeDataUri }),
|
||||
error => res.render('index', options)
|
||||
);
|
||||
@ -71,10 +72,12 @@ router.get('/extension/:extensionEndpoint', function(req, res, next) {
|
||||
const { extensionEndpoint } = req.params;
|
||||
const options = {
|
||||
title: `Open extension ${extensionEndpoint} in Status`,
|
||||
info: `Open the <span>${extensionEndpoint}</span> extension in Status.`,
|
||||
path: req.originalUrl,
|
||||
id: `${extensionEndpoint}`
|
||||
chatId: extensionEndpoint,
|
||||
chatName: extensionEndpoint,
|
||||
};
|
||||
makeQrCodeDataUri('https://get.status.im/extension/' + extensionEndpoint).then(
|
||||
utils.makeQrCodeDataUri('https://join.status.im/extension/' + extensionEndpoint).then(
|
||||
qrCodeDataUri => res.render('index', { ...options, qrCodeDataUri }),
|
||||
error => res.render('index', options)
|
||||
);
|
||||
|
29
utils/index.js
Normal file
29
utils/index.js
Normal file
@ -0,0 +1,29 @@
|
||||
var QRCode = require('qrcode')
|
||||
|
||||
function isChatKey(str) {
|
||||
if (typeof str != "string") {
|
||||
throw TypeError("Expected chat key to be a string.")
|
||||
}
|
||||
/* Chat keys are prefixed with 0x04 and follwed by
|
||||
* two 32 byte hexadecimal digits. */
|
||||
return /^0[xX]04[0-9a-fA-F]{128}$/.test(str.trim())
|
||||
}
|
||||
|
||||
function makeQrCodeDataUri(x) {
|
||||
return QRCode.toDataURL(x, {width: 300})
|
||||
}
|
||||
|
||||
function isAndroid(userAgent) {
|
||||
return userAgent.toLowerCase().indexOf("android") > -1;
|
||||
}
|
||||
|
||||
function isIOS(userAgent) {
|
||||
return userAgent.toLowerCase().indexOf("iphone") > -1;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isChatKey,
|
||||
isAndroid,
|
||||
isIOS,
|
||||
makeQrCodeDataUri,
|
||||
}
|
@ -163,19 +163,19 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h3 class="break-word"><%= id %></h3>
|
||||
<h3 class="break-word"><%= chatName %></h3>
|
||||
<%if (locals.qrCodeDataUri) { %>
|
||||
<img class="qr-code" src="<%= qrCodeDataUri %>" />
|
||||
<% } %>
|
||||
<div class="row">
|
||||
<div class="col-md-6 ml-auto mr-auto text-center">
|
||||
<div class="copy">
|
||||
<div class="inner" id="copy-target"><%= id %></div>
|
||||
<div class="inner" id="copy-target"><%= chatId %></div>
|
||||
<a href="#" data-clipboard-target="#copy-target">Copy</a>
|
||||
</div>
|
||||
<a href="https://status.im/get/" class="btn btn-purple-fill">Download Status</a>
|
||||
<div class="info">
|
||||
Chat and transact with <span><%= id %></span> in Status.
|
||||
<%- info %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user