universal-links-handler/routes/index.js

98 lines
3.0 KiB
JavaScript
Raw Normal View History

var express = require('express');
var StatusIm = require('js-status-chat-name')
var assetLinks = require('../resources/assetlinks.json');
2018-06-28 20:11:45 +00:00
var appleSiteAssociation = require('../resources/apple-app-site-association.json');
var utils = require('../utils');
2018-10-05 05:31:10 +00:00
var router = express.Router();
2018-07-02 18:48:58 +00:00
router.get('/', function (req, res, next) {
2018-07-02 13:07:23 +00:00
if (req.query.redirect) {
2018-07-03 06:26:25 +00:00
return next();
2018-07-02 13:07:23 +00:00
}
2018-07-03 05:56:55 +00:00
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
var userAgent = req.headers['user-agent'];
if (utils.isAndroid(userAgent)) {
2018-07-03 06:26:25 +00:00
return res.redirect("https://play.google.com/store/apps/details?id=im.status.ethereum");
} else if (utils.isIOS(userAgent)) {
return res.redirect("https://testflight.apple.com/join/J8EuJmey");
2018-07-02 13:07:23 +00:00
}
2018-07-03 06:26:25 +00:00
return res.redirect("https://status.im");
});
2018-07-02 13:07:23 +00:00
2018-06-28 11:15:04 +00:00
router.get('/health', function(req, res) {
res.send('OK');
});
router.get('/.well-known/assetlinks.json', function(req, res) {
res.json(assetLinks);
});
2018-06-28 20:11:45 +00:00
router.get('/.well-known/apple-app-site-association', function(req, res) {
res.json(appleSiteAssociation);
});
2018-07-02 18:48:58 +00:00
router.get('/chat/:chatType/:chatId', function(req, res, next) {
2018-07-03 06:26:25 +00:00
const { chatId, chatType } = req.params;
/* Make button open chat if on Android */
let buttonTitle = 'Download Status'
let buttonUrl = 'https://status.im/get/'
if (utils.isAndroid(req.headers['user-agent'])) {
buttonTitle = 'Open in Status'
buttonUrl = `status-im://chat/${chatType}/${chatId}`
}
chatName = `#${chatId}`;
const options = {
title: `Join ${chatType} channel #${chatId} on Status`,
info: `Join public channel <span>#${chatId}</span> on Status.`,
path: req.originalUrl,
chatId, chatName, buttonTitle, buttonUrl
};
utils.makeQrCodeDataUri(chatName).then(
qrCodeDataUri => res.render('index', { ...options, qrCodeDataUri }),
error => res.render('index', options)
);
});
2018-07-02 18:48:58 +00:00
router.get('/user/:userId', function(req, res, next) {
2018-10-05 05:31:10 +00:00
const { userId } = req.params;
/* Make button open user profile if on Android */
let buttonTitle = 'Download Status'
let buttonUrl = 'https://status.im/get/'
if (utils.isAndroid(req.headers['user-agent'])) {
buttonTitle = 'Open in Status'
buttonUrl = `status-im://user/${userId}`
}
/* chat keys can be resolved to chat names */
chatName = userId
if (utils.isChatKey(userId)) {
chatName = StatusIm.chatKeyToChatName(userId)
}
2018-10-05 05:31:10 +00:00
const options = {
title: `Join ${chatName} in Status`,
info: `Chat and transact with <span>${userId}</span> in Status.`,
2018-10-05 05:31:10 +00:00
path: req.originalUrl,
chatId: userId,
chatName, buttonTitle, buttonUrl
2018-10-05 05:31:10 +00:00
};
utils.makeQrCodeDataUri(userId).then(
2018-10-05 05:31:10 +00:00
qrCodeDataUri => res.render('index', { ...options, qrCodeDataUri }),
error => res.render('index', options)
);
2018-06-28 07:27:15 +00:00
});
2018-07-05 09:28:59 +00:00
router.get('/browse/:url(*)', function(req, res, next) {
2018-06-28 07:27:15 +00:00
res.render('index', {
2018-07-03 06:26:25 +00:00
title: `Browse to ${req.params.url} in Status`,
path: req.originalUrl,
id: `${req.params.url}`
});
});
module.exports = router;